0
0
mirror of https://github.com/thegeeklab/git-sv.git synced 2024-11-12 15:00:39 +00:00

fix: use description for breaking changes if no message in footer (#16)

This commit is contained in:
Robert Kaussow 2023-10-28 22:25:07 +02:00 committed by GitHub
parent 42297c3db4
commit 24ca46653d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 23 additions and 26 deletions

View File

@ -35,7 +35,7 @@ release-notes:
- name: Documentation
commit-types: [docs]
section-type: commits
- name: Breaking Changes
- name: BREAKING CHANGES
section-type: breaking-changes
commit-message:

View File

@ -292,22 +292,22 @@ func removeCarriage(commit string) string {
// Parse a commit message.
func (p BaseMessageProcessor) Parse(subject, body string) (CommitMessage, error) {
preparedSubject, err := p.prepareHeader(subject)
commitBody := removeCarriage(body)
m := CommitMessage{}
if err != nil {
return CommitMessage{}, err
return m, err
}
commitType, scope, description, hasBreakingChange := parseSubjectMessage(preparedSubject)
metadata := make(map[string]string)
m.Metadata = make(map[string]string)
m.Body = removeCarriage(body)
m.Type, m.Scope, m.Description, m.IsBreakingChange = parseSubjectMessage(preparedSubject)
for key, mdCfg := range p.messageCfg.Footer {
if mdCfg.Key != "" {
prefixes := append([]string{mdCfg.Key}, mdCfg.KeySynonyms...)
for _, prefix := range prefixes {
if tagValue := extractFooterMetadata(prefix, commitBody, mdCfg.UseHash); tagValue != "" {
metadata[key] = tagValue
if tagValue := extractFooterMetadata(prefix, m.Body, mdCfg.UseHash); tagValue != "" {
m.Metadata[key] = tagValue
break
}
@ -315,19 +315,16 @@ func (p BaseMessageProcessor) Parse(subject, body string) (CommitMessage, error)
}
}
if tagValue := extractFooterMetadata(BreakingChangeFooterKey, commitBody, false); tagValue != "" {
metadata[BreakingChangeMetadataKey] = tagValue
hasBreakingChange = true
if m.IsBreakingChange {
m.Metadata[BreakingChangeMetadataKey] = m.Description
}
return CommitMessage{
Type: commitType,
Scope: scope,
Description: description,
Body: commitBody,
IsBreakingChange: hasBreakingChange,
Metadata: metadata,
}, nil
if tagValue := extractFooterMetadata(BreakingChangeFooterKey, m.Body, false); tagValue != "" {
m.IsBreakingChange = true
m.Metadata[BreakingChangeMetadataKey] = tagValue
}
return m, nil
}
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 {
var regex *regexp.Regexp
regex := regexp.MustCompile(key + ": (.*)")
if useHash {
regex = regexp.MustCompile(key + " (#.*)")
} else {
regex = regexp.MustCompile(key + ": (.*)")
}
result := regex.FindStringSubmatch(text)

View File

@ -604,7 +604,7 @@ func TestBaseMessageProcessor_Parse(t *testing.T) {
},
},
{
"breaking change with exclamation mark",
"breaking change with empty body",
ccfg,
"feat!: something new", "",
CommitMessage{
@ -613,7 +613,9 @@ func TestBaseMessageProcessor_Parse(t *testing.T) {
Description: "something new",
Body: "",
IsBreakingChange: true,
Metadata: map[string]string{},
Metadata: map[string]string{
BreakingChangeMetadataKey: "something new",
},
},
},
{

View File

@ -77,8 +77,7 @@ func (p BaseReleaseNoteProcessor) Create(
sections[sectionCfg.Name] = section
}
if commit.Message.BreakingMessage() != "" {
// TODO: if no message found, should use description instead?
if commit.Message.IsBreakingChange {
breakingChanges = append(breakingChanges, commit.Message.BreakingMessage())
}
}