mirror of
https://github.com/apricote/releaser-pleaser.git
synced 2026-02-07 02:07:04 +00:00
fix(parser): continue on unparsable commit message (#48)
We should not fail the whole process if a single commit message is unparsable. Instead we now log the issue and ignore the commit.
This commit is contained in:
parent
2010ac1143
commit
5ea41654a7
3 changed files with 13 additions and 7 deletions
|
|
@ -71,7 +71,7 @@ func run(cmd *cobra.Command, _ []string) error {
|
||||||
f,
|
f,
|
||||||
logger,
|
logger,
|
||||||
flagBranch,
|
flagBranch,
|
||||||
conventionalcommits.NewParser(),
|
conventionalcommits.NewParser(logger),
|
||||||
versioning.SemVerNextVersion,
|
versioning.SemVerNextVersion,
|
||||||
extraFiles,
|
extraFiles,
|
||||||
[]updater.NewUpdater{updater.Generic},
|
[]updater.NewUpdater{updater.Generic},
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ package conventionalcommits
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log/slog"
|
||||||
|
|
||||||
"github.com/leodido/go-conventionalcommits"
|
"github.com/leodido/go-conventionalcommits"
|
||||||
"github.com/leodido/go-conventionalcommits/parser"
|
"github.com/leodido/go-conventionalcommits/parser"
|
||||||
|
|
@ -12,9 +13,10 @@ import (
|
||||||
|
|
||||||
type Parser struct {
|
type Parser struct {
|
||||||
machine conventionalcommits.Machine
|
machine conventionalcommits.Machine
|
||||||
|
logger *slog.Logger
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewParser() *Parser {
|
func NewParser(logger *slog.Logger) *Parser {
|
||||||
parserMachine := parser.NewMachine(
|
parserMachine := parser.NewMachine(
|
||||||
parser.WithBestEffort(),
|
parser.WithBestEffort(),
|
||||||
parser.WithTypes(conventionalcommits.TypesConventional),
|
parser.WithTypes(conventionalcommits.TypesConventional),
|
||||||
|
|
@ -22,6 +24,7 @@ func NewParser() *Parser {
|
||||||
|
|
||||||
return &Parser{
|
return &Parser{
|
||||||
machine: parserMachine,
|
machine: parserMachine,
|
||||||
|
logger: logger,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -31,8 +34,10 @@ func (c *Parser) Analyze(commits []git.Commit) ([]commitparser.AnalyzedCommit, e
|
||||||
for _, commit := range commits {
|
for _, commit := range commits {
|
||||||
msg, err := c.machine.Parse([]byte(commit.Message))
|
msg, err := c.machine.Parse([]byte(commit.Message))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to parse message of commit %q: %w", commit.Hash, err)
|
c.logger.Warn("failed to parse message of commit, skipping", "commit.hash", commit.Hash, "err", err)
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
conventionalCommit, ok := msg.(*conventionalcommits.ConventionalCommit)
|
conventionalCommit, ok := msg.(*conventionalcommits.ConventionalCommit)
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("unable to get ConventionalCommit from parser result: %T", msg)
|
return nil, fmt.Errorf("unable to get ConventionalCommit from parser result: %T", msg)
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
package conventionalcommits
|
package conventionalcommits
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"log/slog"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
|
@ -23,14 +24,14 @@ func TestAnalyzeCommits(t *testing.T) {
|
||||||
wantErr: assert.NoError,
|
wantErr: assert.NoError,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "malformed commit message",
|
name: "skips malformed commit message",
|
||||||
commits: []git.Commit{
|
commits: []git.Commit{
|
||||||
{
|
{
|
||||||
Message: "aksdjaklsdjka",
|
Message: "aksdjaklsdjka",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expectedCommits: nil,
|
expectedCommits: []commitparser.AnalyzedCommit{},
|
||||||
wantErr: assert.Error,
|
wantErr: assert.NoError,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "drops unreleasable",
|
name: "drops unreleasable",
|
||||||
|
|
@ -114,7 +115,7 @@ func TestAnalyzeCommits(t *testing.T) {
|
||||||
}
|
}
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
analyzedCommits, err := NewParser().Analyze(tt.commits)
|
analyzedCommits, err := NewParser(slog.Default()).Analyze(tt.commits)
|
||||||
if !tt.wantErr(t, err) {
|
if !tt.wantErr(t, err) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue