mirror of
https://github.com/apricote/releaser-pleaser.git
synced 2026-02-08 02:37:04 +00:00
feat: analyze commits for conventional commit messages
This commit is contained in:
parent
74ea8fba17
commit
78f4368018
5 changed files with 203 additions and 1 deletions
133
commits_test.go
Normal file
133
commits_test.go
Normal file
|
|
@ -0,0 +1,133 @@
|
|||
package rp
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/leodido/go-conventionalcommits"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestAnalyzeCommits(t *testing.T) {
|
||||
type args struct {
|
||||
commits []Commit
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
commits []Commit
|
||||
expectedCommits []AnalyzedCommit
|
||||
expectedBump conventionalcommits.VersionBump
|
||||
wantErr assert.ErrorAssertionFunc
|
||||
}{
|
||||
{
|
||||
name: "empty commits",
|
||||
commits: []Commit{},
|
||||
expectedCommits: []AnalyzedCommit{},
|
||||
expectedBump: conventionalcommits.UnknownVersion,
|
||||
wantErr: assert.NoError,
|
||||
},
|
||||
{
|
||||
name: "malformed commit message",
|
||||
commits: []Commit{
|
||||
{
|
||||
Message: "aksdjaklsdjka",
|
||||
},
|
||||
},
|
||||
expectedCommits: nil,
|
||||
expectedBump: conventionalcommits.UnknownVersion,
|
||||
wantErr: assert.Error,
|
||||
},
|
||||
{
|
||||
name: "drops unreleasable",
|
||||
commits: []Commit{
|
||||
{
|
||||
Message: "chore: foobar",
|
||||
},
|
||||
},
|
||||
expectedCommits: []AnalyzedCommit{},
|
||||
expectedBump: conventionalcommits.UnknownVersion,
|
||||
wantErr: assert.NoError,
|
||||
},
|
||||
{
|
||||
name: "highest bump (patch)",
|
||||
commits: []Commit{
|
||||
{
|
||||
Message: "chore: foobar",
|
||||
},
|
||||
{
|
||||
Message: "fix: blabla",
|
||||
},
|
||||
},
|
||||
expectedCommits: []AnalyzedCommit{
|
||||
{
|
||||
Commit: Commit{Message: "fix: blabla"},
|
||||
Type: "fix",
|
||||
Description: "blabla",
|
||||
},
|
||||
},
|
||||
expectedBump: conventionalcommits.PatchVersion,
|
||||
wantErr: assert.NoError,
|
||||
},
|
||||
{
|
||||
name: "highest bump (minor)",
|
||||
commits: []Commit{
|
||||
{
|
||||
Message: "fix: blabla",
|
||||
},
|
||||
{
|
||||
Message: "feat: foobar",
|
||||
},
|
||||
},
|
||||
expectedCommits: []AnalyzedCommit{
|
||||
{
|
||||
Commit: Commit{Message: "fix: blabla"},
|
||||
Type: "fix",
|
||||
Description: "blabla",
|
||||
},
|
||||
{
|
||||
Commit: Commit{Message: "feat: foobar"},
|
||||
Type: "feat",
|
||||
Description: "foobar",
|
||||
},
|
||||
},
|
||||
expectedBump: conventionalcommits.MinorVersion,
|
||||
wantErr: assert.NoError,
|
||||
},
|
||||
|
||||
{
|
||||
name: "highest bump (major)",
|
||||
commits: []Commit{
|
||||
{
|
||||
Message: "fix: blabla",
|
||||
},
|
||||
{
|
||||
Message: "feat!: foobar",
|
||||
},
|
||||
},
|
||||
expectedCommits: []AnalyzedCommit{
|
||||
{
|
||||
Commit: Commit{Message: "fix: blabla"},
|
||||
Type: "fix",
|
||||
Description: "blabla",
|
||||
},
|
||||
{
|
||||
Commit: Commit{Message: "feat!: foobar"},
|
||||
Type: "feat",
|
||||
Description: "foobar",
|
||||
},
|
||||
},
|
||||
expectedBump: conventionalcommits.MajorVersion,
|
||||
wantErr: assert.NoError,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
analyzedCommits, versionBump, err := AnalyzeCommits(tt.commits)
|
||||
if !tt.wantErr(t, err) {
|
||||
return
|
||||
}
|
||||
|
||||
assert.Equal(t, tt.expectedCommits, analyzedCommits)
|
||||
assert.Equal(t, tt.expectedBump, versionBump)
|
||||
})
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue