/
issue_meta.go
112 lines (100 loc) · 2.33 KB
/
issue_meta.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
package jirarest
import (
"strings"
"time"
"github.com/grokify/gojira"
"github.com/grokify/mogo/text/markdown"
)
type IssueMetas []IssueMeta
// HighestEpic returns the highest most Epic.
func (ims IssueMetas) HighestEpic() *IssueMeta {
return ims.HighestType(gojira.TypeEpic)
}
func (ims IssueMetas) HighestType(issueType string) *IssueMeta {
im := IssueMeta{}
typeFound := true
for _, imx := range ims {
if imx.Type == issueType {
im = imx
typeFound = true
}
}
if !typeFound {
return nil
}
return &im
}
// HighestAboveEpic returns the highest item that follows an Epic.
func (ims IssueMetas) HighestAboveEpic() *IssueMeta {
im := IssueMeta{}
epicFound := false
postEpicFound := false
for _, imx := range ims {
if imx.Type == gojira.TypeEpic {
epicFound = true
} else if epicFound && imx.Type != gojira.TypeEpic {
im = imx
postEpicFound = true
}
}
if !postEpicFound {
return nil
}
return &im
}
type IssueMeta struct {
AssigneeName string
CreateTime *time.Time
CreatorName string
EpicName string
Key string
KeyURL string
Labels []string
ParentKey string
Project string
ProjectKey string
Resolution string
Status string
Summary string
Type string
UpdateTime *time.Time
}
func (im *IssueMeta) String() string {
k := strings.TrimSpace(im.Key)
s := strings.TrimSpace(im.Summary)
if k == "" && s == "" {
return ""
}
parts := []string{}
if len(k) > 0 {
parts = append(parts, k)
}
if len(s) > 0 {
parts = append(parts, s)
}
return strings.Join(parts, ": ")
}
func (im *IssueMeta) BuildKeyURL(baseURL string) {
if strings.TrimSpace(baseURL) != "" && strings.TrimSpace(im.Key) != "" {
im.KeyURL = BuildJiraIssueURL(baseURL, im.Key)
}
}
// KeyLinkMarkdown returns a link of both `Key` and `KeyURL` are non-empty,`Key` if `Key` is non-empty or
// an empty string if both are empty.
func (im *IssueMeta) KeyLinkMarkdown() string {
if strings.TrimSpace(im.Key) == "" {
return ""
} else if strings.TrimSpace(im.KeyURL) == "" {
return im.Key
} else {
return markdown.Linkify(im.KeyURL, im.Key)
}
}
/*
keyURL := BuildJiraIssueURL(baseURL, key)
keyDisplay = markdown.Linkify(keyURL, key)
if len(epicKeyDisplay) > 0 {
epicKeyURL := BuildJiraIssueURL(baseURL, im.EpicKey())
epicKeyDisplay = markdown.Linkify(epicKeyURL, im.EpicKey())
}
*/