0
0
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:
Beatriz Vieira 2021-02-15 00:05:43 -03:00
parent df26b50096
commit 2ae35c91af
5 changed files with 26 additions and 37 deletions

View File

@ -82,8 +82,7 @@ func defaultConfig() Config {
Types: []string{"build", "ci", "chore", "docs", "feat", "fix", "perf", "refactor", "revert", "style", "test"}, Types: []string{"build", "ci", "chore", "docs", "feat", "fix", "perf", "refactor", "revert", "style", "test"},
Scope: sv.CommitMessageScopeConfig{}, Scope: sv.CommitMessageScopeConfig{},
Footer: map[string]sv.CommitMessageFooterConfig{ Footer: map[string]sv.CommitMessageFooterConfig{
"issue": {Key: "jira", KeySynonyms: []string{"Jira", "JIRA"}}, "issue": {Key: "jira", KeySynonyms: []string{"Jira", "JIRA"}},
"breaking-change": {Key: "BREAKING CHANGE", KeySynonyms: []string{"BREAKING CHANGES"}},
}, },
Issue: sv.CommitMessageIssueConfig{Regex: "[A-Z]+-[0-9]+"}, Issue: sv.CommitMessageIssueConfig{Regex: "[A-Z]+-[0-9]+"},
}, },

View File

