mirror of
https://github.com/apricote/releaser-pleaser.git
synced 2026-01-13 21:21:03 +00:00
fix(parser): continue on unparsable commit message
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
6bae554d05
3 changed files with 13 additions and 7 deletions
|
|
@ -2,6 +2,7 @@ package conventionalcommits
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"log/slog"
|
||||
|
||||
"github.com/leodido/go-conventionalcommits"
|
||||
"github.com/leodido/go-conventionalcommits/parser"
|
||||
|
|
@ -12,9 +13,10 @@ import (
|
|||
|
||||
type Parser struct {
|
||||
machine conventionalcommits.Machine
|
||||
logger *slog.Logger
|
||||
}
|
||||
|
||||
func NewParser() *Parser {
|
||||
func NewParser(logger *slog.Logger) *Parser {
|
||||
parserMachine := parser.NewMachine(
|
||||
parser.WithBestEffort(),
|
||||
parser.WithTypes(conventionalcommits.TypesConventional),
|
||||
|
|
@ -22,6 +24,7 @@ func NewParser() *Parser {
|
|||
|
||||
return &Parser{
|
||||
machine: parserMachine,
|
||||
logger: logger,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -31,8 +34,10 @@ func (c *Parser) Analyze(commits []git.Commit) ([]commitparser.AnalyzedCommit, e
|
|||
for _, commit := range commits {
|
||||
msg, err := c.machine.Parse([]byte(commit.Message))
|
||||
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)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unable to get ConventionalCommit from parser result: %T", msg)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue