Fix ALL issues #6

Merged
fyrchik merged 1 commit from fyrchik/dco-go:better-messages into master 2024-09-04 19:51:22 +00:00
3 changed files with 36 additions and 1 deletions

4
go.mod
View file

@ -5,6 +5,7 @@ go 1.20
require (
github.com/go-git/go-git/v5 v5.7.0
github.com/sethvargo/go-githubactions v1.1.0
github.com/stretchr/testify v1.4.0
)
require (
@ -12,6 +13,7 @@ require (
github.com/ProtonMail/go-crypto v0.0.0-20230518184743-7afd39499903 // indirect
github.com/acomagu/bufpipe v1.0.4 // indirect
github.com/cloudflare/circl v1.3.3 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/emirpasic/gods v1.18.1 // indirect
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
github.com/go-git/go-billy/v5 v5.4.1 // indirect
@ -20,6 +22,7 @@ require (
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
github.com/kevinburke/ssh_config v1.2.0 // indirect
github.com/pjbgf/sha1cd v0.3.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/sergi/go-diff v1.1.0 // indirect
github.com/sethvargo/go-envconfig v0.8.0 // indirect
github.com/skeema/knownhosts v1.1.1 // indirect
@ -28,4 +31,5 @@ require (
golang.org/x/net v0.10.0 // indirect
golang.org/x/sys v0.8.0 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
gopkg.in/yaml.v2 v2.2.4 // indirect
)

View file

@ -14,9 +14,10 @@ import (
gha "github.com/sethvargo/go-githubactions"
)
var rxHeader = regexp.MustCompile(`^(\[\#[0-9]+\]\s|Release|Revert|Reapply)`)
func main() {
// Prepare regexp templates.
rxHeader := regexp.MustCompile(`^(\[\#[0-9]+\]\s|Release|Revert|Reapply)`)
rxSignOff := regexp.MustCompile(`^Signed-off-by:`)
// Open current git dir.

30
main_test.go Normal file
View file

@ -0,0 +1,30 @@
package main
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestCommitMessages(t *testing.T) {
allowed := []string{
"[#1] omg: Make a commit",
"[#666] Omit component",
`Revert "[#114] local: Fix payload type after recent refactoring"`,
`Reapply "[#114] local: Fix payload type after recent refactoring"`,
`Release v0.4.2`,
}
for i := range allowed {
assert.True(t, rxHeader.MatchString(allowed[i]), "message: '%s'", allowed[i])
}
restricted := []string{
"[#xx] omg: Forget numbers",
"#12 Forget brackets",
"Refactor something",
}
for i := range restricted {
assert.False(t, rxHeader.MatchString(restricted[i]), "message: '%s'", restricted[i])
}
}