diff --git a/log/log.go b/log/log.go index 6329dd0..a0c071f 100644 --- a/log/log.go +++ b/log/log.go @@ -5,12 +5,16 @@ package commitlog import ( "bytes" "fmt" + "regexp" "strings" "github.com/go-git/go-git/v5" "github.com/go-git/go-git/v5/plumbing/object" ) +// SupportedKeys - keys that are supported by the package +const SupportedKeys = "ci|refactor|docs|fix|feat|test|chore|other" + // ErrMessage - simple interface around error with a custom message type ErrMessage struct { Message string @@ -171,8 +175,9 @@ func CommitLog(path string, startCommitString string, endCommitString string, in return "", ErrMessage{"Error getting commits : ", err} } - var inclusions commitTypeInclusions = bytes.SplitN([]byte(inclusionFlags), []byte(","), -1) - + var inclusions commitTypeInclusions + inclusions = append(inclusions, bytes.SplitN([]byte(inclusionFlags), []byte("|"), -1)...) + inclusions = append(inclusions, bytes.SplitN([]byte(inclusionFlags), []byte(","), -1)...) logContainer := logsByCategory{} logContainer.Setup() @@ -188,7 +193,8 @@ func CommitLog(path string, startCommitString string, endCommitString string, in for _, c := range commits { normalizedHash := c.Hash.String() + " - " + normalizeCommit(c.Message) - key := strings.SplitN(strings.TrimSpace(c.Message), ":", 2)[0] + key := findKeyInCommit(SupportedKeys, c.Message) + key = strings.SplitN(strings.TrimSpace(key), ":", 2)[0] logContainer.AddCommit(key, normalizedHash, skipClassification) @@ -212,3 +218,16 @@ func (inclusions *commitTypeInclusions) checkInclusion(flagToCheck string) bool } return false } + +func findKeyInCommit(key string, commitMessage string) string { + re := regexp.MustCompile(`^(` + key + `)[:]|^((` + key + `)\((\w+[, /\\]*)+\)[:])`) + if len(re.FindAllStringSubmatch(commitMessage, -1)) > 0 { + keyCheckOne := re.FindAllStringSubmatch(commitMessage, -1)[0][3] + if keyCheckOne == "" { + keyCheckTwo := re.FindAllStringSubmatch(commitMessage, -1)[0][1] + return keyCheckTwo + } + return keyCheckOne + } + return "" +} diff --git a/main.go b/main.go index c5aa2ee..c3f5b57 100644 --- a/main.go +++ b/main.go @@ -14,7 +14,7 @@ func main() { var repoPath = flag.String("p", ".", "path to the repository, points to the current working directory by default") var startCommit = flag.String("s", "", "commit hash string / revision (ex. HEAD, HEAD^, HEAD~2) \n to start collecting commit messages from") var endCommit = flag.String("e", "", "commit hash string / revision (ex. HEAD, HEAD^, HEAD~2) \n to stop collecting commit message at") - var inclusionFlags = flag.String("i", "ci,refactor,docs,fix,feat,test,chore,other", "commit types to be includes") + var inclusionFlags = flag.String("i", clog.SupportedKeys, "commit types to be includes") var skipClassification = flag.Bool("skip", false, "if true will skip trying to classify and just give a list of changes") flag.Parse()