config

package
v0.17.14 Latest Latest
Warning

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

Go to latest
Published: May 11, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package config provides repository configuration management, including reading and writing stackit configuration files.

Package config provides repository configuration management.

It handles:

  • Repository-specific configuration (stored in git config)
  • Migration from legacy JSON config to git config
  • Continuation state for interrupted operations (like merge conflicts)

Index

Constants

View Source
const (
	// KeyTrunk is the primary trunk branch name.
	KeyTrunk = "stackit.trunk"
	// KeyTrunks stores additional trunk branches (multi-value).
	KeyTrunks = "stackit.trunks"
	// KeyBranchPattern is the pattern used for generating branch names.
	KeyBranchPattern = "stackit.branch.pattern"
	// KeySubmitFooter controls whether to include PR footer in submissions.
	KeySubmitFooter = "stackit.submit.footer"
	// KeyUndoDepth is the maximum number of undo snapshots to keep.
	KeyUndoDepth = "stackit.undo.depth"
	// KeyWorktreeBasePath is the base path for worktrees.
	KeyWorktreeBasePath = "stackit.worktree.basePath"
	// KeyWorktreeAutoClean controls automatic worktree cleanup during sync.
	KeyWorktreeAutoClean = "stackit.worktree.autoClean"
	// KeyMergeMethod is the preferred merge method (squash, merge, rebase).
	KeyMergeMethod = "stackit.merge.method"
	// KeyCICommand is the unified CI validation command.
	KeyCICommand = "stackit.ci.command"
	// KeyCITimeout is the CI command timeout in seconds.
	KeyCITimeout = "stackit.ci.timeout"
	// KeySplitHunkSelector is the hunk selector mode for split (tui or git).
	KeySplitHunkSelector = "stackit.split.hunkSelector"
	// KeyApprovedHooks stores approved post-worktree-create hooks (multi-value).
	KeyApprovedHooks = "stackit.hooks.approvedPostWorktreeCreate"
	// KeyMaxConcurrency is the maximum number of concurrent validation operations.
	KeyMaxConcurrency = "stackit.maxConcurrency"
	// KeyNavigationWhen controls when navigation is displayed (always/never/multiple).
	KeyNavigationWhen = "stackit.navigation.when"
	// KeyNavigationMarker is the custom marker symbol for the current branch.
	KeyNavigationMarker = "stackit.navigation.marker"
	// KeyNavigationLocation controls where navigation appears (body/comment).
	KeyNavigationLocation = "stackit.navigation.location"
	// KeyNavigationShowMerged controls whether to show merged branch history.
	KeyNavigationShowMerged = "stackit.navigation.showMerged"
	// KeySubmitDraft controls whether to create PRs as drafts by default.
	KeySubmitDraft = "stackit.submit.draft"
	// KeySubmitWeb controls when to open PRs in browser (always/created/never).
	KeySubmitWeb = "stackit.submit.web"
	// KeySubmitLabels stores default labels for PRs (multi-value).
	KeySubmitLabels = "stackit.submit.labels"
	// KeySubmitReviewers stores default reviewers for PRs (multi-value).
	KeySubmitReviewers = "stackit.submit.reviewers"
	// KeySubmitAssignees stores default assignees for PRs (multi-value).
	KeySubmitAssignees = "stackit.submit.assignees"
)

Git config keys for stackit configuration. All keys are prefixed with "stackit." to namespace them within git config.

View Source
const (
	// DefaultTrunk is the default trunk branch name.
	DefaultTrunk = "main"
	// DefaultSubmitFooter is whether to include PR footer by default.
	DefaultSubmitFooter = true
	// DefaultUndoDepth is the default number of undo snapshots to keep.
	DefaultUndoDepth = 10
	// DefaultWorktreeAutoClean is whether to auto-clean worktrees by default.
	DefaultWorktreeAutoClean = true
	// DefaultCITimeout is the default CI timeout in seconds (10 minutes).
	DefaultCITimeout = 600
	// DefaultSplitHunkSelector is the default hunk selector mode.
	DefaultSplitHunkSelector = "tui"
	// DefaultMaxConcurrency is the default max concurrent operations (0 = auto).
	DefaultMaxConcurrency = 0
	// DefaultNavigationWhen is the default navigation display mode.
	DefaultNavigationWhen = "multiple"
	// DefaultNavigationMarker is the default marker for the current branch.
	DefaultNavigationMarker = "👈"
	// DefaultNavigationLocation is the default location for navigation (PR body).
	DefaultNavigationLocation = "body"
	// DefaultNavigationShowMerged is whether to show merged history by default.
	DefaultNavigationShowMerged = true
	// DefaultSubmitDraft is whether to create PRs as drafts by default.
	DefaultSubmitDraft = false
	// DefaultSubmitWeb is when to open PRs in browser by default.
	DefaultSubmitWeb = "never"
)

Default values for configuration.

View Source
const (
	NavigationLocationBody    = "body"
	NavigationLocationComment = "comment"
	NavigationLocationNone    = "none"
)

Navigation location constants.

View Source
const (
	SubmitWebAlways  = "always"
	SubmitWebCreated = "created"
	SubmitWebNever   = "never"
)

Submit web constants.

View Source
const ProjectConfigFileName = ".stackit.yaml"

ProjectConfigFileName is the name of the project configuration file

Variables

