mirror of
https://github.com/apricote/releaser-pleaser.git
synced 2026-01-13 13:21:00 +00:00
fix: use commits with slightly invalid messages in release notes (#105)
Fixes a bug where commits with messages that do not strictly conform to conventional commits spec would be ignored. This could easily happen while parsing footers like "Closes #xx" which would start the footer section, while continuing with the body afterwards. This solution has two downsides: - these warnings are not surfaced to the user. - If a `BREAKING CHANGE` footer exists after the parsing issue it is ignored Co-authored-by: jo <ljonas@riseup.net>
This commit is contained in:
parent
faf28fd314
commit
0ae2d909bc
2 changed files with 30 additions and 2 deletions
|
|
@ -35,8 +35,12 @@ func (c *Parser) Analyze(commits []git.Commit) ([]commitparser.AnalyzedCommit, e
|
|||
for _, commit := range commits {
|
||||
msg, err := c.machine.Parse([]byte(strings.TrimSpace(commit.Message)))
|
||||
if err != nil {
|
||||
c.logger.Warn("failed to parse message of commit, skipping", "commit.hash", commit.Hash, "err", err)
|
||||
continue
|
||||
if msg == nil {
|
||||
c.logger.Warn("failed to parse message of commit, skipping", "commit.hash", commit.Hash, "err", err)
|
||||
continue
|
||||
}
|
||||
|
||||
c.logger.Warn("failed to parse message of commit fully, trying to use as much as possible", "commit.hash", commit.Hash, "err", err)
|
||||
}
|
||||
|
||||
conventionalCommit, ok := msg.(*conventionalcommits.ConventionalCommit)
|
||||
|
|
@ -44,6 +48,12 @@ func (c *Parser) Analyze(commits []git.Commit) ([]commitparser.AnalyzedCommit, e
|
|||
return nil, fmt.Errorf("unable to get ConventionalCommit from parser result: %T", msg)
|
||||
}
|
||||
|
||||
if conventionalCommit.Type == "" {
|
||||
// Parsing broke before getting the type, can not use the commit
|
||||
c.logger.Warn("commit type was not parsed, skipping", "commit.hash", commit.Hash, "err", err)
|
||||
continue
|
||||
}
|
||||
|
||||
commitVersionBump := conventionalCommit.VersionBump(conventionalcommits.DefaultStrategy)
|
||||
if commitVersionBump > conventionalcommits.UnknownVersion {
|
||||
// We only care about releasable commits
|
||||
|
|
|
|||
|
|
@ -125,6 +125,24 @@ func TestAnalyzeCommits(t *testing.T) {
|
|||
},
|
||||
wantErr: assert.NoError,
|
||||
},
|
||||
|
||||
{
|
||||
name: "success with body",
|
||||
commits: []git.Commit{
|
||||
{
|
||||
Message: "feat: some thing (hz/fl!144)\n\nFixes #15\n\nDepends on !143",
|
||||
},
|
||||
},
|
||||
expectedCommits: []commitparser.AnalyzedCommit{
|
||||
{
|
||||
Commit: git.Commit{Message: "feat: some thing (hz/fl!144)\n\nFixes #15\n\nDepends on !143"},
|
||||
Type: "feat",
|
||||
Description: "some thing (hz/fl!144)",
|
||||
BreakingChange: false,
|
||||
},
|
||||
},
|
||||
wantErr: assert.NoError,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue