mirror of
https://github.com/thegeeklab/git-sv.git
synced 2024-11-21 22:10:39 +00:00
feat: support # as footer metadata separator
This commit is contained in:
parent
abeae14b96
commit
57995c3458
@ -97,7 +97,7 @@ func (p MessageProcessorImpl) Validate(message string) error {
|
|||||||
|
|
||||||
// Enhance add metadata on commit message.
|
// Enhance add metadata on commit message.
|
||||||
func (p MessageProcessorImpl) Enhance(branch string, message string) (string, error) {
|
func (p MessageProcessorImpl) Enhance(branch string, message string) (string, error) {
|
||||||
if p.branchesCfg.DisableIssue || p.messageCfg.IssueFooterConfig().Key == "" || hasIssueID(message, p.messageCfg.IssueFooterConfig().Key) {
|
if p.branchesCfg.DisableIssue || p.messageCfg.IssueFooterConfig().Key == "" || hasIssueID(message, p.messageCfg.IssueFooterConfig()) {
|
||||||
return "", nil //enhance disabled
|
return "", nil //enhance disabled
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -151,7 +151,11 @@ func (p MessageProcessorImpl) Format(msg CommitMessage) (string, string, string)
|
|||||||
if footer.Len() > 0 {
|
if footer.Len() > 0 {
|
||||||
footer.WriteString("\n")
|
footer.WriteString("\n")
|
||||||
}
|
}
|
||||||
footer.WriteString(fmt.Sprintf("%s: %s", p.messageCfg.IssueFooterConfig().Key, issue))
|
if p.messageCfg.IssueFooterConfig().UseHash {
|
||||||
|
footer.WriteString(fmt.Sprintf("%s #%s", p.messageCfg.IssueFooterConfig().Key, strings.TrimPrefix(issue, "#")))
|
||||||
|
} else {
|
||||||
|
footer.WriteString(fmt.Sprintf("%s: %s", p.messageCfg.IssueFooterConfig().Key, issue))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return header.String(), msg.Body, footer.String()
|
return header.String(), msg.Body, footer.String()
|
||||||
@ -225,8 +229,13 @@ func hasFooter(message string) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func hasIssueID(message, issueKeyName string) bool {
|
func hasIssueID(message string, issueConfig CommitMessageFooterConfig) bool {
|
||||||
r := regexp.MustCompile(fmt.Sprintf("(?m)^%s: .+$", issueKeyName))
|
var r *regexp.Regexp
|
||||||
|
if issueConfig.UseHash {
|
||||||
|
r = regexp.MustCompile(fmt.Sprintf("(?m)^%s #.+$", issueConfig.Key))
|
||||||
|
} else {
|
||||||
|
r = regexp.MustCompile(fmt.Sprintf("(?m)^%s: .+$", issueConfig.Key))
|
||||||
|
}
|
||||||
return r.MatchString(message)
|
return r.MatchString(message)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -174,26 +174,32 @@ jira: JIRA-123`
|
|||||||
)
|
)
|
||||||
|
|
||||||
func Test_hasIssueID(t *testing.T) {
|
func Test_hasIssueID(t *testing.T) {
|
||||||
|
cfgColon := CommitMessageFooterConfig{Key: "jira"}
|
||||||
|
cfgHash := CommitMessageFooterConfig{Key: "jira", UseHash: true}
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
message string
|
message string
|
||||||
issueKeyName string
|
issueCfg CommitMessageFooterConfig
|
||||||
want bool
|
want bool
|
||||||
}{
|
}{
|
||||||
{"single line without issue", "feat: something", "jira", false},
|
{"single line without issue", "feat: something", cfgColon, false},
|
||||||
{"multi line without issue", `feat: something
|
{"multi line without issue", `feat: something
|
||||||
|
|
||||||
yay`, "jira", false},
|
yay`, cfgColon, false},
|
||||||
{"multi line without jira issue", `feat: something
|
{"multi line without jira issue", `feat: something
|
||||||
|
|
||||||
jira1: JIRA-123`, "jira", false},
|
jira1: JIRA-123`, cfgColon, false},
|
||||||
{"multi line with issue", `feat: something
|
{"multi line with issue", `feat: something
|
||||||
|
|
||||||
jira: JIRA-123`, "jira", true},
|
jira: JIRA-123`, cfgColon, true},
|
||||||
|
{"multi line with issue and hash", `feat: something
|
||||||
|
|
||||||
|
jira #JIRA-123`, cfgHash, true},
|
||||||
}
|
}
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
if got := hasIssueID(tt.message, tt.issueKeyName); got != tt.want {
|
if got := hasIssueID(tt.message, tt.issueCfg); got != tt.want {
|
||||||
t.Errorf("hasIssueID() = %v, want %v", got, tt.want)
|
t.Errorf("hasIssueID() = %v, want %v", got, tt.want)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user