Skip to content

Commit

Permalink
fix: trimming all commit messages to a single line (#432)
Browse files Browse the repository at this point in the history
  • Loading branch information
albertocsm authored Jul 11, 2024
1 parent a999c3a commit 106a03d
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
2 changes: 1 addition & 1 deletion internal/task/changelog/changelog.go
Original file line number Diff line number Diff line change
Expand Up @@ -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])
}
}
}
Expand Down
42 changes: 42 additions & 0 deletions internal/task/changelog/changelog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 106a03d

Please sign in to comment.