Skip to content

Commit

Permalink
Merge pull request #24 from ArtusC/add-plural-of-messages
Browse files Browse the repository at this point in the history
feat: add new merge master commit message to be validated
  • Loading branch information
ebbauer authored Oct 25, 2024
2 parents 83eb060 + eb22507 commit a398c15
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 6 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
v2.0.4:
- Added a new commit message to be validated for merge from master to the branch (@artus.andermann)

v2.0.3:
- Fix IsValidMessage method adding a new exception for merge from master to the branch (@esequiel.virtuoso)

Expand Down
30 changes: 24 additions & 6 deletions src/commit-message/commit_message_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package commitmessage
import (
"errors"
"fmt"
"regexp"
"strings"
)

Expand Down Expand Up @@ -78,17 +79,34 @@ func (f *CommitMessage) PrettifyCommitMessage(commitMessage string) (string, err
func isMergeMasterToBranch(message string) bool {
splitedMessage := strings.Split(strings.ToLower(message), "\n")

mergePatterns := []string{
"'origin/master' into",
"merge branches 'master' into",
"merge branch 'master' into",
"merge branch 'master' of",
"'origin/main' into",
"merge branch 'main' into",
"merge branch 'main' of",
}

mergeRegexPattern := `merge branches '.*' and 'master' of`
re := regexp.MustCompile(mergeRegexPattern)

for _, row := range splitedMessage {
lowerRow := strings.ToLower(row)
if strings.Contains(lowerRow, "'origin/master' into") ||
strings.Contains(lowerRow, "merge branch 'master' into") ||
strings.Contains(lowerRow, "merge branch 'master' of") ||
strings.Contains(lowerRow, "'origin/main' into") ||
strings.Contains(lowerRow, "merge branch 'main' into") ||
strings.Contains(lowerRow, "merge branch 'main' of") {

found := re.MatchString(lowerRow)
if found {
return true
}

for _, pattern := range mergePatterns {
if strings.Contains(lowerRow, pattern) {
return true
}
}
}

return false
}

Expand Down
4 changes: 4 additions & 0 deletions src/commit-message/commit_message_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ func TestIsValidMessageSuccess(t *testing.T) {
actual := f.commitMessageManager.IsValidMessage(message)
tests.AssertTrue(t, actual)

message = "Merge branches 'sample-branch' and 'master' of ssh://gitlab.lalala/j/dv into sample-branch"
actual = f.commitMessageManager.IsValidMessage(message)
tests.AssertTrue(t, actual)

message = "feat(scope): This is a message"
actual = f.commitMessageManager.IsValidMessage(message)
tests.AssertTrue(t, actual)
Expand Down

0 comments on commit a398c15

Please sign in to comment.