-
Notifications
You must be signed in to change notification settings - Fork 328
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding
labels [add|set|remove]
commands
- Loading branch information
Showing
6 changed files
with
186 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package jiracli | ||
|
||
import ( | ||
"fmt" | ||
|
||
"gopkg.in/Netflix-Skunkworks/go-jira.v1/jiradata" | ||
kingpin "gopkg.in/alecthomas/kingpin.v2" | ||
) | ||
|
||
type LabelsAddOptions struct { | ||
GlobalOptions | ||
Issue string | ||
Labels []string | ||
} | ||
|
||
func (jc *JiraCli) CmdLabelsAddRegistry() *CommandRegistryEntry { | ||
opts := LabelsAddOptions{} | ||
return &CommandRegistryEntry{ | ||
"Add labels to an issue", | ||
func() error { | ||
return jc.CmdLabelsAdd(&opts) | ||
}, | ||
func(cmd *kingpin.CmdClause) error { | ||
return jc.CmdLabelsAddUsage(cmd, &opts) | ||
}, | ||
} | ||
} | ||
|
||
func (jc *JiraCli) CmdLabelsAddUsage(cmd *kingpin.CmdClause, opts *LabelsAddOptions) error { | ||
if err := jc.GlobalUsage(cmd, &opts.GlobalOptions); err != nil { | ||
return err | ||
} | ||
cmd.Arg("ISSUE", "issue id to modify labels").Required().StringVar(&opts.Issue) | ||
cmd.Arg("LABEL", "label to add to issue").Required().StringsVar(&opts.Labels) | ||
return nil | ||
} | ||
|
||
// CmdLabels will add labels on a given issue | ||
func (jc *JiraCli) CmdLabelsAdd(opts *LabelsAddOptions) error { | ||
ops := jiradata.FieldOperations{} | ||
for _, label := range opts.Labels { | ||
ops = append(ops, jiradata.FieldOperation{ | ||
"add": label, | ||
}) | ||
} | ||
issueUpdate := jiradata.IssueUpdate{ | ||
Update: jiradata.FieldOperationsMap{ | ||
"labels": ops, | ||
}, | ||
} | ||
|
||
err := jc.EditIssue(opts.Issue, &issueUpdate) | ||
if err != nil { | ||
return err | ||
} | ||
fmt.Printf("OK %s %s/browse/%s\n", opts.Issue, jc.Endpoint, opts.Issue) | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package jiracli | ||
|
||
import ( | ||
"fmt" | ||
|
||
"gopkg.in/Netflix-Skunkworks/go-jira.v1/jiradata" | ||
kingpin "gopkg.in/alecthomas/kingpin.v2" | ||
) | ||
|
||
type LabelsRemoveOptions struct { | ||
GlobalOptions | ||
Issue string | ||
Labels []string | ||
} | ||
|
||
func (jc *JiraCli) CmdLabelsRemoveRegistry() *CommandRegistryEntry { | ||
opts := LabelsRemoveOptions{} | ||
return &CommandRegistryEntry{ | ||
"Remove labels from an issue", | ||
func() error { | ||
return jc.CmdLabelsRemove(&opts) | ||
}, | ||
func(cmd *kingpin.CmdClause) error { | ||
return jc.CmdLabelsRemoveUsage(cmd, &opts) | ||
}, | ||
} | ||
} | ||
|
||
func (jc *JiraCli) CmdLabelsRemoveUsage(cmd *kingpin.CmdClause, opts *LabelsRemoveOptions) error { | ||
if err := jc.GlobalUsage(cmd, &opts.GlobalOptions); err != nil { | ||
return err | ||
} | ||
cmd.Arg("ISSUE", "issue id to modify labels").Required().StringVar(&opts.Issue) | ||
cmd.Arg("LABEL", "label to remove from issue").Required().StringsVar(&opts.Labels) | ||
return nil | ||
} | ||
|
||
// CmdLabels will remove labels on a given issue | ||
func (jc *JiraCli) CmdLabelsRemove(opts *LabelsRemoveOptions) error { | ||
ops := jiradata.FieldOperations{} | ||
for _, label := range opts.Labels { | ||
ops = append(ops, jiradata.FieldOperation{ | ||
"remove": label, | ||
}) | ||
} | ||
issueUpdate := jiradata.IssueUpdate{ | ||
Update: jiradata.FieldOperationsMap{ | ||
"labels": ops, | ||
}, | ||
} | ||
|
||
err := jc.EditIssue(opts.Issue, &issueUpdate) | ||
if err != nil { | ||
return err | ||
} | ||
fmt.Printf("OK %s %s/browse/%s\n", opts.Issue, jc.Endpoint, opts.Issue) | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package jiracli | ||
|
||
import ( | ||
"fmt" | ||
|
||
"gopkg.in/Netflix-Skunkworks/go-jira.v1/jiradata" | ||
kingpin "gopkg.in/alecthomas/kingpin.v2" | ||
) | ||
|
||
type LabelsSetOptions struct { | ||
GlobalOptions | ||
Issue string | ||
Labels []string | ||
} | ||
|
||
func (jc *JiraCli) CmdLabelsSetRegistry() *CommandRegistryEntry { | ||
opts := LabelsSetOptions{} | ||
return &CommandRegistryEntry{ | ||
"Set labels on an issue", | ||
func() error { | ||
return jc.CmdLabelsSet(&opts) | ||
}, | ||
func(cmd *kingpin.CmdClause) error { | ||
return jc.CmdLabelsSetUsage(cmd, &opts) | ||
}, | ||
} | ||
} | ||
|
||
func (jc *JiraCli) CmdLabelsSetUsage(cmd *kingpin.CmdClause, opts *LabelsSetOptions) error { | ||
if err := jc.GlobalUsage(cmd, &opts.GlobalOptions); err != nil { | ||
return err | ||
} | ||
cmd.Arg("ISSUE", "issue id to modify labels").Required().StringVar(&opts.Issue) | ||
cmd.Arg("LABEL", "label to set on issue").Required().StringsVar(&opts.Labels) | ||
return nil | ||
} | ||
|
||
// CmdLabels will set labels on a given issue | ||
func (jc *JiraCli) CmdLabelsSet(opts *LabelsSetOptions) error { | ||
issueUpdate := jiradata.IssueUpdate{ | ||
Update: jiradata.FieldOperationsMap{ | ||
"labels": jiradata.FieldOperations{ | ||
jiradata.FieldOperation{ | ||
"set": opts.Labels, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
err := jc.EditIssue(opts.Issue, &issueUpdate) | ||
if err != nil { | ||
return err | ||
} | ||
fmt.Printf("OK %s %s/browse/%s\n", opts.Issue, jc.Endpoint, opts.Issue) | ||
return nil | ||
} |