mirror of
https://github.com/thegeeklab/git-sv.git
synced 2024-11-24 21:20:40 +00:00
parent
dc37dbf520
commit
2adacd62ef
@ -62,6 +62,19 @@ func newBranchCfg(skipDetached bool) BranchesConfig {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func newCommitMessageCfg(headerSelector string) CommitMessageConfig {
|
||||||
|
return CommitMessageConfig{
|
||||||
|
Types: []string{"feat", "fix"},
|
||||||
|
Scope: CommitMessageScopeConfig{Values: []string{"", "scope"}},
|
||||||
|
Footer: map[string]CommitMessageFooterConfig{
|
||||||
|
"issue": {Key: "jira", KeySynonyms: []string{"Jira"}},
|
||||||
|
"refs": {Key: "Refs", UseHash: true},
|
||||||
|
},
|
||||||
|
Issue: CommitMessageIssueConfig{Regex: "[A-Z]+-[0-9]+"},
|
||||||
|
HeaderSelector: headerSelector,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// messages samples start.
|
// messages samples start.
|
||||||
var fullMessage = `fix: correct minor typos in code
|
var fullMessage = `fix: correct minor typos in code
|
||||||
|
|
||||||
@ -506,3 +519,35 @@ func Test_parseSubjectMessage(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Test_prepareHeader(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
headerSelector string
|
||||||
|
commitHeader string
|
||||||
|
wantHeader string
|
||||||
|
wantError bool
|
||||||
|
}{
|
||||||
|
{"conventional without selector", "", "feat: something", "feat: something", false},
|
||||||
|
{"conventional with scope without selector", "", "feat(scope): something", "feat(scope): something", false},
|
||||||
|
{"non-conventional without selector", "", "something", "something", false},
|
||||||
|
{"matching conventional with selector with group", "Merged PR (\\d+): (?P<header>.*)", "Merged PR 123: feat: something", "feat: something", false},
|
||||||
|
{"matching non-conventional with selector with group", "Merged PR (\\d+): (?P<header>.*)", "Merged PR 123: something", "something", false},
|
||||||
|
{"matching non-conventional with selector without group", "Merged PR (\\d+): (.*)", "Merged PR 123: something", "", true},
|
||||||
|
{"non-matching non-conventional with selector with group", "Merged PR (\\d+): (?P<header>.*)", "something", "", true},
|
||||||
|
{"matching non-conventional with invalid regex", "Merged PR (\\d+): (?<header>.*)", "Merged PR 123: something", "", true},
|
||||||
|
}
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
msgProcessor := NewMessageProcessor(newCommitMessageCfg(tt.headerSelector), newBranchCfg(false))
|
||||||
|
header, err := msgProcessor.prepareHeader(tt.commitHeader)
|
||||||
|
|
||||||
|
if tt.wantError && err == nil {
|
||||||
|
t.Errorf("prepareHeader() err got = %v, want not nil", err)
|
||||||
|
}
|
||||||
|
if header != tt.wantHeader {
|
||||||
|
t.Errorf("prepareHeader() header got = %v, want %v", header, tt.wantHeader)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user