-
Notifications
You must be signed in to change notification settings - Fork 1
/
issue.go
174 lines (146 loc) · 3.36 KB
/
issue.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
package jira
import (
"encoding/json"
"strconv"
"strings"
"time"
)
type Time time.Time
func (t *Time) UnmarshalJSON(b []byte) error {
var str string
err := json.Unmarshal(b, &str)
if err != nil {
return err
}
pt, err := time.Parse("2006-01-02T15:04:05.999-0700", str)
if err != nil {
return err
}
*t = Time(pt)
return nil
}
type FieldsID int
func (id *FieldsID) UnmarshalJSON(b []byte) error {
var strID string
err := json.Unmarshal(b, &strID)
if err != nil {
return err
}
intID, err := strconv.ParseInt(strID, 10, 32)
if err != nil {
return err
}
*id = FieldsID(int(intID))
return nil
}
type Priority struct {
ID FieldsID `json:"id"`
Name string `json:"name"`
Self string `json:"self"`
IconURL string `json:"IconURL"`
}
func (p *Priority) GetID() int {
return int(p.ID)
}
type Person struct {
Name string `json:"name"`
DisplayName string `json:"displayName"`
Active bool `json:"active"`
}
func (p *Person) JiraName() string {
return p.Name
}
func (p *Person) RealName() string {
return p.DisplayName
}
type Issue struct {
browseURL string
ID FieldsID `json:"id"`
Self string `json:"self"`
Key string `json:"key"`
Fields struct {
Summary string `json:"summary"`
Description string `json:"description"`
Created Time `json:"created"`
Updated Time `json:"updated"`
Priority Priority `json:"priority"`
Status struct {
ID FieldsID `json:"id"`
Name string `json:"name"`
} `json:"status"`
IssueType struct {
ID FieldsID `json:"id"`
Name string `json:"name"`
} `json:"issuetype"`
Resolution struct {
ID FieldsID `json:"id"`
Name string `json:"name"`
} `json:"resolution"`
Assignee Person `json:"assignee"`
Reporter Person `json:"reporter"`
Creator Person `json:"creator"`
Watches struct {
WatchCount int `json:"watchCount"`
} `json:"watches"`
Components []struct {
ID FieldsID `json:"id"`
Name string `json:"name"`
} `json:"components"`
Labels []string `json:"labels"`
} `json:"fields"`
}
func (i *Issue) Link() string {
return i.browseURL + "/" + i.Key
}
func (i *Issue) DefaultTitle() string {
return i.Key + " " + i.Fields.Summary
}
func (i *Issue) GetKey() string {
return i.Key
}
func (i *Issue) GetSummary() string {
return i.Fields.Summary
}
func (i *Issue) Description() string {
return i.Fields.Description
}
func (i *Issue) Priority() *Priority {
return &i.Fields.Priority
}
func (i *Issue) Status() string {
return i.Fields.Status.Name
}
func (i *Issue) IssueType() string {
return i.Fields.IssueType.Name
}
func (i *Issue) Resolution() string {
return i.Fields.Resolution.Name
}
func (i *Issue) Assignee() *Person {
return &i.Fields.Assignee
}
func (i *Issue) Reporter() *Person {
return &i.Fields.Reporter
}
func (i *Issue) Creator() *Person {
return &i.Fields.Creator
}
func (i *Issue) Created() time.Time {
return time.Time(i.Fields.Created)
}
func (i *Issue) Updated() time.Time {
return time.Time(i.Fields.Updated)
}
func (i *Issue) Watches() int {
return i.Fields.Watches.WatchCount
}
func (i *Issue) Components() string {
components := make([]string, len(i.Fields.Components))
for i, c := range i.Fields.Components {
components[i] = c.Name
}
return strings.Join(components, ",")
}
func (i *Issue) Labels() string {
return strings.Join(i.Fields.Labels, ",")
}