fix: use description for breaking changes if no message in footer (#16)
This commit is contained in:
parent
42297c3db4
commit
24ca46653d
4 changed files with 23 additions and 26 deletions
|
@ -35,7 +35,7 @@ release-notes:
|
||||||
- name: Documentation
|
- name: Documentation
|
||||||
commit-types: [docs]
|
commit-types: [docs]
|
||||||
section-type: commits
|
section-type: commits
|
||||||
- name: Breaking Changes
|
- name: BREAKING CHANGES
|
||||||
section-type: breaking-changes
|
section-type: breaking-changes
|
||||||
|
|
||||||
commit-message:
|
commit-message:
|
||||||
|
|
|
@ -292,22 +292,22 @@ func removeCarriage(commit string) string {
|
||||||
// Parse a commit message.
|
// Parse a commit message.
|
||||||
func (p BaseMessageProcessor) Parse(subject, body string) (CommitMessage, error) {
|
func (p BaseMessageProcessor) Parse(subject, body string) (CommitMessage, error) {
|
||||||
preparedSubject, err := p.prepareHeader(subject)
|
preparedSubject, err := p.prepareHeader(subject)
|
||||||
commitBody := removeCarriage(body)
|
m := CommitMessage{}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return CommitMessage{}, err
|
return m, err
|
||||||
}
|
}
|
||||||
|
|
||||||
commitType, scope, description, hasBreakingChange := parseSubjectMessage(preparedSubject)
|
m.Metadata = make(map[string]string)
|
||||||
|
m.Body = removeCarriage(body)
|
||||||
metadata := make(map[string]string)
|
m.Type, m.Scope, m.Description, m.IsBreakingChange = parseSubjectMessage(preparedSubject)
|
||||||
|
|
||||||
for key, mdCfg := range p.messageCfg.Footer {
|
for key, mdCfg := range p.messageCfg.Footer {
|
||||||
if mdCfg.Key != "" {
|
if mdCfg.Key != "" {
|
||||||
prefixes := append([]string{mdCfg.Key}, mdCfg.KeySynonyms...)
|
prefixes := append([]string{mdCfg.Key}, mdCfg.KeySynonyms...)
|
||||||
for _, prefix := range prefixes {
|
for _, prefix := range prefixes {
|
||||||
if tagValue := extractFooterMetadata(prefix, commitBody, mdCfg.UseHash); tagValue != "" {
|
if tagValue := extractFooterMetadata(prefix, m.Body, mdCfg.UseHash); tagValue != "" {
|
||||||
metadata[key] = tagValue
|
m.Metadata[key] = tagValue
|
||||||
|
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
@ -315,19 +315,16 @@ func (p BaseMessageProcessor) Parse(subject, body string) (CommitMessage, error)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if tagValue := extractFooterMetadata(BreakingChangeFooterKey, commitBody, false); tagValue != "" {
|
if m.IsBreakingChange {
|
||||||
metadata[BreakingChangeMetadataKey] = tagValue
|
m.Metadata[BreakingChangeMetadataKey] = m.Description
|
||||||
hasBreakingChange = true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return CommitMessage{
|
if tagValue := extractFooterMetadata(BreakingChangeFooterKey, m.Body, false); tagValue != "" {
|
||||||
Type: commitType,
|
m.IsBreakingChange = true
|
||||||
Scope: scope,
|
m.Metadata[BreakingChangeMetadataKey] = tagValue
|
||||||
Description: description,
|
}
|
||||||
Body: commitBody,
|
|
||||||
IsBreakingChange: hasBreakingChange,
|
return m, nil
|
||||||
Metadata: metadata,
|
|
||||||
}, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p BaseMessageProcessor) prepareHeader(header string) (string, error) {
|
func (p BaseMessageProcessor) prepareHeader(header string) (string, error) {
|
||||||
|
@ -371,11 +368,10 @@ func parseSubjectMessage(message string) (string, string, string, bool) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func extractFooterMetadata(key, text string, useHash bool) string {
|
func extractFooterMetadata(key, text string, useHash bool) string {
|
||||||
var regex *regexp.Regexp
|
regex := regexp.MustCompile(key + ": (.*)")
|
||||||
|
|
||||||
if useHash {
|
if useHash {
|
||||||
regex = regexp.MustCompile(key + " (#.*)")
|
regex = regexp.MustCompile(key + " (#.*)")
|
||||||
} else {
|
|
||||||
regex = regexp.MustCompile(key + ": (.*)")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
result := regex.FindStringSubmatch(text)
|
result := regex.FindStringSubmatch(text)
|
||||||
|
|
|
@ -604,7 +604,7 @@ func TestBaseMessageProcessor_Parse(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"breaking change with exclamation mark",
|
"breaking change with empty body",
|
||||||
ccfg,
|
ccfg,
|
||||||
"feat!: something new", "",
|
"feat!: something new", "",
|
||||||
CommitMessage{
|
CommitMessage{
|
||||||
|
@ -613,7 +613,9 @@ func TestBaseMessageProcessor_Parse(t *testing.T) {
|
||||||
Description: "something new",
|
Description: "something new",
|
||||||
Body: "",
|
Body: "",
|
||||||
IsBreakingChange: true,
|
IsBreakingChange: true,
|
||||||
Metadata: map[string]string{},
|
Metadata: map[string]string{
|
||||||
|
BreakingChangeMetadataKey: "something new",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
@ -77,8 +77,7 @@ func (p BaseReleaseNoteProcessor) Create(
|
||||||
sections[sectionCfg.Name] = section
|
sections[sectionCfg.Name] = section
|
||||||
}
|
}
|
||||||
|
|
||||||
if commit.Message.BreakingMessage() != "" {
|
if commit.Message.IsBreakingChange {
|
||||||
// TODO: if no message found, should use description instead?
|
|
||||||
breakingChanges = append(breakingChanges, commit.Message.BreakingMessage())
|
breakingChanges = append(breakingChanges, commit.Message.BreakingMessage())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue