-
Notifications
You must be signed in to change notification settings - Fork 1
/
transition.go
70 lines (58 loc) · 1.3 KB
/
transition.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
68
69
70
package main
import (
"fmt"
"github.com/urfave/cli"
)
func TransitionCommand() cli.Command {
command := cli.Command{
Name: "transition",
Aliases: []string{"t"},
Usage: "perform transition",
Flags: []cli.Flag{
cli.StringFlag{Name: "issue, i"},
cli.StringFlag{Name: "action, a"},
cli.StringFlag{Name: "jql, j"},
cli.BoolFlag{Name: "list, l"},
cli.StringFlag{Name: "comment, c"},
},
Action: func(c *cli.Context) error {
jc, err := NewClient()
if err != nil {
panic(err)
}
action := c.String("action")
jql := c.String("jql")
issueKey := c.String("issue")
list := c.Bool("list")
comment := c.String("comment")
issues, err := jc.findIssues(jql, issueKey)
if err != nil {
panic(err)
}
if list {
for _, issue := range *issues {
ts, _ := jc.Transitions(issue.Key)
for _, t := range *ts {
fmt.Printf("* %s: %s\n", t.Name, t.ID)
}
}
return nil
} else if len(action) == 0 {
fmt.Printf("Action is required.\n\n")
return nil
}
for _, issue := range *issues {
if len(comment) == 0 {
err = jc.DoTransition(issue.Key, action)
} else {
err = jc.DoTransitionWithPayload(issue.Key, action, comment)
}
if err != nil {
panic(err)
}
}
return nil
},
}
return command
}