Files
releaser/internal/commits/commits.go
T
k3nny f0723e706a
ci / vet, staticcheck, test, build (push) Failing after 3m26s
release / Build and publish release (push) Successful in 4m28s
feat(releaser): initial release v0.4.0
Complete GitFlow release automation tool for Conventional Commits workflows:

- Core pipeline: branch parsing, tag discovery, commit analysis, version bump
- Maven pom.xml read/write, git commit/tag, HTTPS push with token auth
- GitLab release creation via API with auto-generated release notes
- Configurable via .releaser.yml (tag_prefix, branch_pattern, commit_message, pom_path, gitlab)
- CLI flags: --dry-run, --no-push, --no-commit, --tag-only, --branch, --pom, --tag-prefix, --branch-pattern
- Dockerfile (multi-stage Alpine), .releaser.gitlab-ci.yml reusable template
- Gitea CI (vet + staticcheck + test + build) and release (5-platform cross-compilation) workflows
- Taskfile with build/test/cov/lint/fuzz/ci/docker tasks
- 96% test coverage with real in-memory git repos and fuzz tests for all parsers

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-07 00:07:53 +02:00

64 lines
1.4 KiB
Go

package commits
import (
"regexp"
"strings"
)
// Type represents the semantic weight of a commit for versioning purposes.
type Type int
const (
TypeNone Type = iota // no version bump
TypeFix // fix: → patch bump
TypeFeat // feat: → patch bump (minor is pinned to branch)
TypeBreaking // feat!: or BREAKING CHANGE → patch bump
)
// headerRe matches conventional commit headers in non-strict mode:
// case-insensitive, optional scope, optional breaking marker, flexible whitespace around colon.
var headerRe = regexp.MustCompile(`(?i)^(\w+)(?:\([^)]*\))?(!)?\s*:\s*\S`)
// Parse extracts the commit type from a commit message.
// Unparseable messages return TypeNone — never an error.
func Parse(message string) Type {
msg := strings.TrimSpace(message)
// BREAKING CHANGE anywhere in the body/footer takes priority (spec §10).
if strings.Contains(msg, "BREAKING CHANGE") {
return TypeBreaking
}
first := strings.SplitN(msg, "\n", 2)[0]
m := headerRe.FindStringSubmatch(first)
if m == nil {
return TypeNone
}
if m[2] == "!" {
return TypeBreaking
}
switch strings.ToLower(m[1]) {
case "feat":
return TypeFeat
case "fix":
return TypeFix
default:
return TypeNone
}
}
func (t Type) String() string {
switch t {
case TypeFix:
return "fix"
case TypeFeat:
return "feat"
case TypeBreaking:
return "breaking"
default:
return "none"
}
}