From 106a03dc4ea15ded307698fa2ea314521b3cbe84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alberto=20S=C3=A3o=20Marcos?= Date: Thu, 11 Jul 2024 17:10:23 +0100 Subject: [PATCH] fix: trimming all commit messages to a single line (#432) --- internal/task/changelog/changelog.go | 2 +- internal/task/changelog/changelog_test.go | 42 +++++++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/internal/task/changelog/changelog.go b/internal/task/changelog/changelog.go index 6069ef01..65c1977b 100644 --- a/internal/task/changelog/changelog.go +++ b/internal/task/changelog/changelog.go @@ -153,7 +153,7 @@ func (t Task) Run(ctx *context.Context) error { rels[i].Changes[j].Message = msg } if idx := strings.Index(msg, "\n"); idx > -1 { - rels[i].Changes[j].Message = strings.TrimSpace(msg) + rels[i].Changes[j].Message = strings.TrimSpace(msg[:idx]) } } } diff --git a/internal/task/changelog/changelog_test.go b/internal/task/changelog/changelog_test.go index 6f36bf53..a23ab112 100644 --- a/internal/task/changelog/changelog_test.go +++ b/internal/task/changelog/changelog_test.go @@ -713,6 +713,48 @@ ci: tweak assert.NotContains(t, actual, "fix(scope1): a fix") } +func TestRun_SinglelineMessages(t *testing.T) { + log := `> (tag: 1.1.0) feat: this is a multiline commit + +Where these lines should be trimmed +and not be present + +in the changelog. + +> feat: this is a single line commit that remains unchanged +> (tag: 1.0.0) not included in changelog` + gittest.InitRepository(t, gittest.WithLog(log)) + glog := gittest.Log(t) + + var buf bytes.Buffer + ctx := &context.Context{ + Out: &buf, + Changelog: context.Changelog{ + DiffOnly: true, + }, + CurrentVersion: semver.Version{ + Raw: "1.0.0", + }, + NextVersion: semver.Version{ + Raw: "1.1.0", + }, + SCM: context.SCM{ + Provider: context.Unrecognised, + }, + } + + err := Task{}.Run(ctx) + require.NoError(t, err) + + expected := fmt.Sprintf(`## 1.1.0 - %s + +- %s feat: this is a multiline commit +- %s feat: this is a single line commit that remains unchanged +`, changelogDate(t), fmt.Sprintf("`%s`", glog[0].AbbrevHash), fmt.Sprintf("`%s`", glog[1].AbbrevHash)) + + assert.Equal(t, expected, buf.String()) +} + func TestRun_MultilineMessages(t *testing.T) { log := `> (tag: 1.1.0) feat: this is a multiline commit