mirror of
https://github.com/Threnklyn/jira.git
synced 2026-06-07 13:33:32 +02:00
adding labels [add|set|remove] commands
This commit is contained in:
@@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user