mirror of
https://github.com/Threnklyn/jira.git
synced 2026-05-18 20:23:28 +02:00
adding labels [add|set|remove] commands
This commit is contained in:
@@ -43,17 +43,12 @@ else
|
||||
GOBUILD=go build -v -ldflags "$(LDFLAGS) -s"
|
||||
endif
|
||||
|
||||
build: src/gopkg.in/Netflix-Skunkworks/go-jira.v0
|
||||
build:
|
||||
$(GOBUILD) -o '$(BIN)' cmd/jira/main.go
|
||||
|
||||
debug:
|
||||
go build -v -o '$(BIN)' cmd/jira/main.go
|
||||
|
||||
src/%:
|
||||
mkdir -p $(@D)
|
||||
test -L $@ || ln -sf '../../..' $@
|
||||
go get -v $* $*/main
|
||||
|
||||
vet:
|
||||
@go vet .
|
||||
@go vet ./data
|
||||
|
||||
+13
-15
@@ -203,6 +203,19 @@ func main() {
|
||||
Command: "watch",
|
||||
Entry: cli.CmdWatchRegistry(),
|
||||
},
|
||||
jiracli.CommandRegistry{
|
||||
Command: "labels add",
|
||||
Entry: cli.CmdLabelsAddRegistry(),
|
||||
},
|
||||
jiracli.CommandRegistry{
|
||||
Command: "labels set",
|
||||
Entry: cli.CmdLabelsAddRegistry(),
|
||||
},
|
||||
jiracli.CommandRegistry{
|
||||
Command: "labels remove",
|
||||
Entry: cli.CmdLabelsAddRegistry(),
|
||||
Aliases: []string{"rm"},
|
||||
},
|
||||
}
|
||||
|
||||
cli.Register(app, registry)
|
||||
@@ -221,8 +234,6 @@ func main() {
|
||||
}
|
||||
|
||||
// Usage:
|
||||
// jira comment ISSUE [--noedit] <Edit Options>
|
||||
// jira (set,add,remove) labels ISSUE [LABEL] ...
|
||||
// jira take ISSUE
|
||||
// jira (assign|give) ISSUE [ASSIGNEE|--default]
|
||||
// jira unassign ISSUE
|
||||
@@ -277,9 +288,6 @@ func main() {
|
||||
// }
|
||||
|
||||
// jiraCommands := map[string]string{
|
||||
// "comment": "comment",
|
||||
// "label": "labels",
|
||||
// "labels": "labels",
|
||||
// "component": "component",
|
||||
// "components": "components",
|
||||
// "take": "take",
|
||||
@@ -438,16 +446,6 @@ func main() {
|
||||
// switch command {
|
||||
// case "issuetypes":
|
||||
// err = c.CmdIssueTypes()
|
||||
// case "comment":
|
||||
// requireArgs(1)
|
||||
// setEditing(true)
|
||||
// err = c.CmdComment(args[0])
|
||||
// case "labels":
|
||||
// requireArgs(2)
|
||||
// action := args[0]
|
||||
// issue := args[1]
|
||||
// labels := args[2:]
|
||||
// err = c.CmdLabels(action, issue, labels)
|
||||
// case "component":
|
||||
// requireArgs(2)
|
||||
// action := args[0]
|
||||
|
||||
@@ -116,54 +116,6 @@ func (jc *JiraCli) Register(app *kingpin.Application, reg []CommandRegistry) {
|
||||
// return runTemplate(c.getTemplate("components"), data, nil)
|
||||
// }
|
||||
|
||||
// // CmdComment will open up editor with "comment" template and submit
|
||||
// // YAML output to jira
|
||||
// func (c *Cli) CmdComment(issue string) error {
|
||||
// log.Debugf("comment called")
|
||||
|
||||
// handlePost := func(json string) error {
|
||||
// uri := fmt.Sprintf("%s/rest/api/2/issue/%s/comment", c.endpoint, issue)
|
||||
// if c.getOptBool("dryrun", false) {
|
||||
// log.Debugf("POST: %s", json)
|
||||
// log.Debugf("Dryrun mode, skipping POST")
|
||||
// return nil
|
||||
// }
|
||||
// resp, err := c.post(uri, json)
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
|
||||
// if resp.StatusCode == 201 {
|
||||
// c.Browse(issue)
|
||||
// if !c.GetOptBool("quiet", false) {
|
||||
// fmt.Printf("OK %s %s/browse/%s\n", issue, c.endpoint, issue)
|
||||
// }
|
||||
// return nil
|
||||
// }
|
||||
// logBuffer := bytes.NewBuffer(make([]byte, 0))
|
||||
// resp.Write(logBuffer)
|
||||
// err = fmt.Errorf("Unexpected Response From POST")
|
||||
// log.Errorf("%s:\n%s", err, logBuffer)
|
||||
// return err
|
||||
// }
|
||||
|
||||
// if comment, ok := c.opts["comment"]; ok && comment != "" {
|
||||
// json, err := jsonEncode(map[string]interface{}{
|
||||
// "body": comment,
|
||||
// })
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
// return handlePost(json)
|
||||
// }
|
||||
// return c.editTemplate(
|
||||
// c.getTemplate("comment"),
|
||||
// fmt.Sprintf("%s-create-", issue),
|
||||
// map[string]interface{}{},
|
||||
// handlePost,
|
||||
// )
|
||||
// }
|
||||
|
||||
// // CmdComponent will add a new component to given project
|
||||
// func (c *Cli) CmdComponent(action string, project string, name string, desc string, lead string) error {
|
||||
// log.Debugf("component called")
|
||||
|
||||
@@ -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
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
@@ -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