-
Notifications
You must be signed in to change notification settings - Fork 1
/
issues.go
92 lines (74 loc) · 1.63 KB
/
issues.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package main
import (
"encoding/json"
"fmt"
"os"
"github.com/urfave/cli"
)
func IssuesCommand() cli.Command {
command := cli.Command{
Name: "issues",
Aliases: []string{"i"},
Usage: "list issues",
Flags: []cli.Flag{
cli.StringFlag{Name: "jql, j"},
cli.StringFlag{Name: "issue, i"},
},
Action: func(c *cli.Context) error {
jc, err := NewClient()
if err != nil {
panic(err)
}
jql := c.String("jql")
issueKey := c.String("issue")
issues, err := jc.findIssues(jql, issueKey)
if err != nil {
panic(err)
}
for _, issue := range *issues {
fmt.Printf("* %s: %s\n -> %sbrowse/%s\n", issue.Key, issue.Fields.Summary, os.Getenv("GOJIRA_BASEURL"), issue.Key)
}
return err
},
}
return command
}
func UpdateIssueCommand() cli.Command {
command := cli.Command{
Name: "update",
Aliases: []string{"u"},
Usage: "Update Issue",
Flags: []cli.Flag{
cli.StringFlag{Name: "jql, j"},
cli.StringFlag{Name: "issue, i"},
cli.StringFlag{Name: "payload, p"},
},
Action: func(c *cli.Context) error {
jc, err := NewClient()
if err != nil {
panic(err)
}
jql := c.String("jql")
issueKey := c.String("issue")
issues, err := jc.findIssues(jql, issueKey)
payload := c.String("payload")
if len(payload) == 0 {
fmt.Printf("payload json is required.")
return nil
}
var data map[string]interface{}
err = json.Unmarshal([]byte(payload), &data)
if err != nil {
panic(err)
}
for _, issue := range *issues {
err = jc.UpdateIssue(issue.Key, data)
if err != nil {
panic(err)
}
}
return nil
},
}
return command
}