View Source
var Options = []Option{

	{
		YAMLPath:    "trunk",
		GitKey:      KeyTrunk,
		Description: "Primary trunk branch",
		Default:     DefaultTrunk,
		Section:     "trunk",
	},
	{
		YAMLPath:    "trunks",
		GitKey:      KeyTrunks,
		Description: "Additional trunk branches (e.g., release branches)",
		IsArray:     true,
		Example:     "develop, release",
		Section:     "trunk",
	},

	{
		YAMLPath:    "branch.pattern",
		GitKey:      KeyBranchPattern,
		Description: "Branch naming pattern",
		Comment:     "Placeholders: {username}, {date}, {message}, {scope}",
		Example:     "{username}/{date}/{message}",
		Section:     "branch",
	},

	{
		YAMLPath:    "submit.footer",
		GitKey:      KeySubmitFooter,
		Description: "Include navigation footer",
		Default:     DefaultSubmitFooter,
		Section:     "submit",
	},
	{
		YAMLPath:    "submit.draft",
		GitKey:      KeySubmitDraft,
		Description: "Create as draft",
		Default:     DefaultSubmitDraft,
		Section:     "submit",
	},
	{
		YAMLPath:    "submit.web",
		GitKey:      KeySubmitWeb,
		Description: "Open in browser: always, created, never",
		Default:     DefaultSubmitWeb,
		ValidValues: ValidSubmitWeb,
		Section:     "submit",
	},
	{
		YAMLPath:    "submit.labels",
		GitKey:      KeySubmitLabels,
		Description: "Default labels",
		IsArray:     true,
		Section:     "submit",
	},
	{
		YAMLPath:    "submit.reviewers",
		GitKey:      KeySubmitReviewers,
		Description: "Default reviewers",
		IsArray:     true,
		Section:     "submit",
	},
	{
		YAMLPath:    "submit.assignees",
		GitKey:      KeySubmitAssignees,
		Description: "Default assignees",
		IsArray:     true,
		Section:     "submit",
	},

	{
		YAMLPath:    "merge.method",
		GitKey:      KeyMergeMethod,
		Description: "Merge method: squash, merge, rebase",
		ValidValues: ValidMergeMethods,
		Example:     "squash",
		Section:     "merge",
	},

	{
		YAMLPath:    "ci.command",
		GitKey:      KeyCICommand,
		Description: "Command to run",
		Example:     "make test",
		Section:     "ci",
	},
	{
		YAMLPath:    "ci.timeout",
		GitKey:      KeyCITimeout,
		Description: "Timeout in seconds",
		Default:     DefaultCITimeout,
		Section:     "ci",
	},

	{
		YAMLPath:    "undo.depth",
		GitKey:      KeyUndoDepth,
		Description: "Max snapshots",
		Default:     DefaultUndoDepth,
		Section:     "undo",
	},

	{
		YAMLPath:    "worktree.basePath",
		GitKey:      KeyWorktreeBasePath,
		Description: "Base directory (empty = auto)",
		Example:     "",
		Section:     "worktree",
	},
	{
		YAMLPath:    "worktree.autoClean",
		GitKey:      KeyWorktreeAutoClean,
		Description: "Clean during sync",
		Default:     DefaultWorktreeAutoClean,
		Section:     "worktree",
	},

	{
		YAMLPath:    "split.hunkSelector",
		GitKey:      KeySplitHunkSelector,
		Description: "tui or git",
		Default:     DefaultSplitHunkSelector,
		ValidValues: ValidHunkSelectors,
		Section:     "split",
	},

	{
		YAMLPath:    "maxConcurrency",
		GitKey:      KeyMaxConcurrency,
		Description: "0 = auto-detect",
		Default:     DefaultMaxConcurrency,
		Section:     "concurrency",
	},

	{
		YAMLPath:    "navigation.when",
		GitKey:      KeyNavigationWhen,
		Description: "always, never, multiple",
		Default:     DefaultNavigationWhen,
		ValidValues: ValidNavigationWhen,
		Section:     "navigation",
	},
	{
		YAMLPath:    "navigation.location",
		GitKey:      KeyNavigationLocation,
		Description: "body, comment, none",
		Default:     DefaultNavigationLocation,
		ValidValues: ValidNavigationLocation,
		Section:     "navigation",
	},
	{
		YAMLPath:    "navigation.marker",
		GitKey:      KeyNavigationMarker,
		Description: "Current branch marker",
		Default:     DefaultNavigationMarker,
		Section:     "navigation",
	},
	{
		YAMLPath:    "navigation.showMerged",
		GitKey:      KeyNavigationShowMerged,
		Description: "Show merged history",
		Default:     DefaultNavigationShowMerged,
		Section:     "navigation",
	},

	{
		YAMLPath:    "hooks.post-worktree-create",
		GitKey:      KeyApprovedHooks,
		Description: "Commands to run after creating a worktree",
		IsArray:     true,
		Example:     "npm install, mise install",
		Section:     "hooks",
	},
}

Options is the registry of all configuration options. This is the single source of truth for all config keys and their metadata.

View Source
var Sections = []Section{
	{Name: "trunk", Title: "", DocsTitle: "Trunk branches"},
	{Name: "branch", Title: "Branch naming pattern", DocsTitle: "Branch naming"},
	{Name: "submit", Title: "PR submission settings", DocsTitle: "PR submission"},
	{Name: "merge", Title: "Merge method: squash, merge, rebase", DocsTitle: "Merge settings"},
	{Name: "ci", Title: "CI validation", DocsTitle: "CI validation"},
	{Name: "undo", Title: "Undo history", DocsTitle: "Other settings"},
	{Name: "worktree", Title: "Worktree settings", DocsTitle: "Worktree settings"},
	{Name: "split", Title: "Split command", DocsTitle: "Split command"},
	{Name: "concurrency", Title: "Concurrency", DocsTitle: ""},
	{Name: "navigation", Title: "PR navigation display", DocsTitle: "PR navigation"},
	{Name: "hooks", Title: "Post-worktree-create hooks (require approval on first run)", DocsTitle: ""},
}

Sections defines the ordering and titles for config sections. This is the single source of truth for section organization.

View Source
var ValidHunkSelectors = []string{"tui", "git"}

ValidHunkSelectors contains the allowed hunk selector values.

View Source
var ValidMergeMethods = []string{"squash", "merge", "rebase"}

ValidMergeMethods contains the allowed merge method values.

ValidNavigationLocation contains the allowed navigation location values. "none" is an alias for disabling navigation (equivalent to when=never).

View Source
var ValidNavigationWhen = []string{"always", "never", "multiple"}

ValidNavigationWhen contains the allowed navigation when values.

ValidSubmitWeb contains the allowed submit.web values.

Functions

func AllGitKeys

func AllGitKeys() []string

AllGitKeys returns all git config keys from the registry.

func ClearContinuationState

func ClearContinuationState(repoRoot string) error

ClearContinuationState removes the continuation state file

func GenerateConfigDocs

func GenerateConfigDocs() string

GenerateConfigDocs generates markdown documentation for all configuration options. This is used to generate the config reference documentation.

func GenerateConfigTemplate

func GenerateConfigTemplate() string

GenerateConfigTemplate generates a .stackit.yaml template with all options commented out. The template is generated from Options, ensuring it stays in sync with the codebase.

func GenerateYAMLExample

func GenerateYAMLExample() string

GenerateYAMLExample generates an example .stackit.yaml with common settings uncommented. This is used in documentation to show a complete working example.

func PersistContinuationState

func PersistContinuationState(repoRoot string, state *ContinuationState) error

PersistContinuationState writes the continuation state to disk

Types

type BranchConfig

type BranchConfig struct {
	Pattern string `yaml:"pattern,omitempty"`
}

BranchConfig contains branch naming configuration

type BranchPattern

type BranchPattern string

BranchPattern represents a branch name pattern with validation

const DefaultBranchPattern BranchPattern = "{username}/{date}/{message}"

DefaultBranchPattern is the default branch name pattern

func NewBranchPattern

func NewBranchPattern(pattern string) (BranchPattern, error)

