@@ -8,28 +8,48 @@ import (
88)
99
1010// logContainer - Container of log strings
11- type logContainer []string
11+ type logContainer struct {
12+ include bool
13+ commits []string
14+ }
1215
1316// logsByCategory - Type to hold logs by each's category
1417// to be left as ALLCAPS to be considered as symbols instead of selectors
1518type logsByCategory struct {
16- CI logContainer
17- FIX logContainer
18- REFACTOR logContainer
19- FEATURE logContainer
20- DOCS logContainer
21- CHORE logContainer
22- TEST logContainer
23- OTHER logContainer
19+ CI logContainer
20+ FIX logContainer
21+ REFACTOR logContainer
22+ FEATURE logContainer
23+ DOCS logContainer
24+ CHORE logContainer
25+ TEST logContainer
26+ OTHER logContainer
27+ UNCLASSIFIED logContainer
28+ }
29+
30+ // Setup - Initialize all Log Containers
31+ func (logs logsByCategory ) Setup () {
32+ logs .CI .include = true
33+ logs .FIX .include = true
34+ logs .REFACTOR .include = true
35+ logs .FEATURE .include = true
36+ logs .DOCS .include = true
37+ logs .CHORE .include = true
38+ logs .TEST .include = true
39+ logs .OTHER .include = true
40+ logs .UNCLASSIFIED .include = true
2441}
2542
2643// printLog - loops through the collected logs to write them to string builder
2744func (logs logContainer ) printLog (out * strings.Builder , title string , skipped bool ) {
28- if len (logs ) > 0 {
45+ if ! logs .include {
46+ return
47+ }
48+ if len (logs .commits ) > 0 {
2949 if ! skipped {
3050 out .WriteString (fmt .Sprintf ("\n \n ## %s \n " , title ))
3151 }
32- for _ , item := range logs {
52+ for _ , item := range logs . commits {
3353 out .WriteString (item + "\n " )
3454 }
3555 }
@@ -51,8 +71,68 @@ func (logs *logsByCategory) ToMarkdown(skipped bool) string {
5171 logs .TEST .printLog (& markdownString , "Tests" , skipped )
5272 logs .OTHER .printLog (& markdownString , "Other Changes" , skipped )
5373 } else {
54- logs .OTHER .printLog (& markdownString , "Other Changes" , skipped )
74+ logs .UNCLASSIFIED .include = true
75+ logs .UNCLASSIFIED .printLog (& markdownString , "Unclassified Changes" , skipped )
5576 }
5677
5778 return markdownString .String ()
5879}
80+
81+ // AddCommit - Add a commit to the needed logContainer based on skip and include flag
82+ func (logs * logsByCategory ) AddCommit (key , commitHash string , skip bool ) {
83+ var addCommitToContainer * logContainer
84+ switch key {
85+ case "ci" :
86+ if logs .CI .include && ! skip {
87+ addCommitToContainer = & logs .CI
88+ } else if skip && logs .CI .include {
89+ addCommitToContainer = & logs .UNCLASSIFIED
90+ }
91+ case "fix" :
92+ if logs .FIX .include && ! skip {
93+ addCommitToContainer = & logs .FIX
94+ } else if skip && logs .FIX .include {
95+ addCommitToContainer = & logs .UNCLASSIFIED
96+ }
97+ case "refactor" :
98+ if logs .REFACTOR .include && ! skip {
99+ addCommitToContainer = & logs .REFACTOR
100+ } else if skip && logs .REFACTOR .include {
101+ addCommitToContainer = & logs .UNCLASSIFIED
102+ }
103+ case "feat" , "feature" :
104+ if logs .FEATURE .include && ! skip {
105+ addCommitToContainer = & logs .FEATURE
106+ } else if skip && logs .FEATURE .include {
107+ addCommitToContainer = & logs .UNCLASSIFIED
108+ }
109+ case "docs" :
110+ if logs .DOCS .include && ! skip {
111+ addCommitToContainer = & logs .DOCS
112+ } else if skip && logs .DOCS .include {
113+ addCommitToContainer = & logs .UNCLASSIFIED
114+ }
115+ case "test" :
116+ if logs .TEST .include && ! skip {
117+ addCommitToContainer = & logs .TEST
118+ } else if skip && logs .TEST .include {
119+ addCommitToContainer = & logs .UNCLASSIFIED
120+ }
121+ case "chore" :
122+ if logs .CHORE .include && ! skip {
123+ addCommitToContainer = & logs .CHORE
124+ } else if skip && logs .CHORE .include {
125+ addCommitToContainer = & logs .UNCLASSIFIED
126+ }
127+ default :
128+ if logs .OTHER .include && ! skip {
129+ addCommitToContainer = & logs .OTHER
130+ } else if skip && logs .OTHER .include {
131+ addCommitToContainer = & logs .UNCLASSIFIED
132+ }
133+ }
134+
135+ if addCommitToContainer != nil {
136+ addCommitToContainer .commits = append (addCommitToContainer .commits , commitHash )
137+ }
138+ }
0 commit comments