@@ -5,12 +5,16 @@ package commitlog
55import (
66 "bytes"
77 "fmt"
8+ "regexp"
89 "strings"
910
1011 "github.com/go-git/go-git/v5"
1112 "github.com/go-git/go-git/v5/plumbing/object"
1213)
1314
15+ // SupportedKeys - keys that are supported by the package
16+ const SupportedKeys = "ci|refactor|docs|fix|feat|test|chore|other"
17+
1418// ErrMessage - simple interface around error with a custom message
1519type ErrMessage struct {
1620 Message string
@@ -171,8 +175,9 @@ func CommitLog(path string, startCommitString string, endCommitString string, in
171175 return "" , ErrMessage {"Error getting commits : " , err }
172176 }
173177
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 )... )
176181 logContainer := logsByCategory {}
177182
178183 logContainer .Setup ()
@@ -188,7 +193,8 @@ func CommitLog(path string, startCommitString string, endCommitString string, in
188193
189194 for _ , c := range commits {
190195 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 ]
192198
193199 logContainer .AddCommit (key , normalizedHash , skipClassification )
194200
@@ -212,3 +218,16 @@ func (inclusions *commitTypeInclusions) checkInclusion(flagToCheck string) bool
212218 }
213219 return false
214220}
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