mirror of
https://github.com/apricote/releaser-pleaser.git
synced 2026-02-07 10:17:02 +00:00
fix(parser): invalid handling of empty lines
GitLab generates commit messages of the pattern "scope: message\n" if no body is present. This throws up the conventional commits parser we use, and results in the error message "missing a blank line". We now `strings.TrimSpace()` the commit message to avoid this problem.
This commit is contained in:
parent
ee5c7aa142
commit
76e040a5a6
2 changed files with 15 additions and 1 deletions
|
|
@ -3,6 +3,7 @@ package conventionalcommits
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log/slog"
|
"log/slog"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/leodido/go-conventionalcommits"
|
"github.com/leodido/go-conventionalcommits"
|
||||||
"github.com/leodido/go-conventionalcommits/parser"
|
"github.com/leodido/go-conventionalcommits/parser"
|
||||||
|
|
@ -32,7 +33,7 @@ func (c *Parser) Analyze(commits []git.Commit) ([]commitparser.AnalyzedCommit, e
|
||||||
analyzedCommits := make([]commitparser.AnalyzedCommit, 0, len(commits))
|
analyzedCommits := make([]commitparser.AnalyzedCommit, 0, len(commits))
|
||||||
|
|
||||||
for _, commit := range commits {
|
for _, commit := range commits {
|
||||||
msg, err := c.machine.Parse([]byte(commit.Message))
|
msg, err := c.machine.Parse([]byte(strings.TrimSpace(commit.Message)))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.logger.Warn("failed to parse message of commit, skipping", "commit.hash", commit.Hash, "err", err)
|
c.logger.Warn("failed to parse message of commit, skipping", "commit.hash", commit.Hash, "err", err)
|
||||||
continue
|
continue
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,19 @@ func TestAnalyzeCommits(t *testing.T) {
|
||||||
expectedCommits: []commitparser.AnalyzedCommit{},
|
expectedCommits: []commitparser.AnalyzedCommit{},
|
||||||
wantErr: assert.NoError,
|
wantErr: assert.NoError,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
// GitLab seems to create commits with pattern "scope: message\n" if no body is added.
|
||||||
|
// This has previously caused a parser error "missing a blank line".
|
||||||
|
// We added a workaround with `strings.TrimSpace()` and this test make sure that it does not break again.
|
||||||
|
name: "handles title with new line",
|
||||||
|
commits: []git.Commit{
|
||||||
|
{
|
||||||
|
Message: "aksdjaklsdjka",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
expectedCommits: []commitparser.AnalyzedCommit{},
|
||||||
|
wantErr: assert.NoError,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "drops unreleasable",
|
name: "drops unreleasable",
|
||||||
commits: []git.Commit{
|
commits: []git.Commit{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue