commitmsg

package
v0.0.0-...-44943ba Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 21, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultConfigFile = ".commit-msg-lint.yml"

DefaultConfigFile is the name of the configuration file.

Variables

This section is empty.

Functions

func Run

func Run(stdin io.Reader, args []string) error

Run validates commit messages. Mode is auto-detected from the arguments:

  • If --base-ref / --head-ref flags are present: CI mode (validate commit range)
  • If args[1] is an existing file: commit-msg hook mode (validate that file)
  • Otherwise: pre-push hook mode (read refs from stdin)

func RunPrePushHook

func RunPrePushHook(stdin io.Reader, _ []string) error

RunPrePushHook validates commits from git pre-push hook input on stdin. Use this entry point when the binary is explicitly deployed as a pre-push hook, bypassing the auto-detection in Run.

Types

type Config

type Config struct {
	Rules    []Rule   `yaml:"rules"`
	Settings Settings `yaml:"settings,omitempty"`
}

Config represents the complete configuration for commit message linting.

func LoadConfig

func LoadConfig(repoPath string) (*Config, error)

LoadConfig loads and validates configuration from the specified directory.

type ParsedCommitMessage

type ParsedCommitMessage struct {
	Raw    string
	Title  string
	Body   string
	Footer string
}

ParsedCommitMessage represents a commit message split into sections.

func ParseCommitMessage

func ParseCommitMessage(message string) ParsedCommitMessage

ParseCommitMessage parses a commit message into title, body, and footer.

Parsing rules: - Sections are separated by empty lines (lines with only whitespace) - Title: First section (always present) - Footer: Last section (after final empty line), if 2+ sections exist - Body: All middle sections (between title and footer), if 3+ sections exist.

type Rule

type Rule struct {
	Name    string   `yaml:"name"`
	Type    RuleType `yaml:"type"`
	Scope   Scope    `yaml:"scope"`
	Pattern string   `yaml:"pattern"`
	Message string   `yaml:"message,omitempty"`
	// contains filtered or unexported fields
}

Rule represents a single linting rule.

type RuleType

type RuleType string

RuleType defines the type of rule enforcement.

const (
	// RuleTypeDeny fails if the pattern matches.
	RuleTypeDeny RuleType = "deny"
	// RuleTypeRequire fails if the pattern does NOT match.
	RuleTypeRequire RuleType = "require"
)

type RuleViolation

type RuleViolation struct {
	Rule    Rule
	Matched bool // For deny rules: true means pattern matched (violation)

}

RuleViolation represents a failed rule check.

func EvaluateRules

func EvaluateRules(rules []Rule, message ParsedCommitMessage) []RuleViolation

EvaluateRules evaluates all rules against a parsed commit message. Returns a slice of violations (empty if all rules pass).

type Scope

type Scope string

Scope defines where in the commit message to search.

const (
	// ScopeTitle searches only the first line (title).
	ScopeTitle Scope = "title"
	// ScopeBody searches the middle sections (between title and footer).
	ScopeBody Scope = "body"
	// ScopeFooter searches the last section (after final empty line).
	ScopeFooter Scope = "footer"
	// ScopeMessage searches the complete commit message.
	ScopeMessage Scope = "message"
)

type Settings

type Settings struct {
	FailFast         bool     `yaml:"fail_fast,omitempty"`
	SkipMergeCommits *bool    `yaml:"skip_merge_commits,omitempty"`
	SkipAuthors      []string `yaml:"skip_authors,omitempty"`
	MainRef          string   `yaml:"main_ref,omitempty"`
}

Settings contains global configuration options.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL