Skip to content

Commit 159cec8

Browse files
Simon ProchazkaSimon Prochazka
authored andcommitted
feat: allow revert commits
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 aevea#434
1 parent 556bc1a commit 159cec8

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed

internal/commitpipeline/run.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func (pipeline *Pipeline) Run() (*dispatcher.PipelineSuccess, error) {
5959

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

62-
if !text.IsMergeCommit(commitObject.Message) && !text.IsInitialCommit(commitObject.Message) {
62+
if !text.IsMergeCommit(commitObject.Message) && !text.IsInitialCommit(commitObject.Message) && !text.IsRevertCommit(commitObject.Message) {
6363
filteredCommits = append(filteredCommits, commitHash)
6464
}
6565
}

pkg/text/is_revert_commit.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package text
2+
3+
import "strings"
4+
5+
func IsRevertCommit(commitMessage string) bool {
6+
if strings.HasPrefix(commitMessage, "Revert") {
7+
return true
8+
}
9+
10+
return strings.HasPrefix(commitMessage, "revert")
11+
}

pkg/text/is_revert_commit_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package text
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/assert"
7+
)
8+
9+
func TestIsRevertCommit(t *testing.T) {
10+
tests := map[string]bool{
11+
"Revert some commit": true,
12+
"revert \"some commit\"": true,
13+
"chore: something\n": false,
14+
"fix: test": false,
15+
"fix: Kodiak style regex": false,
16+
}
17+
18+
for test, expected := range tests {
19+
err := IsRevertCommit(test)
20+
assert.Equal(t, expected, err)
21+
}
22+
}

0 commit comments

Comments
 (0)