@ -12,15 +12,7 @@ type CommitMessageConfig struct {
// IssueFooterConfig config for issue. // IssueFooterConfig config for issue.
func (c CommitMessageConfig) IssueFooterConfig() CommitMessageFooterConfig { func (c CommitMessageConfig) IssueFooterConfig() CommitMessageFooterConfig {
if v, exists := c.Footer[issueKey]; exists { if v, exists := c.Footer[issueMetadataKey]; exists {
return v
}
return CommitMessageFooterConfig{}
}
// BreakingChangeFooterConfig config for breaking changes.
func (c CommitMessageConfig) BreakingChangeFooterConfig() CommitMessageFooterConfig {
if v, exists := c.Footer[breakingKey]; exists {
return v return v
} }
return CommitMessageFooterConfig{} return CommitMessageFooterConfig{}

View File

@ -13,7 +13,7 @@ func version(v string) semver.Version {
func commitlog(t string, metadata map[string]string) GitCommitLog { func commitlog(t string, metadata map[string]string) GitCommitLog {
breaking := false breaking := false
if _, found := metadata[breakingKey]; found { if _, found := metadata[breakingChangeMetadataKey]; found {
breaking = true breaking = true
} }
return GitCommitLog{ return GitCommitLog{

View File

@ -9,9 +9,9 @@ import (
) )
const ( const (
breakingKey = "breaking-change" breakingChangeFooterKey = "BREAKING CHANGE"
// IssueIDKey key to issue id metadata breakingChangeMetadataKey = "breaking-change"
issueKey = "issue" issueMetadataKey = "issue"
) )
// CommitMessage is a message using conventional commits. // CommitMessage is a message using conventional commits.
@ -28,22 +28,22 @@ type CommitMessage struct {
func NewCommitMessage(ctype, scope, description, body, issue, breakingChanges string) CommitMessage { func NewCommitMessage(ctype, scope, description, body, issue, breakingChanges string) CommitMessage {
metadata := make(map[string]string) metadata := make(map[string]string)
if issue != "" { if issue != "" {
metadata[issueKey] = issue metadata[issueMetadataKey] = issue
} }
if breakingChanges != "" { if breakingChanges != "" {
metadata[breakingKey] = breakingChanges metadata[breakingChangeMetadataKey] = breakingChanges
} }
return CommitMessage{Type: ctype, Scope: scope, Description: description, Body: body, IsBreakingChange: breakingChanges != "", Metadata: metadata} return CommitMessage{Type: ctype, Scope: scope, Description: description, Body: body, IsBreakingChange: breakingChanges != "", Metadata: metadata}
} }
// Issue return issue from metadata. // Issue return issue from metadata.
func (m CommitMessage) Issue() string { func (m CommitMessage) Issue() string {
return m.Metadata[issueKey] return m.Metadata[issueMetadataKey]
} }
// BreakingMessage return breaking change message from metadata. // BreakingMessage return breaking change message from metadata.
func (m CommitMessage) BreakingMessage() string { func (m CommitMessage) BreakingMessage() string {
return m.Metadata[breakingKey] return m.Metadata[breakingChangeMetadataKey]
} }
// MessageProcessor interface. // 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) 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 return "\n" + footer, nil
} }
@ -145,9 +145,9 @@ func (p MessageProcessorImpl) Format(msg CommitMessage) (string, string, string)
var footer strings.Builder var footer strings.Builder
if msg.BreakingMessage() != "" { 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 { if footer.Len() > 0 {
footer.WriteString("\n") footer.WriteString("\n")
} }
@ -171,8 +171,8 @@ func (p MessageProcessorImpl) Parse(subject, body string) CommitMessage {
} }
} }
} }
if tagValue := extractFooterMetadata(breakingChangeFooterKey, body, false); tagValue != "" {
if _, exists := metadata[breakingKey]; exists { metadata[breakingChangeMetadataKey] = tagValue
hasBreakingChange = true hasBreakingChange = true
} }
@ -210,8 +210,8 @@ func extractFooterMetadata(key, text string, useHash bool) string {
return result[1] return result[1]
} }
func hasFooter(message, breakingChangeKey string) bool { func hasFooter(message string) bool {
r := regexp.MustCompile("^[a-zA-Z-]+: .*|^[a-zA-Z-]+ #.*|^" + breakingChangeKey + ": .*") r := regexp.MustCompile("^[a-zA-Z-]+: .*|^[a-zA-Z-]+ #.*|^" + breakingChangeFooterKey + ": .*")
scanner := bufio.NewScanner(strings.NewReader(message)) scanner := bufio.NewScanner(strings.NewReader(message))
lines := 0 lines := 0

View File

@ -9,9 +9,8 @@ var ccfg = CommitMessageConfig{
Types: []string{"feat", "fix"}, Types: []string{"feat", "fix"},
Scope: CommitMessageScopeConfig{}, Scope: CommitMessageScopeConfig{},
Footer: map[string]CommitMessageFooterConfig{ Footer: map[string]CommitMessageFooterConfig{
"issue": {Key: "jira", KeySynonyms: []string{"Jira"}}, "issue": {Key: "jira", KeySynonyms: []string{"Jira"}},
"breaking-change": {Key: "BREAKING CHANGE", KeySynonyms: []string{"BREAKING CHANGES"}}, "refs": {Key: "Refs", UseHash: true},
"refs": {Key: "Refs", UseHash: true},
}, },
Issue: CommitMessageIssueConfig{Regex: "[A-Z]+-[0-9]+"}, Issue: CommitMessageIssueConfig{Regex: "[A-Z]+-[0-9]+"},
} }
@ -20,9 +19,8 @@ var ccfgWithScope = CommitMessageConfig{
Types: []string{"feat", "fix"}, Types: []string{"feat", "fix"},
Scope: CommitMessageScopeConfig{Values: []string{"", "scope"}}, Scope: CommitMessageScopeConfig{Values: []string{"", "scope"}},
Footer: map[string]CommitMessageFooterConfig{ Footer: map[string]CommitMessageFooterConfig{
"issue": {Key: "jira", KeySynonyms: []string{"Jira"}}, "issue": {Key: "jira", KeySynonyms: []string{"Jira"}},
"breaking-change": {Key: "BREAKING CHANGE", KeySynonyms: []string{"BREAKING CHANGES"}}, "refs": {Key: "Refs", UseHash: true},
"refs": {Key: "Refs", UseHash: true},
}, },
Issue: CommitMessageIssueConfig{Regex: "[A-Z]+-[0-9]+"}, Issue: CommitMessageIssueConfig{Regex: "[A-Z]+-[0-9]+"},
} }
@ -216,7 +214,7 @@ func Test_hasFooter(t *testing.T) {
} }
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 := 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) 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{}}}, {"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{}}}, {"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{}}}, {"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 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{issueKey: "JIRA-456"}}}, {"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{issueKey: "JIRA-789"}}}, {"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{}}}, {"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 { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {