commit

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2026 License: AGPL-3.0, AGPL-3.0-only Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BranchFromRefspec

func BranchFromRefspec(refspec string) string

BranchFromRefspec extracts the branch name from a refspec like "HEAD:refs/heads/main".

Types

type Backend

type Backend interface {
	Execute(ctx context.Context, plan *Plan, conventional bool) (*Result, error)
}

Backend executes a commit plan.

type DryRunBackend

type DryRunBackend struct {
	RootDir string
}

DryRunBackend prints the commit plan without side effects.

func (*DryRunBackend) Execute

func (d *DryRunBackend) Execute(_ context.Context, plan *Plan, conventional bool) (*Result, error)

Execute simulates the commit and returns what would happen.

type FileChange

type FileChange struct {
	Path    string
	Deleted bool
}

FileChange represents a file with its change status.

type ForgeBackend

type ForgeBackend struct {
	RootDir     string
	ForgeClient forge.Forge
	Branch      string
}

ForgeBackend creates commits purely via forge API (no local git commit).

func (*ForgeBackend) Execute

func (f *ForgeBackend) Execute(ctx context.Context, plan *Plan, conventional bool) (*Result, error)

Execute resolves changed files, reads their content, and commits via forge API.

type GitBackend

type GitBackend struct {
	RootDir string
}

GitBackend executes commits via the git CLI.

func (*GitBackend) Execute

func (g *GitBackend) Execute(_ context.Context, plan *Plan, conventional bool) (*Result, error)

Execute stages files, creates a commit, and optionally pushes via git.

type Plan

type Plan struct {
	Type      string
	Scope     string
	Summary   string
	Body      string
	Breaking  bool
	SkipCI    bool
	Paths     []string // for StageExplicit
	StageMode StageMode
	Push      PushOptions
	SignOff   bool
}

Plan is a fully resolved, validated commit intent.

func BuildPlan

func BuildPlan(opts PlannerOptions, cfg config.CommitConfig, registry *TypeRegistry, rootDir string) (*Plan, error)

BuildPlan merges CLI flags with config defaults, validates, and returns a Plan.

func (Plan) Message

func (p Plan) Message(conventional bool) string

Message renders the full commit message (subject + optional body).

func (Plan) Subject

func (p Plan) Subject(conventional bool) string

Subject renders the commit subject line. When conventional is true: {type}[({scope})][!]: {summary}[ [skip ci]] When conventional is false: {summary}[ [skip ci]]

type PlannerOptions

type PlannerOptions struct {
	Type     string
	Scope    string
	Message  string // positional or --message
	Body     string
	Breaking bool
	SkipCI   *bool    // nil = use config default
	Push     *bool    // nil = use config default
	Paths    []string // from --add flags
	All      bool
	SignOff  bool
	Remote   string
	Refspec  string
}

PlannerOptions holds raw inputs from CLI flags and positional args.

type PushOptions

type PushOptions struct {
	Enabled bool
	Remote  string // default: "origin"
	Refspec string // default: "" (current branch)
}

PushOptions controls post-commit push behavior.

type Result

type Result struct {
	SHA     string
	Message string
	Files   []string // actual staged files (from git diff --cached --name-only)
	Pushed  bool
	NoOp    bool
	Backend string // stable descriptor: "git", "forge (gitlab)", "forge (github)", "dry-run"
}

Result holds the outcome of a commit execution. All informational status must be represented here, not printed by backends.

type StageMode

type StageMode string

StageMode determines how files are staged before commit.

const (
	StageExplicit StageMode = "explicit" // --add paths
	StageAll      StageMode = "all"      // --all (git add -A)
	StageStaged   StageMode = "staged"   // default: commit whatever is already staged
)

type TypeRegistry

type TypeRegistry struct {
	// contains filtered or unexported fields
}

TypeRegistry validates and resolves commit type keys.

func NewTypeRegistry

func NewTypeRegistry(types []config.CommitType) *TypeRegistry

NewTypeRegistry creates a registry from configured commit types.

func (*TypeRegistry) List

func (r *TypeRegistry) List() []config.CommitType

List returns all configured commit types in definition order.

func (*TypeRegistry) Resolve

func (r *TypeRegistry) Resolve(key string) (resolvedKey string, forceBang bool, err error)

Resolve returns the resolved type key and whether a bang (!) is forced. If the type has an AliasFor, it returns the alias target key.

func (*TypeRegistry) Valid

func (r *TypeRegistry) Valid(key string) bool

Valid returns true if the key is a recognized commit type.

Jump to

Keyboard shortcuts

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