forked from go-jira/jira
/
labelsRemove.go
67 lines (59 loc) · 1.95 KB
/
labelsRemove.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package jiracmd
import (
"fmt"
"github.com/coryb/figtree"
"github.com/coryb/oreo"
"gopkg.in/Netflix-Skunkworks/go-jira.v1"
"gopkg.in/Netflix-Skunkworks/go-jira.v1/jiracli"
"gopkg.in/Netflix-Skunkworks/go-jira.v1/jiradata"
kingpin "gopkg.in/alecthomas/kingpin.v2"
)
type LabelsRemoveOptions struct {
jiracli.CommonOptions `yaml:",inline" json:",inline" figtree:",inline"`
Issue string `yaml:"issue,omitempty" json:"issue,omitempty"`
Labels []string `yaml:"labels,omitempty" json:"labels,omitempty"`
}
func CmdLabelsRemoveRegistry() *jiracli.CommandRegistryEntry {
opts := LabelsRemoveOptions{}
return &jiracli.CommandRegistryEntry{
"Remove labels from an issue",
func(fig *figtree.FigTree, cmd *kingpin.CmdClause) error {
jiracli.LoadConfigs(cmd, fig, &opts)
return CmdLabelsRemoveUsage(cmd, &opts)
},
func(o *oreo.Client, globals *jiracli.GlobalOptions) error {
return CmdLabelsRemove(o, globals, &opts)
},
}
}
func CmdLabelsRemoveUsage(cmd *kingpin.CmdClause, opts *LabelsRemoveOptions) error {
jiracli.BrowseUsage(cmd, &opts.CommonOptions)
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 CmdLabelsRemove(o *oreo.Client, globals *jiracli.GlobalOptions, 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 := jira.EditIssue(o, globals.Endpoint.Value, opts.Issue, &issueUpdate)
if err != nil {
return err
}
if !globals.Quiet.Value {
fmt.Printf("OK %s %s/browse/%s\n", opts.Issue, globals.Endpoint.Value, opts.Issue)
}
if opts.Browse.Value {
return CmdBrowse(globals, opts.Issue)
}
return nil
}