mirror of
https://github.com/thegeeklab/git-sv.git
synced 2024-11-21 22:10:39 +00:00
feat: add support to append a prefix to issue value on footer metadata
This commit is contained in:
parent
8c266a5a20
commit
50ba69318c
@ -17,5 +17,6 @@ commit-message:
|
||||
footer:
|
||||
issue:
|
||||
key: issue
|
||||
add-value-prefix: '#'
|
||||
issue:
|
||||
regex: '#[0-9]+'
|
||||
regex: '#?[0-9]+'
|
||||
|
@ -127,6 +127,7 @@ commit-message:
|
||||
- Jira
|
||||
- JIRA
|
||||
use-hash: false # If false, use :<space> separator. If true, use <space># separator.
|
||||
add-value-prefix: '' # Add a prefix to issue value.
|
||||
issue:
|
||||
regex: '[A-Z]+-[0-9]+' # Regex for issue id.
|
||||
```
|
||||
|
@ -28,6 +28,7 @@ type CommitMessageFooterConfig struct {
|
||||
Key string `yaml:"key"`
|
||||
KeySynonyms []string `yaml:"key-synonyms"`
|
||||
UseHash bool `yaml:"use-hash"`
|
||||
AddValuePrefix string `yaml:"add-value-prefix"`
|
||||
}
|
||||
|
||||
// CommitMessageIssueConfig issue preferences.
|
||||
|
@ -117,6 +117,9 @@ func (p MessageProcessorImpl) Enhance(branch string, message string) (string, er
|
||||
}
|
||||
|
||||
func formatIssueFooter(cfg CommitMessageFooterConfig, issue string) string {
|
||||
if !strings.HasPrefix(issue, cfg.AddValuePrefix) {
|
||||
issue = cfg.AddValuePrefix + issue
|
||||
}
|
||||
if cfg.UseHash {
|
||||
return fmt.Sprintf("%s #%s", cfg.Key, strings.TrimPrefix(issue, "#"))
|
||||
}
|
||||
|
@ -25,6 +25,15 @@ var ccfgHash = CommitMessageConfig{
|
||||
Issue: CommitMessageIssueConfig{Regex: "[A-Z]+-[0-9]+"},
|
||||
}
|
||||
|
||||
var ccfgGitIssue = CommitMessageConfig{
|
||||
Types: []string{"feat", "fix"},
|
||||
Scope: CommitMessageScopeConfig{},
|
||||
Footer: map[string]CommitMessageFooterConfig{
|
||||
"issue": {Key: "issue", KeySynonyms: []string{"Issue"}, UseHash: false, AddValuePrefix: "#"},
|
||||
},
|
||||
Issue: CommitMessageIssueConfig{Regex: "#?[0-9]+"},
|
||||
}
|
||||
|
||||
var ccfgEmptyIssue = CommitMessageConfig{
|
||||
Types: []string{"feat", "fix"},
|
||||
Scope: CommitMessageScopeConfig{},
|
||||
@ -166,6 +175,9 @@ func TestMessageProcessorImpl_Enhance(t *testing.T) {
|
||||
{"no issue on branch name", ccfg, "branch", "fix: fix something", "", true},
|
||||
{"unexpected branch name", ccfg, "feature /JIRA-123", "fix: fix something", "", true},
|
||||
{"issue on branch name using hash", ccfgHash, "JIRA-123-some-description", "fix: fix something", "\njira #JIRA-123", false},
|
||||
{"numeric issue on branch name", ccfgGitIssue, "#13", "fix: fix something", "\nissue: #13", false},
|
||||
{"numeric issue on branch name without hash", ccfgGitIssue, "13", "fix: fix something", "\nissue: #13", false},
|
||||
{"numeric issue on branch name with description without hash", ccfgGitIssue, "13-some-fix", "fix: fix something", "\nissue: #13", false},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
@ -343,6 +355,8 @@ func TestMessageProcessorImpl_Format(t *testing.T) {
|
||||
{"with multiline body", ccfg, NewCommitMessage("feat", "", "something", multilineBody, "", ""), "feat: something", multilineBody, ""},
|
||||
{"full message", ccfg, NewCommitMessage("feat", "scope", "something", multilineBody, "JIRA-123", "breaks"), "feat(scope): something", multilineBody, fullFooter},
|
||||
{"config without issue key", ccfgEmptyIssue, NewCommitMessage("feat", "", "something", "", "JIRA-123", ""), "feat: something", "", ""},
|
||||
{"with issue and issue prefix", ccfgGitIssue, NewCommitMessage("feat", "", "something", "", "123", ""), "feat: something", "", "issue: #123"},
|
||||
{"with #issue and issue prefix", ccfgGitIssue, NewCommitMessage("feat", "", "something", "", "#123", ""), "feat: something", "", "issue: #123"},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
|
Loading…
Reference in New Issue
Block a user