Skip to content

Commit

Permalink
feat: allow revert commits
Browse files Browse the repository at this point in the history
Previously Revert commits would fail the pipeline as they were not considered conventional commit friendly.
This caused issues in multiple projects as commitsar checks would just be ignored.

Closes #434
  • Loading branch information
fallion committed Dec 31, 2021
1 parent 556bc1a commit 159cec8
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
2 changes: 1 addition & 1 deletion internal/commitpipeline/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (pipeline *Pipeline) Run() (*dispatcher.PipelineSuccess, error) {

log.Debugf("Commit found: [hash] %v [message] %v", parsedCommit.Hash.String(), parsedCommit.Heading)

if !text.IsMergeCommit(commitObject.Message) && !text.IsInitialCommit(commitObject.Message) {
if !text.IsMergeCommit(commitObject.Message) && !text.IsInitialCommit(commitObject.Message) && !text.IsRevertCommit(commitObject.Message) {
filteredCommits = append(filteredCommits, commitHash)
}
}
Expand Down
11 changes: 11 additions & 0 deletions pkg/text/is_revert_commit.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package text

import "strings"

func IsRevertCommit(commitMessage string) bool {
if strings.HasPrefix(commitMessage, "Revert") {
return true
}

return strings.HasPrefix(commitMessage, "revert")
}
22 changes: 22 additions & 0 deletions pkg/text/is_revert_commit_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package text

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestIsRevertCommit(t *testing.T) {
tests := map[string]bool{
"Revert some commit": true,
"revert \"some commit\"": true,
"chore: something\n": false,
"fix: test": false,
"fix: Kodiak style regex": false,
}

for test, expected := range tests {
err := IsRevertCommit(test)
assert.Equal(t, expected, err)
}
}

1 comment on commit 159cec8

@vercel
Copy link

@vercel vercel bot commented on 159cec8 Jan 1, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.