@@ -41,15 +41,15 @@ func (logs logsByCategory) Setup() {
41
41
}
42
42
43
43
// printLog - loops through the collected logs to write them to string builder
44
- func (logs logContainer ) printLog (out * strings.Builder , title string , skipped bool ) {
45
- if ! logs .include {
44
+ func (container logContainer ) printLog (out * strings.Builder , title string , skipped bool ) {
45
+ if ! container .include {
46
46
return
47
47
}
48
- if len (logs .commits ) > 0 {
48
+ if len (container .commits ) > 0 {
49
49
if ! skipped {
50
50
out .WriteString (fmt .Sprintf ("\n \n ## %s \n " , title ))
51
51
}
52
- for _ , item := range logs .commits {
52
+ for _ , item := range container .commits {
53
53
out .WriteString (item + "\n " )
54
54
}
55
55
}
@@ -80,59 +80,41 @@ func (logs *logsByCategory) ToMarkdown(skipped bool) string {
80
80
81
81
// AddCommit - Add a commit to the needed logContainer based on skip and include flag
82
82
func (logs * logsByCategory ) AddCommit (key , commitHash string , skip bool ) {
83
- var addCommitToContainer * logContainer
83
+ addCommitToContainer := logs .findContainerByKey (key )
84
+ if ! addCommitToContainer .canAddToContainer (skip ) {
85
+ addCommitToContainer = & logs .UNCLASSIFIED
86
+ }
87
+ if addCommitToContainer != nil {
88
+ addCommitToContainer .commits = append (addCommitToContainer .commits , commitHash )
89
+ }
90
+ }
91
+
92
+ func (logs * logsByCategory ) findContainerByKey (key string ) * logContainer {
84
93
switch key {
85
94
case "ci" :
86
- if logs .CI .include && ! skip {
87
- addCommitToContainer = & logs .CI
88
- } else if skip && logs .CI .include {
89
- addCommitToContainer = & logs .UNCLASSIFIED
90
- }
95
+ return & logs .CI
91
96
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
+ return & logs .FIX
97
98
case "refactor" :
98
- if logs .REFACTOR .include && ! skip {
99
- addCommitToContainer = & logs .REFACTOR
100
- } else if skip && logs .REFACTOR .include {
101
- addCommitToContainer = & logs .UNCLASSIFIED
102
- }
99
+ return & logs .REFACTOR
103
100
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
- }
101
+ return & logs .FEATURE
109
102
case "docs" :
110
- if logs .DOCS .include && ! skip {
111
- addCommitToContainer = & logs .DOCS
112
- } else if skip && logs .DOCS .include {
113
- addCommitToContainer = & logs .UNCLASSIFIED
114
- }
103
+ return & logs .DOCS
115
104
case "test" :
116
- if logs .TEST .include && ! skip {
117
- addCommitToContainer = & logs .TEST
118
- } else if skip && logs .TEST .include {
119
- addCommitToContainer = & logs .UNCLASSIFIED
120
- }
105
+ return & logs .TEST
121
106
case "chore" :
122
- if logs .CHORE .include && ! skip {
123
- addCommitToContainer = & logs .CHORE
124
- } else if skip && logs .CHORE .include {
125
- addCommitToContainer = & logs .UNCLASSIFIED
126
- }
107
+ return & logs .CHORE
127
108
default :
128
- if logs .OTHER .include && ! skip {
129
- addCommitToContainer = & logs .OTHER
130
- } else if skip && logs .OTHER .include {
131
- addCommitToContainer = & logs .UNCLASSIFIED
132
- }
109
+ return & logs .OTHER
133
110
}
111
+ }
134
112
135
- if addCommitToContainer != nil {
136
- addCommitToContainer .commits = append (addCommitToContainer .commits , commitHash )
113
+ func (container * logContainer ) canAddToContainer (skip bool ) bool {
114
+ if container .include && ! skip {
115
+ return true
116
+ } else if skip && container .include {
117
+ return false
137
118
}
119
+ return true
138
120
}
0 commit comments