From 4a15a659d9f925b5a2f33decfc09c310c3ebc5bf Mon Sep 17 00:00:00 2001 From: Beatriz Vieira Date: Sat, 21 Jan 2023 21:41:55 -0300 Subject: [PATCH] feat: remove carriage return from commit body issue: #85 --- sv/message.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/sv/message.go b/sv/message.go index fc7e5f7..3344df8 100644 --- a/sv/message.go +++ b/sv/message.go @@ -83,7 +83,7 @@ func (p MessageProcessorImpl) Validate(message string) error { subject, body := splitCommitMessageContent(message) msg, parseErr := p.Parse(subject, body) - if (parseErr != nil) { + if parseErr != nil { return parseErr } @@ -205,14 +205,19 @@ func (p MessageProcessorImpl) Format(msg CommitMessage) (string, string, string) return header.String(), msg.Body, footer.String() } +func removeCarriage(commit string) string { + return regexp.MustCompile(`\r`).ReplaceAllString(commit, "") +} + // Parse a commit message. func (p MessageProcessorImpl) Parse(subject, body string) (CommitMessage, error) { preparedSubject, err := p.prepareHeader(subject) + commitBody := removeCarriage(body) if err != nil { return CommitMessage{}, err } - + commitType, scope, description, hasBreakingChange := parseSubjectMessage(preparedSubject) metadata := make(map[string]string) @@ -220,14 +225,14 @@ func (p MessageProcessorImpl) Parse(subject, body string) (CommitMessage, error) if mdCfg.Key != "" { prefixes := append([]string{mdCfg.Key}, mdCfg.KeySynonyms...) for _, prefix := range prefixes { - if tagValue := extractFooterMetadata(prefix, body, mdCfg.UseHash); tagValue != "" { + if tagValue := extractFooterMetadata(prefix, commitBody, mdCfg.UseHash); tagValue != "" { metadata[key] = tagValue break } } } } - if tagValue := extractFooterMetadata(breakingChangeFooterKey, body, false); tagValue != "" { + if tagValue := extractFooterMetadata(breakingChangeFooterKey, commitBody, false); tagValue != "" { metadata[breakingChangeMetadataKey] = tagValue hasBreakingChange = true } @@ -236,7 +241,7 @@ func (p MessageProcessorImpl) Parse(subject, body string) (CommitMessage, error) Type: commitType, Scope: scope, Description: description, - Body: body, + Body: commitBody, IsBreakingChange: hasBreakingChange, Metadata: metadata, }, nil