@@ -5,12 +5,16 @@ package commitlog
5
5
import (
6
6
"bytes"
7
7
"fmt"
8
+ "regexp"
8
9
"strings"
9
10
10
11
"github.com/go-git/go-git/v5"
11
12
"github.com/go-git/go-git/v5/plumbing/object"
12
13
)
13
14
15
+ // SupportedKeys - keys that are supported by the package
16
+ const SupportedKeys = "ci|refactor|docs|fix|feat|test|chore|other"
17
+
14
18
// ErrMessage - simple interface around error with a custom message
15
19
type ErrMessage struct {
16
20
Message string
@@ -171,8 +175,9 @@ func CommitLog(path string, startCommitString string, endCommitString string, in
171
175
return "" , ErrMessage {"Error getting commits : " , err }
172
176
}
173
177
174
- var inclusions commitTypeInclusions = bytes .SplitN ([]byte (inclusionFlags ), []byte ("," ), - 1 )
175
-
178
+ var inclusions commitTypeInclusions
179
+ inclusions = append (inclusions , bytes .SplitN ([]byte (inclusionFlags ), []byte ("|" ), - 1 )... )
180
+ inclusions = append (inclusions , bytes .SplitN ([]byte (inclusionFlags ), []byte ("," ), - 1 )... )
176
181
logContainer := logsByCategory {}
177
182
178
183
logContainer .Setup ()
@@ -188,7 +193,8 @@ func CommitLog(path string, startCommitString string, endCommitString string, in
188
193
189
194
for _ , c := range commits {
190
195
normalizedHash := c .Hash .String () + " - " + normalizeCommit (c .Message )
191
- key := strings .SplitN (strings .TrimSpace (c .Message ), ":" , 2 )[0 ]
196
+ key := findKeyInCommit (SupportedKeys , c .Message )
197
+ key = strings .SplitN (strings .TrimSpace (key ), ":" , 2 )[0 ]
192
198
193
199
logContainer .AddCommit (key , normalizedHash , skipClassification )
194
200
@@ -212,3 +218,16 @@ func (inclusions *commitTypeInclusions) checkInclusion(flagToCheck string) bool
212
218
}
213
219
return false
214
220
}
221
+
222
+ func findKeyInCommit (key string , commitMessage string ) string {
223
+ re := regexp .MustCompile (`^(` + key + `)[:]|^((` + key + `)\((\w+[, /\\]*)+\)[:])` )
224
+ if len (re .FindAllStringSubmatch (commitMessage , - 1 )) > 0 {
225
+ keyCheckOne := re .FindAllStringSubmatch (commitMessage , - 1 )[0 ][3 ]
226
+ if keyCheckOne == "" {
227
+ keyCheckTwo := re .FindAllStringSubmatch (commitMessage , - 1 )[0 ][1 ]
228
+ return keyCheckTwo
229
+ }
230
+ return keyCheckOne
231
+ }
232
+ return ""
233
+ }
0 commit comments