-
Notifications
You must be signed in to change notification settings - Fork 1
/
print_entries.go
153 lines (126 loc) · 3.25 KB
/
print_entries.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
package main
import (
"fmt"
"sort"
)
func displayEntries(entries []Entry) {
fmt.Printf("Displayable Commits by type :\n")
for j := 0; j < len(entries); j++ {
entry := entries[j]
keys := make([]string, 0, len(entry.commitMap))
for k := range entry.commitMap {
keys = append(keys, k)
}
fmt.Printf("type : %s\t\ttitle: %s\t\tmessage count: %d\n", entry.id, entry.name, len(keys))
}
fmt.Printf("\n")
}
func getBasicResult(entries []Entry) string {
var result string
var ticketURLPrefix = getTicketURLPrefix()
for typeIndex := 0; typeIndex < len(entries); typeIndex++ {
entry := entries[typeIndex]
if len(entry.commitMap) == 0 {
continue
}
result += entry.name + "\n"
keys := getSortedKeys(entry)
for j := 0; j < len(keys); j++ {
key := keys[j]
commitList := entry.commitMap[key]
result += "\n\t• " + key + ": "
if len(commitList) > 1 {
for msgIndex := 0; msgIndex < len(commitList); msgIndex++ {
result += "\n"
result += "\t\t - " + commitToString(commitList[msgIndex], ticketURLPrefix)
}
} else {
result += commitToString(commitList[0], ticketURLPrefix)
}
result += "\n"
}
result += "\n\n"
}
if len(result) == 0 {
fmt.Printf("\n\n === No Debug Changelog Generated === \n\n")
}
return result
}
func getSlackResult(entries []Entry) string {
var result string
var ticketURLPrefix = getTicketURLPrefix()
for typeIndex := 0; typeIndex < len(entries); typeIndex++ {
entry := entries[typeIndex]
showTitlePart := false
typeResult := ""
if len(entry.commitMap) == 0 {
continue
}
keys := getSortedKeys(entry)
for j := 0; j < len(keys); j++ {
key := keys[j]
commitList := entry.commitMap[key]
showSubTitlePart := false
scopeResult := ""
for msgIndex := 0; msgIndex < len(commitList); msgIndex++ {
if len(commitList[msgIndex].ticketIds) == 0 {
continue
}
if showTitlePart == false {
showTitlePart = true
scopeResult += entry.name + "\n"
}
if showSubTitlePart == false {
showSubTitlePart = true
scopeResult += "\n\t• " + key
}
scopeResult += commitToMarkdownString(commitList[msgIndex], ticketURLPrefix)
}
if scopeResult != "" {
typeResult += scopeResult + "\n"
}
}
if typeResult != "" {
result += typeResult + "\n\n"
}
}
if len(result) == 0 {
fmt.Printf("\n\n === No Slack Changelog Generated === \n\n")
}
return result
}
func getSortedKeys(entry Entry) []string {
keys := make([]string, 0, len(entry.commitMap))
for k := range entry.commitMap {
keys = append(keys, k)
}
sort.Strings(keys)
return keys
}
func commitToString(commit Commit, urlPrefix string) string {
var result = commit.message
var ids = commit.ticketIds
for i := 0; i < len(ids); i++ {
result += " #" + ids[i]
}
return result
}
func commitToMarkdownString(commit Commit, urlPrefix string) string {
var result = ""
var ids = commit.ticketIds
for i := 0; i < len(ids); i++ {
var id = ids[i]
var ticketTitle = getTitleForTicket(id)
if ticketTitle != "" {
result += "\n\t\t - "
result += ticketTitle + " <" + urlPrefix + id + "|#" + id + ">"
} else {
result += "\n\t\t - "
if i == 0 {
result += commit.message
}
result += " <" + urlPrefix + id + "|#" + id + ">"
}
}
return result
}