-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathissues.go
106 lines (90 loc) · 1.95 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package jira
import "time"
type Issue struct {
Id string
Key string
Type string
OriginalEstimateSeconds int
Labels []string
Changes []*Change
}
type Issues []*Issue
type filterfunc func(*Issue) bool
func byType(isseType string) filterfunc {
return func(issue *Issue) bool {
return issue.Type == isseType
}
}
func byLabel(labelToSearch string) filterfunc {
return func(issue *Issue) (containsLabel bool) {
for _, labelFound := range issue.Labels {
if labelFound == labelToSearch {
containsLabel = true
break
}
}
return
}
}
func (issues Issues) Filter(fn filterfunc) Issues {
filteredIssues := make([]*Issue, 0, len(issues))
for _, issue := range issues {
if fn(issue) {
filteredIssues = append(filteredIssues, issue)
}
}
return Issues(filteredIssues)
}
func (issues Issues) FilterByType(issueType string) Issues {
return issues.Filter(byType(issueType))
}
func (issues Issues) FilterByLabel(labelToSearch string) Issues {
return issues.Filter(byLabel(labelToSearch))
}
func (issues Issues) filterByLabel2(labelToSearch string) Issues {
filteredIssues := make([]*Issue, 0, len(issues))
for _, issue := range issues {
var containsLabel bool
for _, labelFound := range issue.Labels {
if labelFound == labelToSearch {
containsLabel = true
break
}
}
if containsLabel {
filteredIssues = append(filteredIssues, issue)
}
}
return Issues(filteredIssues)
}
type Change struct {
Timestamp time.Time
Field string
From string
To string
}
func (c *Change) issueClosed() bool {
if c.Field == "status" {
switch c.From {
case "Open":
break
case "Planung":
break
case "In Progress":
break
case "Geschlossen":
return false
}
switch c.To {
case "Open":
break
case "Planung":
break
case "In Progress":
break
case "Geschlossen":
return true
}
}
return false
}