Documentation
¶
Overview ¶
Package conventional provides conventional commit parsing and analysis.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsMergeCommit ¶
IsMergeCommit returns true for any merge-commit message variant:
- "Merge branch …" (local git merge)
- "Merge pull request …" (GitHub PR merge)
- "Merge {sha} into {sha}" (GitHub Actions CI merge commit)
- "Merge remote-tracking branch …"
Types ¶
type BumpLevel ¶
type BumpLevel = string
BumpLevel is a string alias for bump-rules map values. Valid values: "major", "minor", "patch", "none". Type alias (not new type) avoids import of internal/semver.
type BumpRules ¶
BumpRules maps commit-type strings (and the sentinel "breaking-change") to bump levels. Absent keys default to BumpLevelNone at runtime. "breaking-change" is the sentinel for commits with a "!" suffix or "BREAKING CHANGE:" footer — it is NOT a conventional commit type.
type Commit ¶
type Commit struct {
Type CommitType
Scope string // empty if not present
Breaking bool // true if "!" or BREAKING CHANGE footer
Description string
Body string
RawMessage string // original commit message
SHA string // set by caller after parsing
ShortSHA string // first 7 chars of SHA
}
Commit represents a parsed conventional commit
type CommitType ¶
type CommitType string
CommitType represents the commit type
const ( TypeFeat CommitType = "feat" TypeFix CommitType = "fix" TypeChore CommitType = "chore" TypeDocs CommitType = "docs" TypeCI CommitType = "ci" TypeRefactor CommitType = "refactor" TypeTest CommitType = "test" TypePerf CommitType = "perf" TypeBuild CommitType = "build" TypeRevert CommitType = "revert" )
Valid commit types
type CommitTypesConfig ¶
type CommitTypesConfig struct {
// ExtraTypes adds types on top of the built-in set.
ExtraTypes []string `yaml:"extra-types"`
// AllowedTypes replaces the built-in set entirely when len > 0.
// nil or empty (len == 0) falls through to the built-in defaults.
AllowedTypes []CommitType `yaml:"allowed-types"`
}
CommitTypesConfig controls which conventional-commit types semrel lint accepts.
type Config ¶
type Config struct {
Lint LintConfig `yaml:"lint"`
// BumpRules maps commit types to version bump levels.
// Default: {"breaking-change":"major","feat":"minor","fix":"patch"}.
// Absent keys default to "none". A bare null YAML key restores defaults.
// To freeze all bumps, set each key to "none" explicitly:
// bump-rules: {breaking-change: none, feat: none, fix: none}
BumpRules BumpRules `yaml:"bump-rules"`
// ReleaseBranches lists branch patterns (path.Match syntax) on which
// semrel release will proceed. Defaults to ["main","master"].
// Note: '*' does not cross '/' boundaries.
ReleaseBranches []string `yaml:"release-branches"`
// TagPrefix is prepended to version numbers when forming git tags.
// Default: "v" → produces "v1.2.3". Set "" for bare "1.2.3" tags.
// CRITICAL: the default MUST be "v", not "". An empty default silently
// strips the v-prefix from all future tags on repos without a config file.
TagPrefix string `yaml:"tag-prefix"`
// CommitTypes controls the allowed commit type set for semrel lint.
CommitTypes CommitTypesConfig `yaml:"commit-types"`
// InitialVersion is the baseline for the bootstrap case (no existing tags).
// Default: "0.0.0". The detected bump is applied on top of this value.
// Must be a valid semver string. Validated by cli.go (not LoadConfig).
InitialVersion string `yaml:"initial-version"`
}
Config is the root structure of .semrelrc.yml.
func DefaultConfig ¶
func DefaultConfig() Config
DefaultConfig returns the hardcoded defaults (current behaviour — no file needed).
func LoadConfig ¶
LoadConfig reads .semrelrc.yml from path.
- Returns (nil, nil) if the file does not exist — caller uses DefaultConfig().
- Returns (nil, err) if the file exists but contains malformed YAML.
- Returns (*Config, nil) on success.
IMPORTANT: YAML is decoded onto a pre-initialised DefaultConfig() struct so that fields absent from the file retain their default values (not zero values).
type LintConfig ¶
type LintConfig struct {
Rules LintRules `yaml:"rules"`
}
LintConfig is the [lint] section of .semrelrc.yml.
type LintOptions ¶
type LintOptions struct {
CapitalFirstLetter bool
RequireScope bool
// AllowedTypes restricts which commit types ValidateAll accepts.
// nil or empty (len == 0) falls back to the built-in validTypes map.
AllowedTypes []CommitType
}
LintOptions is derived from Config.Lint.Rules and passed to ValidateAll.
func DefaultLintOptions ¶
func DefaultLintOptions() LintOptions
DefaultLintOptions returns options matching the hardcoded defaults.
type LintRules ¶
type LintRules struct {
// CapitalFirstLetter fails commits whose description starts with an
// uppercase letter. Default: true.
CapitalFirstLetter bool `yaml:"capital-first-letter"`
// RequireScope fails commits that have no scope. Default: false.
RequireScope bool `yaml:"require-scope"`
}
LintRules controls which lint rules are enforced by ValidateAll.
type Violation ¶
type Violation struct {
SHA string // commit SHA
ShortSHA string // first 7 chars
RawMessage string // original message
Rule string // e.g., "invalid-type", "empty-description", "trailing-period"
Example string // corrected example
}
Violation represents a validation failure
func ValidateAll ¶
func ValidateAll(commits []RawCommit, opts ...LintOptions) []Violation
ValidateAll validates all commits and returns a slice of violations. Never stops at first violation — collects ALL. Returns empty slice (not nil) when all commits are valid. An optional LintOptions argument overrides the default rule set.