This repository has been archived by the owner on Jun 6, 2021. It is now read-only.
forked from gerad/release-notes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
192 lines (161 loc) · 4.37 KB
/
main.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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
package main
import (
"fmt"
"sort"
"strings"
)
type Label string
const (
labelBug = Label("bug")
labelEnhancement = Label("enhancement")
labelNotReleaseNoted = Label("not release noted")
labelDemo = Label("demo")
)
type Category string
const (
categoryBugFix = Category("bug")
categoryDemo = Category("demo")
categoryEnhancement = Category("enhancement")
categoryInternal = Category("internal")
categoryOmitted = Category("omitted")
categoryPendingHotfix = Category("pendingHotfix")
categoryUntagged = Category("untagged")
categoryUpcoming = Category("upcoming")
)
var categoryToText = map[Category]string{
categoryEnhancement: "Enhancements",
categoryBugFix: "Bug Fixes",
categoryUntagged: "Untagged",
categoryPendingHotfix: "Pending Hotfixes",
categoryUpcoming: "Upcoming",
categoryInternal: "Internal",
categoryDemo: "Demo Changes",
}
var outputCategories = []Category{
categoryEnhancement,
categoryBugFix,
categoryUntagged,
categoryPendingHotfix,
categoryUpcoming,
categoryInternal,
categoryDemo,
}
func main() {
config := parseFlags()
githubDirect := NewGithubClient(config.username, config.password)
goGithub := oauth2Client(config.password)
parseBranchTemplate(&config, goGithub)
var app App
if config.useCommits {
app = NewCommitApp(config, githubDirect)
} else {
app = NewIssuesApp(config, githubDirect)
}
filteredIssues := filterIssues(app.Issues(), config.hotfixOnly, config.withInternal)
issuesByCategory := splitIssuesByCategory(filteredIssues)
fmt.Println("<!DOCTYPE html>")
fmt.Println("<html>")
fmt.Println("<body>")
for _, category := range outputCategories {
printIssues(categoryToText[category], issuesByCategory[category], config.withReleaseNotes, config.withTesting)
}
fmt.Println("</body>")
fmt.Println("</html>")
}
func printIssues(label string, issues []Issue, withReleaseNotes, withTesting bool) bool {
if len(issues) == 0 {
return false
}
sort.Sort(IssuesByAuthorAndInternal(issues))
if label != "" {
fmt.Printf("<h3>%s</h3>\n", label)
}
for _, issue := range issues {
releaseNotes := ""
if withReleaseNotes && issue.ReleaseNotes != "" {
releaseNotes = nlToBr(issue.ReleaseNotes) + "<br/>"
}
testing := ""
if withTesting && issue.Testing != "" {
testing = nlToBr(issue.Testing) + "<br/>"
}
fmt.Printf("<b>%s</b> - <a href=\"%s\">#%s</a> - %s<br/>%s%s<br/>\n",
issue.Title, issue.URL, issue.Num, issue.Author, releaseNotes, testing)
}
return true
}
func filterIssues(issues []Issue, hotfixOnly, withInternal bool) []Issue {
var filteredIssues []Issue
for _, issue := range issues {
releaseNoted := !contains(issue.Labels, labelNotReleaseNoted)
if (!hotfixOnly || issue.IsHotfix) && (releaseNoted || withInternal) {
filteredIssues = append(filteredIssues, issue)
}
}
return filteredIssues
}
func splitIssuesByCategory(issues []Issue) map[Category][]Issue {
issuesByCategory := map[Category][]Issue{}
for _, issue := range issues {
category := issueCategory(issue)
issuesByCategory[category] = append(issuesByCategory[category], issue)
}
return issuesByCategory
}
func issueCategory(issue Issue) Category {
isBugFix := contains(issue.Labels, labelBug)
isDemoChange := contains(issue.Labels, labelDemo)
isEnhancement := contains(issue.Labels, labelEnhancement)
isReleaseNoted := !contains(issue.Labels, labelNotReleaseNoted)
if isDemoChange {
return categoryDemo
}
if issue.IsMerged {
if contains(issue.Labels, labelNotReleaseNoted) {
return categoryInternal
}
if isBugFix {
return categoryBugFix
}
if isEnhancement {
return categoryEnhancement
}
return categoryUntagged
}
if issue.IsHotfix {
return categoryPendingHotfix
}
if isReleaseNoted {
return categoryUpcoming
}
return categoryOmitted
}
func contains(list []string, v Label) bool {
for _, l := range list {
if l == string(v) {
return true
}
}
return false
}
func nlToBr(str string) string {
return strings.Replace(str, "\n", "<br>", -1)
}
type App interface {
Issues() []Issue
}
type GithubGateway interface {
Get(path string, v interface{}) error
}
type Issue struct {
Author string
Num string
Title string
Repo string
Labels []string
URL string
ReleaseNotes string
Testing string
IsHotfix bool
IsMerged bool
}