diff --git a/README.md b/README.md index 18a0f23..f387c22 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,7 @@ Project created overnight, to prove that management of semantic versioning is NO ### Important changes * From version `1.4.2+` as pointed out in [issue #12](https://github.com/lukaszraczylo/semver-generator/issues/12) commits from merge will not be included in the calculations and commits themselves will bump the version on first match ( starting checks from `patch` upwards ). +* Added support for blacklisting terms to ignore specific commits, branch names, and merge messages from version calculations. ### Usage @@ -172,6 +173,11 @@ force: minor: 0 patch: 1 commit: 69fbe2df696f40281b9104ff073d26186cde1024 +blacklist: + - "Merge branch" + - "Merge pull request" + - "feature/" + - "feature:" wording: patch: - update @@ -190,10 +196,11 @@ wording: * `version`: is not respected at the moment, introduced for potential backwards compatibility in future * `force`: sets the "starting" version, you don't need to specify this section as the default is always `0` * `force.commit`: allows you to set commit hash from which the calculations should start +* `blacklist`: terms to ignore when processing commits. Any commit containing these terms will be skipped in version calculations. Useful for ignoring merge commits, feature branch names, and other unwanted triggers. * `wording`: words the program should look for in the git commits to increment (patch|minor|major) ### Good to know * Word matching uses fuzzy search AND is case INSENSITIVE * I do not recommend using common words ( like "the" from the example configuration ) -* You can specify env variable `LOG_LEVEL=debug` to see what exactly happens during the calculations \ No newline at end of file +* You can specify env variable `LOG_LEVEL=debug` to see what exactly happens during the calculations diff --git a/cmd/main.go b/cmd/main.go index ea6a298..2d784be 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -81,6 +81,7 @@ type Setup struct { Semver SemVer Generate bool UseLocal bool + Blacklist []string } type CommitDetails struct { @@ -96,12 +97,17 @@ type TagDetails struct { } func checkMatches(content []string, targets []string) bool { - if fuzzy.MatchNormalizedFold(strings.Join(content, " "), "Merge branch") { - logger.Debug(&libpack_logger.LogMessage{ - Message: "Merge detected, ignoring commits within", - Pairs: map[string]interface{}{"content": strings.Join(content, " ")}, - }) - return false + contentStr := strings.Join(content, " ") + + // Check against blacklist terms first + for _, blacklistTerm := range repo.Blacklist { + if fuzzy.MatchNormalizedFold(contentStr, blacklistTerm) { + logger.Debug(&libpack_logger.LogMessage{ + Message: "Blacklisted term detected, ignoring commit", + Pairs: map[string]interface{}{"content": contentStr, "blacklist_term": blacklistTerm}, + }) + return false + } } for _, tgt := range targets { r := fuzzy.FindNormalizedFold(tgt, content) @@ -354,6 +360,7 @@ func (s *Setup) ReadConfig(file string) error { } viper.UnmarshalKey("wording", &s.Wording) viper.UnmarshalKey("force", &s.Force) + viper.UnmarshalKey("blacklist", &s.Blacklist) return err } diff --git a/config.yaml b/config.yaml index ebbc077..3d2559b 100644 --- a/config.yaml +++ b/config.yaml @@ -3,6 +3,11 @@ force: major: 1 existing: true strict: false +blacklist: + - "Merge branch" + - "Merge pull request" + - "feature/" + - "feature:" wording: patch: - update