Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions log/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand All @@ -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)

Expand All @@ -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 ""
}
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down