Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use commits with slightly invalid messages in release notes #105

Merged
merged 2 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions internal/commitparser/conventionalcommits/conventionalcommits.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,25 @@ 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)
if !ok {
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Loading