mirror of
https://github.com/thegeeklab/git-sv.git
synced 2024-11-21 22:10:39 +00:00
feat: remove breaking change synonyms support
BREAKING CHANGE: is not possible to set breaking change footer synonym
This commit is contained in:
parent
df26b50096
commit
2ae35c91af
@ -82,8 +82,7 @@ func defaultConfig() Config {
|
||||
Types: []string{"build", "ci", "chore", "docs", "feat", "fix", "perf", "refactor", "revert", "style", "test"},
|
||||
Scope: sv.CommitMessageScopeConfig{},
|
||||
Footer: map[string]sv.CommitMessageFooterConfig{
|
||||
"issue": {Key: "jira", KeySynonyms: []string{"Jira", "JIRA"}},
|
||||
"breaking-change": {Key: "BREAKING CHANGE", KeySynonyms: []string{"BREAKING CHANGES"}},
|
||||
"issue": {Key: "jira", KeySynonyms: []string{"Jira", "JIRA"}},
|
||||
},
|
||||
Issue: sv.CommitMessageIssueConfig{Regex: "[A-Z]+-[0-9]+"},
|
||||
},
|
||||
|
10
sv/config.go
10
sv/config.go
@ -12,15 +12,7 @@ type CommitMessageConfig struct {
|
||||
|
||||
// IssueFooterConfig config for issue.
|
||||
func (c CommitMessageConfig) IssueFooterConfig() CommitMessageFooterConfig {
|
||||
if v, exists := c.Footer[issueKey]; exists {
|
||||
return v
|
||||
}
|
||||
return CommitMessageFooterConfig{}
|
||||
}
|
||||
|
||||
// BreakingChangeFooterConfig config for breaking changes.
|
||||
func (c CommitMessageConfig) BreakingChangeFooterConfig() CommitMessageFooterConfig {
|
||||
if v, exists := c.Footer[breakingKey]; exists {
|
||||
if v, exists := c.Footer[issueMetadataKey]; exists {
|
||||
return v
|
||||
}
|
||||
return CommitMessageFooterConfig{}
|
||||
|
@ -13,7 +13,7 @@ func version(v string) semver.Version {
|
||||
|
||||
func commitlog(t string, metadata map[string]string) GitCommitLog {
|
||||
breaking := false
|
||||
if _, found := metadata[breakingKey]; found {
|
||||
if _, found := metadata[breakingChangeMetadataKey]; found {
|
||||
breaking = true
|
||||
}
|
||||
return GitCommitLog{
|
||||
|
@ -9,9 +9,9 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
breakingKey = "breaking-change"
|
||||
// IssueIDKey key to issue id metadata
|
||||
issueKey = "issue"
|
||||
breakingChangeFooterKey = "BREAKING CHANGE"
|
||||
breakingChangeMetadataKey = "breaking-change"
|
||||
issueMetadataKey = "issue"
|
||||
)
|
||||
|
||||
// CommitMessage is a message using conventional commits.
|
||||
@ -28,22 +28,22 @@ type CommitMessage struct {
|
||||
func NewCommitMessage(ctype, scope, description, body, issue, breakingChanges string) CommitMessage {
|
||||
metadata := make(map[string]string)
|
||||
if issue != "" {
|
||||
metadata[issueKey] = issue
|
||||
metadata[issueMetadataKey] = issue
|
||||
}
|
||||
if breakingChanges != "" {
|
||||
metadata[breakingKey] = breakingChanges
|
||||
metadata[breakingChangeMetadataKey] = breakingChanges
|
||||
}
|
||||
return CommitMessage{Type: ctype, Scope: scope, Description: description, Body: body, IsBreakingChange: breakingChanges != "", Metadata: metadata}
|
||||
}
|
||||
|
||||
// Issue return issue from metadata.
|
||||
func (m CommitMessage) Issue() string {
|
||||
return m.Metadata[issueKey]
|
||||
return m.Metadata[issueMetadataKey]
|
||||
}
|
||||
|
||||
// BreakingMessage return breaking change message from metadata.
|
||||
func (m CommitMessage) BreakingMessage() string {
|
||||
return m.Metadata[breakingKey]
|
||||
return m.Metadata[breakingChangeMetadataKey]
|
||||
}
|
||||
|
||||
// MessageProcessor interface.
|
||||
@ -111,7 +111,7 @@ func (p MessageProcessorImpl) Enhance(branch string, message string) (string, er
|
||||
|
||||
footer := fmt.Sprintf("%s: %s", p.messageCfg.IssueFooterConfig().Key, issue)
|
||||
|
||||
if !hasFooter(message, p.messageCfg.Footer[breakingKey].Key) {
|
||||
if !hasFooter(message) {
|
||||
return "\n" + footer, nil
|
||||
}
|
||||
|
||||
@ -145,9 +145,9 @@ func (p MessageProcessorImpl) Format(msg CommitMessage) (string, string, string)
|
||||
|
||||
var footer strings.Builder
|
||||
if msg.BreakingMessage() != "" {
|
||||
footer.WriteString(fmt.Sprintf("%s: %s", p.messageCfg.BreakingChangeFooterConfig().Key, msg.BreakingMessage()))
|
||||
footer.WriteString(fmt.Sprintf("%s: %s", breakingChangeFooterKey, msg.BreakingMessage()))
|
||||
}
|
||||
if issue, exists := msg.Metadata[issueKey]; exists {
|
||||
if issue, exists := msg.Metadata[issueMetadataKey]; exists {
|
||||
if footer.Len() > 0 {
|
||||
footer.WriteString("\n")
|
||||
}
|
||||
@ -171,8 +171,8 @@ func (p MessageProcessorImpl) Parse(subject, body string) CommitMessage {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if _, exists := metadata[breakingKey]; exists {
|
||||
if tagValue := extractFooterMetadata(breakingChangeFooterKey, body, false); tagValue != "" {
|
||||
metadata[breakingChangeMetadataKey] = tagValue
|
||||
hasBreakingChange = true
|
||||
}
|
||||
|
||||
@ -210,8 +210,8 @@ func extractFooterMetadata(key, text string, useHash bool) string {
|
||||
return result[1]
|
||||
}
|
||||
|
||||
func hasFooter(message, breakingChangeKey string) bool {
|
||||
r := regexp.MustCompile("^[a-zA-Z-]+: .*|^[a-zA-Z-]+ #.*|^" + breakingChangeKey + ": .*")
|
||||
func hasFooter(message string) bool {
|
||||
r := regexp.MustCompile("^[a-zA-Z-]+: .*|^[a-zA-Z-]+ #.*|^" + breakingChangeFooterKey + ": .*")
|
||||
|
||||
scanner := bufio.NewScanner(strings.NewReader(message))
|
||||
lines := 0
|
||||
|
@ -9,9 +9,8 @@ var ccfg = CommitMessageConfig{
|
||||
Types: []string{"feat", "fix"},
|
||||
Scope: CommitMessageScopeConfig{},
|
||||
Footer: map[string]CommitMessageFooterConfig{
|
||||
"issue": {Key: "jira", KeySynonyms: []string{"Jira"}},
|
||||
"breaking-change": {Key: "BREAKING CHANGE", KeySynonyms: []string{"BREAKING CHANGES"}},
|
||||
"refs": {Key: "Refs", UseHash: true},
|
||||
"issue": {Key: "jira", KeySynonyms: []string{"Jira"}},
|
||||
"refs": {Key: "Refs", UseHash: true},
|
||||
},
|
||||
Issue: CommitMessageIssueConfig{Regex: "[A-Z]+-[0-9]+"},
|
||||
}
|
||||
@ -20,9 +19,8 @@ var ccfgWithScope = CommitMessageConfig{
|
||||
Types: []string{"feat", "fix"},
|
||||
Scope: CommitMessageScopeConfig{Values: []string{"", "scope"}},
|
||||
Footer: map[string]CommitMessageFooterConfig{
|
||||
"issue": {Key: "jira", KeySynonyms: []string{"Jira"}},
|
||||
"breaking-change": {Key: "BREAKING CHANGE", KeySynonyms: []string{"BREAKING CHANGES"}},
|
||||
"refs": {Key: "Refs", UseHash: true},
|
||||
"issue": {Key: "jira", KeySynonyms: []string{"Jira"}},
|
||||
"refs": {Key: "Refs", UseHash: true},
|
||||
},
|
||||
Issue: CommitMessageIssueConfig{Regex: "[A-Z]+-[0-9]+"},
|
||||
}
|
||||
@ -216,7 +214,7 @@ func Test_hasFooter(t *testing.T) {
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if got := hasFooter(tt.message, "BREAKING CHANGE"); got != tt.want {
|
||||
if got := hasFooter(tt.message); got != tt.want {
|
||||
t.Errorf("hasFooter() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
@ -255,11 +253,11 @@ func TestMessageProcessorImpl_Parse(t *testing.T) {
|
||||
{"simple message", "feat: something awesome", "", CommitMessage{Type: "feat", Scope: "", Description: "something awesome", Body: "", IsBreakingChange: false, Metadata: map[string]string{}}},
|
||||
{"message with scope", "feat(scope): something awesome", "", CommitMessage{Type: "feat", Scope: "scope", Description: "something awesome", Body: "", IsBreakingChange: false, Metadata: map[string]string{}}},
|
||||
{"unmapped type", "unkn: something unknown", "", CommitMessage{Type: "unkn", Scope: "", Description: "something unknown", Body: "", IsBreakingChange: false, Metadata: map[string]string{}}},
|
||||
{"jira and breaking change metadata", "feat: something new", completeBody, CommitMessage{Type: "feat", Scope: "", Description: "something new", Body: completeBody, IsBreakingChange: true, Metadata: map[string]string{issueKey: "JIRA-123", breakingKey: "this change breaks everything"}}},
|
||||
{"jira only metadata", "feat: something new", issueOnlyBody, CommitMessage{Type: "feat", Scope: "", Description: "something new", Body: issueOnlyBody, IsBreakingChange: false, Metadata: map[string]string{issueKey: "JIRA-456"}}},
|
||||
{"jira synonyms metadata", "feat: something new", issueSynonymsBody, CommitMessage{Type: "feat", Scope: "", Description: "something new", Body: issueSynonymsBody, IsBreakingChange: false, Metadata: map[string]string{issueKey: "JIRA-789"}}},
|
||||
{"jira and breaking change metadata", "feat: something new", completeBody, CommitMessage{Type: "feat", Scope: "", Description: "something new", Body: completeBody, IsBreakingChange: true, Metadata: map[string]string{issueMetadataKey: "JIRA-123", breakingChangeMetadataKey: "this change breaks everything"}}},
|
||||
{"jira only metadata", "feat: something new", issueOnlyBody, CommitMessage{Type: "feat", Scope: "", Description: "something new", Body: issueOnlyBody, IsBreakingChange: false, Metadata: map[string]string{issueMetadataKey: "JIRA-456"}}},
|
||||
{"jira synonyms metadata", "feat: something new", issueSynonymsBody, CommitMessage{Type: "feat", Scope: "", Description: "something new", Body: issueSynonymsBody, IsBreakingChange: false, Metadata: map[string]string{issueMetadataKey: "JIRA-789"}}},
|
||||
{"breaking change with exclamation mark", "feat!: something new", "", CommitMessage{Type: "feat", Scope: "", Description: "something new", Body: "", IsBreakingChange: true, Metadata: map[string]string{}}},
|
||||
{"hash metadata", "feat: something new", hashMetadataBody, CommitMessage{Type: "feat", Scope: "", Description: "something new", Body: hashMetadataBody, IsBreakingChange: false, Metadata: map[string]string{issueKey: "JIRA-999", "refs": "#123"}}},
|
||||
{"hash metadata", "feat: something new", hashMetadataBody, CommitMessage{Type: "feat", Scope: "", Description: "something new", Body: hashMetadataBody, IsBreakingChange: false, Metadata: map[string]string{issueMetadataKey: "JIRA-999", "refs": "#123"}}},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
|
Loading…
Reference in New Issue
Block a user