| | | 1 | | package plugins |
| | | 2 | | |
| | | 3 | | import ( |
| | | 4 | | "context" |
| | | 5 | | |
| | | 6 | | "github.com/jedi-knights/go-semantic-release/internal/domain" |
| | | 7 | | "github.com/jedi-knights/go-semantic-release/internal/ports" |
| | | 8 | | ) |
| | | 9 | | |
| | | 10 | | // Compile-time interface compliance checks. |
| | | 11 | | var ( |
| | | 12 | | _ ports.Plugin = (*CommitAnalyzerPlugin)(nil) |
| | | 13 | | _ ports.AnalyzeCommitsPlugin = (*CommitAnalyzerPlugin)(nil) |
| | | 14 | | ) |
| | | 15 | | |
| | | 16 | | // CommitAnalyzerPlugin implements AnalyzeCommitsPlugin using conventional commits. |
| | | 17 | | type CommitAnalyzerPlugin struct { |
| | | 18 | | parser ports.CommitParser |
| | | 19 | | typeMapping map[string]domain.ReleaseType |
| | | 20 | | } |
| | | 21 | | |
| | | 22 | | // NewCommitAnalyzerPlugin creates the default commit analyzer plugin. |
| | | 23 | | func NewCommitAnalyzerPlugin(parser ports.CommitParser, typeMapping map[string]domain.ReleaseType) *CommitAnalyzerPlugin |
| | | 24 | | return &CommitAnalyzerPlugin{parser: parser, typeMapping: typeMapping} |
| | | 25 | | } |
| | | 26 | | |
| | 1 | 27 | | func (p *CommitAnalyzerPlugin) Name() string { return "commit-analyzer" } |
| | | 28 | | |
| | 3 | 29 | | func (p *CommitAnalyzerPlugin) AnalyzeCommits(_ context.Context, rc *domain.ReleaseContext) (domain.ReleaseType, error) |
| | 3 | 30 | | highest := domain.ReleaseNone |
| | 3 | 31 | | for i := range rc.Commits { |
| | 5 | 32 | | rt := rc.Commits[i].ReleaseType(p.typeMapping) |
| | 5 | 33 | | highest = highest.Higher(rt) |
| | 5 | 34 | | } |
| | 3 | 35 | | return highest, nil |
| | | 36 | | } |