0
0
mirror of https://github.com/thegeeklab/git-sv.git synced 2024-11-28 06:30:35 +00:00

feat: remove carriage return from commit body

issue: #85
This commit is contained in:
Beatriz Vieira 2023-01-21 21:41:55 -03:00
parent 81c97c21ba
commit 4a15a659d9

View File

@ -83,7 +83,7 @@ func (p MessageProcessorImpl) Validate(message string) error {
subject, body := splitCommitMessageContent(message) subject, body := splitCommitMessageContent(message)
msg, parseErr := p.Parse(subject, body) msg, parseErr := p.Parse(subject, body)
if (parseErr != nil) { if parseErr != nil {
return parseErr return parseErr
} }
@ -205,9 +205,14 @@ func (p MessageProcessorImpl) Format(msg CommitMessage) (string, string, string)
return header.String(), msg.Body, footer.String() return header.String(), msg.Body, footer.String()
} }
func removeCarriage(commit string) string {
return regexp.MustCompile(`\r`).ReplaceAllString(commit, "")
}
// Parse a commit message. // Parse a commit message.
func (p MessageProcessorImpl) Parse(subject, body string) (CommitMessage, error) { func (p MessageProcessorImpl) Parse(subject, body string) (CommitMessage, error) {
preparedSubject, err := p.prepareHeader(subject) preparedSubject, err := p.prepareHeader(subject)
commitBody := removeCarriage(body)
if err != nil { if err != nil {
return CommitMessage{}, err return CommitMessage{}, err
@ -220,14 +225,14 @@ func (p MessageProcessorImpl) Parse(subject, body string) (CommitMessage, error)
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, body, mdCfg.UseHash); tagValue != "" { if tagValue := extractFooterMetadata(prefix, commitBody, mdCfg.UseHash); tagValue != "" {
metadata[key] = tagValue metadata[key] = tagValue
break break
} }
} }
} }
} }
if tagValue := extractFooterMetadata(breakingChangeFooterKey, body, false); tagValue != "" { if tagValue := extractFooterMetadata(breakingChangeFooterKey, commitBody, false); tagValue != "" {
metadata[breakingChangeMetadataKey] = tagValue metadata[breakingChangeMetadataKey] = tagValue
hasBreakingChange = true hasBreakingChange = true
} }
@ -236,7 +241,7 @@ func (p MessageProcessorImpl) Parse(subject, body string) (CommitMessage, error)
Type: commitType, Type: commitType,
Scope: scope, Scope: scope,
Description: description, Description: description,
Body: body, Body: commitBody,
IsBreakingChange: hasBreakingChange, IsBreakingChange: hasBreakingChange,
Metadata: metadata, Metadata: metadata,
}, nil }, nil