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
|
package main
import (
"sort"
"strings"
"time"
)
type Issues []Issue
type Issue struct {
Id uint32
Summary string
Description string
Project KeyVal
Category KeyVal
TargetVersion KeyVal `json:"target_version"`
Reporter KeyVal
handler KeyVal
Status KeyVal
Resolution KeyVal
ViewState KeyVal `json:"view_state"`
Priority KeyVal
Severity KeyVal
Reproducibility KeyVal
Sticky bool
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
Notes []Note
Relationships []Relationship
Tags []KeyVal
History []Change
}
type KeyVal struct {
Id uint32
Name string
Label string `json:",omitempty"`
Color string `json:",omitempty"`
}
type Note struct {
Id uint32
Text string
Reporter KeyVal
ViewState KeyVal `json:"view_state"`
Attachments []Attachment
Typ string `json:"type"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"created_at"`
}
type Attachment struct {
Name string
Content []byte
}
type Relationship struct {
Id uint32
Typ KeyVal `json:"type"`
Issue struct {
Id uint32
Summary string
Status KeyVal
Resolution KeyVal
Handler KeyVal
}
}
type Change struct {
CreatedAt time.Time `json:"created_at"`
Message string
User KeyVal
Typ KeyVal `json:"type"`
Note struct{ id int32 }
}
type ByCategory []Issue
func (b ByCategory) Len() int { return len(b) }
func (b ByCategory) Less(i, j int) bool {
return strings.Compare(b[i].Category.Name, b[j].Category.Name) < 0
}
func (b ByCategory) Swap(i, j int) { b[i], b[j] = b[j], b[i] }
type ById []Issue
func (b ById) Len() int { return len(b) }
func (b ById) Less(i, j int) bool { return b[i].Id < b[j].Id }
func (b ById) Swap(i, j int) { b[i], b[j] = b[j], b[i] }
type ByTarget []Issue
func (b ByTarget) Len() int { return len(b) }
func (b ByTarget) Less(i, j int) bool {
return strings.Compare(b[i].TargetVersion.Name, b[j].TargetVersion.Name) < 0
}
func (b ByTarget) Swap(i, j int) { b[i], b[j] = b[j], b[i] }
func (i Issues) Tags() (tags []string) {
var m = map[string]bool{}
for _, issue := range i {
for _, tag := range issue.Tags {
m[tag.Name] = true
}
}
for tag := range m {
tags = append(tags, tag)
}
sort.Strings(tags)
return
}
func (i Issues) TargetVersions() (targets []string) {
var m = map[string]bool{}
for _, issue := range i {
m[issue.TargetVersion.Name] = true
}
for t := range m {
targets = append(targets, t)
}
sort.Strings(targets)
return
}
func (i Issues) Categories() []string {
var m = map[string]bool{}
for _, issue := range i {
m[issue.Category.Name] = true
}
var r = []string{}
for c := range m {
r = append(r, c)
}
sort.Strings(r)
return r
}
func (i Issues) ByCategory(cat string) (issues Issues) {
for _, issue := range i {
if issue.Category.Name == cat {
issues = append(issues, issue)
}
}
sort.Sort(ById(issues))
return issues
}
func (i Issues) ByCategoryAndTarget(cat, tar string) (issues Issues) {
for _, is := range i {
if is.TargetVersion.Name == tar &&
is.Category.Name == cat {
issues = append(issues, is)
}
}
sort.Sort(ById(issues))
return
}
|