Add support for the blacklisting

This commit is contained in:
2025-02-08 01:55:10 +00:00
parent 925c4f5abe
commit 38b1869177
3 changed files with 26 additions and 7 deletions
+8 -1
View File
@@ -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
* You can specify env variable `LOG_LEVEL=debug` to see what exactly happens during the calculations
+13 -6
View File
@@ -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
}
+5
View File
@@ -3,6 +3,11 @@ force:
major: 1
existing: true
strict: false
blacklist:
- "Merge branch"
- "Merge pull request"
- "feature/"
- "feature:"
wording:
patch:
- update