NewBranchPattern creates a new BranchPattern from a string Returns an error if the pattern is invalid (doesn't contain {message})

func (BranchPattern) ContainsScope

func (p BranchPattern) ContainsScope() bool

ContainsScope returns true if the pattern contains the {scope} placeholder

func (BranchPattern) GetBranchName

func (p BranchPattern) GetBranchName(ctx GitContext, commitMessage string, scope string) (string, error)

GetBranchName generates a branch name from the pattern using the provided commit message and optional scope. It fetches the username and current date internally only if needed by the pattern.

func (BranchPattern) IsValid

func (p BranchPattern) IsValid() bool

IsValid checks if the pattern is valid (contains {message})

func (BranchPattern) String

func (p BranchPattern) String() string

String returns the string representation of the pattern

func (BranchPattern) WithDefault

func (p BranchPattern) WithDefault() BranchPattern

WithDefault returns the pattern, or the default if empty

type CIConfig

type CIConfig struct {
	Command string `yaml:"command,omitempty"`
	Timeout int    `yaml:"timeout,omitempty"`
}

CIConfig contains CI validation configuration

type Configurer

type Configurer interface {
	// Initialization
	IsInitialized() bool

	// Trunk configuration
	Trunk() string
	AllTrunks() []string
	IsTrunk(branch string) bool

	// Branch naming
	BranchNamePattern() string
	GetBranchPattern() BranchPattern

	// Submit settings
	SubmitFooter() bool

	// Undo settings
	UndoStackDepth() int

	// Worktree settings
	WorktreeBasePath() string
	WorktreeAutoClean() bool

	// Merge settings
	MergeMethod() string

	// CI settings
	CICommand() string
	CITimeout() int

	// Split settings
	SplitHunkSelector() string

	// Concurrency settings
	MaxConcurrency() int

	// Navigation settings
	NavigationWhen() string
	NavigationMarker() string
	NavigationLocation() string
	NavigationShowMerged() bool

	// Hook approvals
	ApprovedPostWorktreeCreateHooks() []string
	IsPostWorktreeCreateHookApproved(hook string) bool

	// Deprecated methods (for backwards compatibility)
	CombineCICommand() string
	CombineCITimeout() int
}

Configurer is the interface for stackit configuration. The git-based GitConfig implements this interface.

type ContinuationState

type ContinuationState struct {
	BranchesToRestack     []string `json:"branchesToRestack,omitempty"`
	BranchesToSync        []string `json:"branchesToSync,omitempty"` // For future sync command
	CurrentBranchOverride string   `json:"currentBranchOverride,omitempty"`
	RebasedBranchBase     string   `json:"rebasedBranchBase,omitempty"`
}

ContinuationState represents the state of a command that was interrupted by a rebase conflict

func GetContinuationState

func GetContinuationState(repoRoot string) (*ContinuationState, error)

GetContinuationState reads the continuation state from disk

type GitConfig

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

GitConfig provides typed access to stackit configuration stored in git config. This replaces the JSON-based config storage with native git config. Configuration follows a layered system: personal git config > team project config > defaults.

func LoadConfig

func LoadConfig(repoRoot string) (*GitConfig, error)

LoadConfig loads the repository configuration. This function delegates to LoadGitConfigWithProject for git-based config storage with project config (.stackit.yaml) fallback support. It automatically migrates any existing JSON config to git config.

func LoadGitConfig

func LoadGitConfig(repoRoot string) (*GitConfig, error)

LoadGitConfig loads configuration from git config. If JSON config exists and needs migration, it will be migrated automatically. This function does NOT load project config (.stackit.yaml) - use LoadGitConfigWithProject for that.

func LoadGitConfigWithProject

func LoadGitConfigWithProject(repoRoot string) (*GitConfig, error)

LoadGitConfigWithProject loads configuration from git config with project config fallback. The layered system follows: personal git config > team project config (.stackit.yaml) > defaults.

func (*GitConfig) AddApprovedPostWorktreeCreateHook

func (c *GitConfig) AddApprovedPostWorktreeCreateHook(hook string) error

AddApprovedPostWorktreeCreateHook adds a hook to the approved list.

func (*GitConfig) AddSubmitAssignee

func (c *GitConfig) AddSubmitAssignee(assignee string) error

AddSubmitAssignee adds an assignee to the default assignees.

func (*GitConfig) AddSubmitLabel

func (c *GitConfig) AddSubmitLabel(label string) error

AddSubmitLabel adds a label to the default labels.

func (*GitConfig) AddSubmitReviewer

func (c *GitConfig) AddSubmitReviewer(reviewer string) error

AddSubmitReviewer adds a reviewer to the default reviewers.

func (*GitConfig) AddTrunk

func (c *GitConfig) AddTrunk(trunk string) error

AddTrunk adds an additional trunk branch.

func (*GitConfig) AllTrunks

func (c *GitConfig) AllTrunks() []string

AllTrunks returns all configured trunk branches (primary + additional). Merges trunks from git config and project config (deduplicated).

func (*GitConfig) ApprovedPostWorktreeCreateHooks

func (c *GitConfig) ApprovedPostWorktreeCreateHooks() []string

ApprovedPostWorktreeCreateHooks returns the list of approved hooks.

func (*GitConfig) BranchNamePattern

func (c *GitConfig) BranchNamePattern() string

BranchNamePattern returns the branch name pattern. Priority: personal git config > team project config > default.

func (*GitConfig) CICommand

func (c *GitConfig) CICommand() string

CICommand returns the CI validation command. Priority: personal git config > team project config > empty (not set).

func (*GitConfig) CITimeout

func (c *GitConfig) CITimeout() int

CITimeout returns the CI timeout in seconds. Priority: personal git config > team project config > default.

func (*GitConfig) ClearApprovedPostWorktreeCreateHooks

func (c *GitConfig) ClearApprovedPostWorktreeCreateHooks() error

ClearApprovedPostWorktreeCreateHooks removes all hook approvals.

func (*GitConfig) ClearTrunks

func (c *GitConfig) ClearTrunks() error

ClearTrunks removes all additional trunks from personal git config. Note: Trunks from team config (.stackit.yaml) will still be visible in AllTrunks().

func (*GitConfig) CombineCICommand

func (c *GitConfig) CombineCICommand() string

CombineCICommand returns the CI command (deprecated, use CICommand).

func (*GitConfig) CombineCITimeout

func (c *GitConfig) CombineCITimeout() int

CombineCITimeout returns the CI timeout (deprecated, use CITimeout).

func (*GitConfig) GetBranchPattern

func (c *GitConfig) GetBranchPattern() BranchPattern

GetBranchPattern returns the branch pattern object.

func (*GitConfig) IsInitialized

func (c *GitConfig) IsInitialized() bool

IsInitialized checks if stackit has been initialized (trunk is set).

func (*GitConfig) IsPostWorktreeCreateHookApproved

func (c *GitConfig) IsPostWorktreeCreateHookApproved(hook string) bool

IsPostWorktreeCreateHookApproved checks if a hook is approved.

func (*GitConfig) IsTrunk

func (c *GitConfig) IsTrunk(branch string) bool

IsTrunk checks if a branch is configured as a trunk.

func (*GitConfig) MaxConcurrency

func (c *GitConfig) MaxConcurrency() int

MaxConcurrency returns the maximum number of concurrent validation operations. Priority: personal git config > team project config > default (0 = auto based on CPU count).

func (*GitConfig) MergeMethod

func (c *GitConfig) MergeMethod() string

MergeMethod returns the configured merge method (empty if not set). Priority: personal git config > team project config > empty (not set).

func (*GitConfig) NavigationLocation

func (c *GitConfig) NavigationLocation() string

NavigationLocation returns where navigation should appear. Priority: personal git config > team project config > default.

func (*GitConfig) NavigationMarker

func (c *GitConfig) NavigationMarker() string

NavigationMarker returns the marker symbol for the current branch. Priority: personal git config > team project config > default.

func (*GitConfig) NavigationShowMerged

func (c *GitConfig) NavigationShowMerged() bool

NavigationShowMerged returns whether to show merged branch history. Priority: personal git config > team project config > default.

func (*GitConfig) NavigationWhen

func (c *GitConfig) NavigationWhen() string

NavigationWhen returns when navigation should be displayed. Priority: personal git config > team project config > default.

func (*GitConfig) RemoveApprovedPostWorktreeCreateHook

func (c *GitConfig) RemoveApprovedPostWorktreeCreateHook(hook string) error

RemoveApprovedPostWorktreeCreateHook removes a hook from the approved list.

func (*GitConfig) RemoveTrunk

func (c *GitConfig) RemoveTrunk(trunk string) error

RemoveTrunk removes a trunk from the additional trunks list. Cannot remove the primary trunk (use SetTrunk to change it).

func (*GitConfig) ResetAllPersonal

func (c *GitConfig) ResetAllPersonal() error

ResetAllPersonal removes all personal configuration overrides, reverting to team/default values. This clears all stackit.* keys from the local git config.

func (*GitConfig) Save

func (c *GitConfig) Save() error

Save is a no-op for GitConfig since git config writes are immediate. This method exists for API compatibility with the old Config type.

func (*GitConfig) SetBranchNamePattern

func (c *GitConfig) SetBranchNamePattern(pattern string) error

SetBranchNamePattern sets the branch name pattern.

func (*GitConfig) SetCICommand

func (c *GitConfig) SetCICommand(cmd string) error

SetCICommand sets the CI validation command.

func (*GitConfig) SetCITimeout

func (c *GitConfig) SetCITimeout(seconds int) error

SetCITimeout sets the CI timeout in seconds. Must be at least 1 second. To revert to the default timeout, use UnsetCITimeout() instead of setting to 0.

func (*GitConfig) SetCombineCICommand

func (c *GitConfig) SetCombineCICommand(cmd string)

SetCombineCICommand sets the CI command (deprecated, use SetCICommand).

func (*GitConfig) SetCombineCITimeout

func (c *GitConfig) SetCombineCITimeout(seconds int)

SetCombineCITimeout sets the CI timeout (deprecated, use SetCITimeout).

func (*GitConfig) SetMaxConcurrency

func (c *GitConfig) SetMaxConcurrency(n int) error

SetMaxConcurrency sets the maximum number of concurrent validation operations.

func (*GitConfig) SetMergeMethod

func (c *GitConfig) SetMergeMethod(method string) error

SetMergeMethod sets the merge method preference.

func (*GitConfig) SetNavigationLocation

func (c *GitConfig) SetNavigationLocation(location string) error

SetNavigationLocation sets where navigation should appear.

func (*GitConfig) SetNavigationMarker

func (c *GitConfig) SetNavigationMarker(marker string) error

SetNavigationMarker sets the marker symbol for the current branch.

func (*GitConfig) SetNavigationShowMerged

func (c *GitConfig) SetNavigationShowMerged(show bool) error

SetNavigationShowMerged sets whether to show merged branch history.

func (*GitConfig) SetNavigationWhen

func (c *GitConfig) SetNavigationWhen(when string) error

SetNavigationWhen sets when navigation should be displayed.

func (*GitConfig) SetSplitHunkSelector

func (c *GitConfig) SetSplitHunkSelector(selector string) error

SetSplitHunkSelector sets the hunk selector mode.

func (*GitConfig) SetSubmitAssignees

func (c *GitConfig) SetSubmitAssignees(assignees []string) error

SetSubmitAssignees sets the default assignees for PRs. This replaces all existing assignees.

func (*GitConfig) SetSubmitDraft

func (c *GitConfig) SetSubmitDraft(draft bool) error

SetSubmitDraft sets whether to create PRs as drafts by default.

func (*GitConfig) SetSubmitFooter

func (c *GitConfig) SetSubmitFooter(enabled bool) error

SetSubmitFooter sets whether to include PR footer.

func (*GitConfig) SetSubmitLabels

func (c *GitConfig) SetSubmitLabels(labels []string) error

SetSubmitLabels sets the default labels for PRs. This replaces all existing labels.

func (*GitConfig) SetSubmitReviewers

func (c *GitConfig) SetSubmitReviewers(reviewers []string) error

SetSubmitReviewers sets the default reviewers for PRs. This replaces all existing reviewers.

func (*GitConfig) SetSubmitWeb

func (c *GitConfig) SetSubmitWeb(web string) error

SetSubmitWeb sets when to open PRs in browser.

func (*GitConfig) SetTrunk

func (c *GitConfig) SetTrunk(trunk string) error

SetTrunk sets the primary trunk branch name.

func (*GitConfig) SetUndoStackDepth

func (c *GitConfig) SetUndoStackDepth(depth int) error

SetUndoStackDepth sets the max undo depth.

func (*GitConfig) SetWorktreeAutoClean

func (c *GitConfig) SetWorktreeAutoClean(enabled bool) error

SetWorktreeAutoClean sets whether to auto-clean worktrees.

func (*GitConfig) SetWorktreeBasePath

func (c *GitConfig) SetWorktreeBasePath(path string) error

SetWorktreeBasePath sets the worktree base path.

func (*GitConfig) SplitHunkSelector

func (c *GitConfig) SplitHunkSelector() string

SplitHunkSelector returns the hunk selector mode. Priority: personal git config > team project config > default.

func (*GitConfig) SubmitAssignees

func (c *GitConfig) SubmitAssignees() []string

SubmitAssignees returns the default assignees for PRs. Merges assignees from git config and project config (deduplicated).

func (*GitConfig) SubmitDraft

func (c *GitConfig) SubmitDraft() bool

SubmitDraft returns whether to create PRs as drafts by default. Priority: personal git config > team project config > default.

func (*GitConfig) SubmitFooter

func (c *GitConfig) SubmitFooter() bool

SubmitFooter returns whether to include PR footer. Priority: personal git config > team project config > default.

func (*GitConfig) SubmitLabels

func (c *GitConfig) SubmitLabels() []string

SubmitLabels returns the default labels for PRs. Merges labels from git config and project config (deduplicated).

func (*GitConfig) SubmitReviewers

func (c *GitConfig) SubmitReviewers() []string

SubmitReviewers returns the default reviewers for PRs. Merges reviewers from git config and project config (deduplicated).

func (*GitConfig) SubmitWeb

func (c *GitConfig) SubmitWeb() string

SubmitWeb returns when to open PRs in browser. Priority: personal git config > team project config > default.

func (*GitConfig) Trunk

func (c *GitConfig) Trunk() string

Trunk returns the primary trunk branch name. Priority: personal git config > team project config > default.

func (*GitConfig) UndoStackDepth

func (c *GitConfig) UndoStackDepth() int

UndoStackDepth returns the max undo depth. Priority: personal git config > team project config > default.

func (*GitConfig) UnsetBranchNamePattern

func (c *GitConfig) UnsetBranchNamePattern() error

UnsetBranchNamePattern removes the personal branch name pattern, reverting to project/default.

func (*GitConfig) UnsetCICommand

func (c *GitConfig) UnsetCICommand() error

UnsetCICommand removes the personal CI command setting, reverting to project/default.

func (*GitConfig) UnsetCITimeout

func (c *GitConfig) UnsetCITimeout() error

UnsetCITimeout removes the personal CI timeout setting, reverting to project/default.

func (*GitConfig) UnsetMaxConcurrency

func (c *GitConfig) UnsetMaxConcurrency() error

UnsetMaxConcurrency removes the personal max concurrency setting, reverting to default.

func (*GitConfig) UnsetMergeMethod

func (c *GitConfig) UnsetMergeMethod() error

UnsetMergeMethod removes the personal merge method setting, reverting to project/default.

func (*GitConfig) UnsetNavigationLocation

func (c *GitConfig) UnsetNavigationLocation() error

UnsetNavigationLocation removes the personal navigation.location setting, reverting to project/default.

func (*GitConfig) UnsetNavigationMarker

func (c *GitConfig) UnsetNavigationMarker() error

UnsetNavigationMarker removes the personal navigation.marker setting, reverting to project/default.

func (*GitConfig) UnsetNavigationShowMerged

func (c *GitConfig) UnsetNavigationShowMerged() error

UnsetNavigationShowMerged removes the personal navigation.showMerged setting, reverting to project/default.

func (*GitConfig) UnsetNavigationWhen

func (c *GitConfig) UnsetNavigationWhen() error

UnsetNavigationWhen removes the personal navigation.when setting, reverting to project/default.

func (*GitConfig) UnsetSplitHunkSelector

func (c *GitConfig) UnsetSplitHunkSelector() error

UnsetSplitHunkSelector removes the personal split hunk selector setting, reverting to project/default.

func (*GitConfig) UnsetSubmitAssignees

func (c *GitConfig) UnsetSubmitAssignees() error

UnsetSubmitAssignees removes all personal submit.assignees, reverting to project/default.

func (*GitConfig) UnsetSubmitDraft

func (c *GitConfig) UnsetSubmitDraft() error

UnsetSubmitDraft removes the personal submit.draft setting, reverting to project/default.

func (*GitConfig) UnsetSubmitFooter

func (c *GitConfig) UnsetSubmitFooter() error

UnsetSubmitFooter removes the personal submit footer setting, reverting to project/default.

func (*GitConfig) UnsetSubmitLabels

func (c *GitConfig) UnsetSubmitLabels() error

UnsetSubmitLabels removes all personal submit.labels, reverting to project/default.

func (*GitConfig) UnsetSubmitReviewers

func (c *GitConfig) UnsetSubmitReviewers() error

UnsetSubmitReviewers removes all personal submit.reviewers, reverting to project/default.

func (*GitConfig) UnsetSubmitWeb

func (c *GitConfig) UnsetSubmitWeb() error

UnsetSubmitWeb removes the personal submit.web setting, reverting to project/default.

func (*GitConfig) UnsetTrunk

func (c *GitConfig) UnsetTrunk() error

UnsetTrunk removes the personal trunk setting, reverting to project/default. Note: This only makes sense if there's a project config with a trunk set, otherwise the effective trunk will be the built-in default ("main").

func (*GitConfig) UnsetUndoStackDepth

func (c *GitConfig) UnsetUndoStackDepth() error

UnsetUndoStackDepth removes the personal undo stack depth setting, reverting to project/default.

func (*GitConfig) UnsetWorktreeAutoClean

func (c *GitConfig) UnsetWorktreeAutoClean() error

UnsetWorktreeAutoClean removes the personal worktree auto clean setting, reverting to project/default.

func (*GitConfig) UnsetWorktreeBasePath

func (c *GitConfig) UnsetWorktreeBasePath() error

UnsetWorktreeBasePath removes the personal worktree base path setting, reverting to project/default.

func (*GitConfig) WorktreeAutoClean

func (c *GitConfig) WorktreeAutoClean() bool

WorktreeAutoClean returns whether to auto-clean worktrees. Priority: personal git config > team project config > default.

func (*GitConfig) WorktreeBasePath

func (c *GitConfig) WorktreeBasePath() string

WorktreeBasePath returns the worktree base path. Priority: personal git config > team project config > empty (not set).

type GitContext

type GitContext interface {
	context.Context
	Git() git.Runner
}

GitContext is a minimal interface that provides a git runner and context. This matches app.Context but avoids a circular dependency.

type HooksConfig

type HooksConfig struct {
	// PostWorktreeCreate contains commands to run after creating a worktree
	PostWorktreeCreate []string `yaml:"post-worktree-create"`
}

HooksConfig contains hook configurations

type MergeConfig

type MergeConfig struct {
	Method string `yaml:"method,omitempty"`
}

MergeConfig contains merge method configuration

type NavigationConfig struct {
	When       string `yaml:"when,omitempty"`       // always/never/multiple
	Marker     string `yaml:"marker,omitempty"`     // custom marker symbol
	Location   string `yaml:"location,omitempty"`   // body/comment
	ShowMerged *bool  `yaml:"showMerged,omitempty"` // show merged history
}

NavigationConfig contains PR navigation display settings

type Option

type Option struct {
	// YAMLPath is the path in the YAML config file (e.g., "submit.footer")
	YAMLPath string
	// GitKey is the full git config key (e.g., "stackit.submit.footer")
	GitKey string
	// Description is a human-readable description of the option
	Description string
	// Default is the default value (nil if no default)
	Default any
	// ValidValues lists allowed values for enum-type options (nil if any value allowed)
	ValidValues []string
	// Example is an example value for the template (optional, used when Default is nil)
	Example string
	// IsArray indicates this is a multi-value option
	IsArray bool
	// Section groups related options together in the generated template
	Section string
	// Comment provides additional context in the template (e.g., "Placeholders: {username}, {date}")
	Comment string
}

Option describes a single configuration option for documentation and template generation.

func GetOptionByGitKey

func GetOptionByGitKey(gitKey string) *Option

GetOptionByGitKey returns the Option for a given git key, or nil if not found.

func GetOptionByYAMLPath

func GetOptionByYAMLPath(yamlPath string) *Option

GetOptionByYAMLPath returns the Option for a given YAML path, or nil if not found.

func GetOptionsForSection

func GetOptionsForSection(section string) []Option

GetOptionsForSection returns all options belonging to the given section.

type ProjectConfig

type ProjectConfig struct {
	Trunk  string   `yaml:"trunk,omitempty"`
	Trunks []string `yaml:"trunks,omitempty"`

	Branch         BranchConfig     `yaml:"branch,omitempty"`
	Submit         SubmitConfig     `yaml:"submit,omitempty"`
	Merge          MergeConfig      `yaml:"merge,omitempty"`
	CI             CIConfig         `yaml:"ci,omitempty"`
	Undo           UndoConfig       `yaml:"undo,omitempty"`
	Worktree       WorktreeConfig   `yaml:"worktree,omitempty"`
	Split          SplitConfig      `yaml:"split,omitempty"`
	Hooks          HooksConfig      `yaml:"hooks,omitempty"`
	MaxConcurrency *int             `yaml:"maxConcurrency,omitempty"` // Pointer to distinguish unset from 0
	Navigation     NavigationConfig `yaml:"navigation,omitempty"`
}

ProjectConfig represents the project-level configuration stored in .stackit.yaml This file is committed to the repository and shared across the team. Team settings can be overridden by personal git config (git config > project config > defaults).

func LoadProjectConfig

func LoadProjectConfig(repoRoot string) (*ProjectConfig, error)

LoadProjectConfig reads the project configuration from .stackit.yaml in the repo root. Returns an empty config (not an error) if the file doesn't exist.

func (*ProjectConfig) GetMaxConcurrency

func (c *ProjectConfig) GetMaxConcurrency() int

GetMaxConcurrency returns the max concurrency value (caller should check HasMaxConcurrency first)

func (*ProjectConfig) GetNavigationShowMerged

func (c *ProjectConfig) GetNavigationShowMerged() bool

GetNavigationShowMerged returns the navigation.showMerged value (caller should check HasNavigationShowMerged first)

func (*ProjectConfig) GetSubmitDraft

func (c *ProjectConfig) GetSubmitDraft() bool

GetSubmitDraft returns the submit draft value (caller should check HasSubmitDraft first)

func (*ProjectConfig) GetSubmitFooter

func (c *ProjectConfig) GetSubmitFooter() bool

GetSubmitFooter returns the submit footer value (caller should check HasSubmitFooter first)

func (*ProjectConfig) GetWorktreeAutoClean

func (c *ProjectConfig) GetWorktreeAutoClean() bool

GetWorktreeAutoClean returns the worktree auto clean value (caller should check HasWorktreeAutoClean first)

func (*ProjectConfig) HasBranchPattern

func (c *ProjectConfig) HasBranchPattern() bool

HasBranchPattern returns true if a branch naming pattern is configured

func (*ProjectConfig) HasCICommand

func (c *ProjectConfig) HasCICommand() bool

HasCICommand returns true if a CI command is configured

func (*ProjectConfig) HasCITimeout

func (c *ProjectConfig) HasCITimeout() bool

HasCITimeout returns true if a CI timeout is configured

func (*ProjectConfig) HasMaxConcurrency

func (c *ProjectConfig) HasMaxConcurrency() bool

HasMaxConcurrency returns true if max concurrency is configured

func (*ProjectConfig) HasMergeMethod

func (c *ProjectConfig) HasMergeMethod() bool

HasMergeMethod returns true if a merge method is configured

func (*ProjectConfig) HasNavigationLocation

func (c *ProjectConfig) HasNavigationLocation() bool

HasNavigationLocation returns true if navigation.location is configured

func (*ProjectConfig) HasNavigationMarker

func (c *ProjectConfig) HasNavigationMarker() bool

HasNavigationMarker returns true if navigation.marker is configured

func (*ProjectConfig) HasNavigationShowMerged

func (c *ProjectConfig) HasNavigationShowMerged() bool

HasNavigationShowMerged returns true if navigation.showMerged is configured

func (*ProjectConfig) HasNavigationWhen

func (c *ProjectConfig) HasNavigationWhen() bool

HasNavigationWhen returns true if navigation.when is configured

func (*ProjectConfig) HasPostWorktreeCreateHooks

func (c *ProjectConfig) HasPostWorktreeCreateHooks() bool

HasPostWorktreeCreateHooks returns true if there are any post-worktree-create hooks configured

func (*ProjectConfig) HasSplitHunkSelector

func (c *ProjectConfig) HasSplitHunkSelector() bool

HasSplitHunkSelector returns true if split hunk selector is configured

func (*ProjectConfig) HasSubmitAssignees

func (c *ProjectConfig) HasSubmitAssignees() bool

HasSubmitAssignees returns true if default assignees are configured

func (*ProjectConfig) HasSubmitDraft

func (c *ProjectConfig) HasSubmitDraft() bool

HasSubmitDraft returns true if the submit draft setting is configured

func (*ProjectConfig) HasSubmitFooter

func (c *ProjectConfig) HasSubmitFooter() bool

HasSubmitFooter returns true if the submit footer setting is configured

func (*ProjectConfig) HasSubmitLabels

func (c *ProjectConfig) HasSubmitLabels() bool

HasSubmitLabels returns true if default labels are configured

func (*ProjectConfig) HasSubmitReviewers

func (c *ProjectConfig) HasSubmitReviewers() bool

HasSubmitReviewers returns true if default reviewers are configured

func (*ProjectConfig) HasSubmitWeb

func (c *ProjectConfig) HasSubmitWeb() bool

HasSubmitWeb returns true if the submit web setting is configured

func (*ProjectConfig) HasTrunk

func (c *ProjectConfig) HasTrunk() bool

HasTrunk returns true if a trunk branch is configured

func (*ProjectConfig) HasTrunks

func (c *ProjectConfig) HasTrunks() bool

HasTrunks returns true if additional trunk branches are configured

func (*ProjectConfig) HasUndoDepth

func (c *ProjectConfig) HasUndoDepth() bool

HasUndoDepth returns true if undo depth is configured

func (*ProjectConfig) HasWorktreeAutoClean

func (c *ProjectConfig) HasWorktreeAutoClean() bool

HasWorktreeAutoClean returns true if worktree auto clean is configured

func (*ProjectConfig) HasWorktreeBasePath

func (c *ProjectConfig) HasWorktreeBasePath() bool

HasWorktreeBasePath returns true if worktree base path is configured

func (*ProjectConfig) Validate

func (c *ProjectConfig) Validate() error

Validate checks the configuration for invalid values

type RepoConfig

type RepoConfig struct {
	Trunk                           *string  `json:"trunk,omitempty"`
	Trunks                          []string `json:"trunks,omitempty"`
	IsGithubIntegrationEnabled      *bool    `json:"isGithubIntegrationEnabled,omitempty"`
	BranchNamePattern               *string  `json:"branchNamePattern,omitempty"`
	SubmitFooter                    *bool    `json:"submit.footer,omitempty"`
	UndoStackDepth                  *int     `json:"undo.stackDepth,omitempty"`
	MaxConcurrency                  *int     `json:"maxConcurrency,omitempty"` // Maximum concurrent validation operations
	WorktreeBasePath                *string  `json:"worktree.basePath,omitempty"`
	WorktreeAutoClean               *bool    `json:"worktree.autoClean,omitempty"`
	MergeMethod                     *string  `json:"merge.method,omitempty"`
	CombineCICommand                *string  `json:"combine.ciCommand,omitempty"` // Deprecated: use CICommand
	CombineCITimeout                *int     `json:"combine.ciTimeout,omitempty"` // Deprecated: use CITimeout
	CICommand                       *string  `json:"ci.command,omitempty"`        // Unified CI command for all validation
	CITimeout                       *int     `json:"ci.timeout,omitempty"`        // Unified CI timeout in seconds
	SplitHunkSelector               *string  `json:"split.hunkSelector,omitempty"`
	ApprovedPostWorktreeCreateHooks []string `json:"hooks.approvedPostWorktreeCreate,omitempty"`
}

RepoConfig represents the legacy JSON-based repository configuration. This struct is used only for migration from the old .stackit_config JSON format.

func (*RepoConfig) GetBranchPattern

func (c *RepoConfig) GetBranchPattern() BranchPattern

GetBranchPattern returns the branch name pattern as a BranchPattern type. Always returns a valid pattern (default if not set or invalid).

type Section

type Section struct {
	// Name is the internal identifier (matches Option.Section)
	Name string
	// Title is the display title for templates (empty = no header comment)
	Title string
	// DocsTitle is the display title for documentation (empty = skip in docs)
	DocsTitle string
}

Section defines a group of related options for documentation and templates.

func GetSectionByName

func GetSectionByName(name string) *Section

GetSectionByName returns the Section with the given name, or nil if not found.

type SplitConfig

type SplitConfig struct {
	HunkSelector string `yaml:"hunkSelector,omitempty"`
}

SplitConfig contains split settings

type SubmitConfig

type SubmitConfig struct {
	Footer    *bool    `yaml:"footer,omitempty"`    // Pointer to distinguish unset from false
	Draft     *bool    `yaml:"draft,omitempty"`     // Pointer to distinguish unset from false
	Web       string   `yaml:"web,omitempty"`       // "always", "created", "never"
	Labels    []string `yaml:"labels,omitempty"`    // Default labels for PRs
	Reviewers []string `yaml:"reviewers,omitempty"` // Default reviewers for PRs
	Assignees []string `yaml:"assignees,omitempty"` // Default assignees for PRs
}

SubmitConfig contains PR submission configuration

type UndoConfig

type UndoConfig struct {
	Depth int `yaml:"depth,omitempty"`
}

UndoConfig contains undo settings

type WorktreeConfig

type WorktreeConfig struct {
	BasePath  string `yaml:"basePath,omitempty"`
	AutoClean *bool  `yaml:"autoClean,omitempty"` // Pointer to distinguish unset from false
}

WorktreeConfig contains worktree settings

Jump to

Keyboard shortcuts

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