issue

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2026 License: MIT Imports: 29 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrBranchLockedForReview = errors.New("branch locked for review")

ErrBranchLockedForReview is returned by reviewPreflight when the branch is locked because a review is in progress. Use errors.Is to detect it.

View Source
var ErrReviewChangesRequested = errors.New("reviewer requested changes")

ErrReviewChangesRequested is returned by reviewPreflight when the reviewer has requested changes. Use errors.Is to detect it.

Functions

func RunIssueStart added in v0.9.6

func RunIssueStart(ctx context.Context, deps StartDeps, prompter StartPrompter) error

RunIssueStart is the prompter-driven core of the issue-start flow. Called from startRunE (production, via a HuhStartPrompter) and from cmd/branch's newRunE (also production). Tests call it directly with a scriptedStartPrompter. TrackerFirst is carried inside deps.Flags.

Returns nil on two non-error exits: (1) pickIssue returns (nil, nil) — only possible when a test prompter does so; production prompters always return a non-nil issue or an error — and (2) prompter.ResolveBranchConflict returns (nil, nil) to signal the operator aborted or checked out an existing branch.

Types

type BranchClient added in v0.9.6

type BranchClient interface {
	BranchExists(name string) (bool, error)
	Checkout(ctx context.Context, branch string) error
	IO() *pkg.IO
}

BranchClient is the subset of *git.Client that ResolveBranchConflict needs. Declared as a small interface so tests can substitute a fake without constructing a full *git.Client.

type ClosePrompter added in v0.9.5

type ClosePrompter interface {
	// PickBranch is called only when at least one in-progress branch exists.
	// A non-nil error indicates cancellation or an internal failure.
	PickBranch(ctx context.Context, branches []store.BranchRow, current string) (*store.BranchRow, error)

	// PickStrategy is called only when MergeDryRun reports no conflicts.
	PickStrategy(ctx context.Context) (MergeStrategy, error)

	// ConfirmMerge gates the actual merge. confirmed=false means the operator
	// declined; runClose prints "Aborted." and returns nil.
	ConfirmMerge(ctx context.Context, branch, base string, strategy MergeStrategy) (confirmed bool, err error)

	// ComposeMessage runs inline AFTER the strategy has staged its changes
	// (after MergeSquash / MergeRebase+soft-reset / MergeNoFFNoCommit). The
	// prefill is already populated with issue-derived type/scope and a
	// strategy-specific subject. The returned tui.CommitOption is passed to
	// git.Client.Commit verbatim.
	ComposeMessage(ctx context.Context, prefill map[string]any) ([]byte, tui.CommitOption, error)

	// PickTrackerStatus is called only when a tracker is configured AND the
	// merge succeeded. An empty return signals "no selection" — the caller
	// decides whether to treat that as skip or abort.
	PickTrackerStatus(ctx context.Context, issueID, trackerType string, statuses []string) (string, error)

	// ConfirmDeleteBranch runs after a successful merge.
	ConfirmDeleteBranch(ctx context.Context, branchName string) (delete bool, err error)
}

ClosePrompter resolves every user-facing decision in the close flow. The production implementation drives huh forms; the test implementation in close_prompter_test.go returns canned values.

Each method maps 1:1 to a huh.NewForm call in the pre-refactor close.go. The order below mirrors the order calls happen in runClose.

type HuhStartPrompter added in v0.9.6

type HuhStartPrompter struct{}

HuhStartPrompter is the production StartPrompter. It opens real huh forms. Constructed once per `issue start` (or `branch new`) invocation.

func NewHuhStartPrompter added in v0.9.6

func NewHuhStartPrompter() *HuhStartPrompter

NewHuhStartPrompter constructs the production huh-driven StartPrompter. Exported so cmd/branch/branch.go can build one when delegating to RunIssueStart.

func (*HuhStartPrompter) ConfirmCreateBranch added in v0.9.6

func (p *HuhStartPrompter) ConfirmCreateBranch(ctx context.Context, message string) (bool, error)

func (*HuhStartPrompter) ConfirmCreateWorktree added in v0.9.6

func (p *HuhStartPrompter) ConfirmCreateWorktree(ctx context.Context, message string) (bool, error)

func (*HuhStartPrompter) NotifyTrackerError added in v0.9.6

func (p *HuhStartPrompter) NotifyTrackerError(ctx context.Context, message string) error

func (*HuhStartPrompter) PickBaseBranch added in v0.11.0

func (p *HuhStartPrompter) PickBaseBranch(ctx context.Context, defaultBase string, branches []string) (string, error)

func (*HuhStartPrompter) PickIssueFromTracker added in v0.9.6

func (p *HuhStartPrompter) PickIssueFromTracker(ctx context.Context, issues []tracker.Issue, allowedTypes []string) (*issuepkg.Issue, error)

func (*HuhStartPrompter) PickIssueFromUser added in v0.9.6

func (p *HuhStartPrompter) PickIssueFromUser(ctx context.Context, allowedTypes []string) (*issuepkg.Issue, error)

func (*HuhStartPrompter) PickTrackerStatus added in v0.9.6

func (p *HuhStartPrompter) PickTrackerStatus(
	ctx context.Context, issueID, trackerType string, statuses []string) (string, error)

func (*HuhStartPrompter) PickUseTracker added in v0.9.6

func (p *HuhStartPrompter) PickUseTracker(ctx context.Context, trackerType string, trackerFirst bool) (bool, error)

func (*HuhStartPrompter) PickUseWorktree added in v0.9.6

func (p *HuhStartPrompter) PickUseWorktree(ctx context.Context) (bool, error)

func (*HuhStartPrompter) ResolveBranchConflict added in v0.9.6

func (p *HuhStartPrompter) ResolveBranchConflict(ctx context.Context, client BranchClient, b *branch.Branch, picked *issuepkg.Issue) (*branch.Branch, error)

ResolveBranchConflict is the production conflict-resolution loop. It is the body of the pre-refactor cmd/issue/conflict.go:resolveBranchConflict lifted verbatim onto the prompter so tests can substitute a scripted result.

type Issue

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

func New

func New(appConfig *config.AppConfig) Issue

func (Issue) GetRootCmd

func (i Issue) GetRootCmd() *cobra.Command

type MergeStrategy added in v0.8.0

type MergeStrategy string
const (
	StrategySquash  MergeStrategy = "squash"
	StrategyRebase  MergeStrategy = "rebase"
	StrategyClassic MergeStrategy = "classic"
)

type StartDeps added in v0.9.6

type StartDeps struct {
	Client             *git.Client
	Cfg                *config.AppConfig
	Tracker            tracker.Tracker // nil when cfg.IssueTracker.Type == ""
	Flags              issue.IssueStartFlags
	BaseBranchOverride string // set by PickBaseBranch; skips store re-query in prepareBranch
}

StartDeps bundles the long-lived dependencies the start flow needs. Production code builds it via BuildStartDeps; tests inject directly. Exported because cmd/branch/branch.go's newRunE constructs one too.

func BuildStartDeps added in v0.9.6

func BuildStartDeps(
	cmd *cobra.Command,
	cfg *config.AppConfig,
	flags issue.IssueStartFlags,
) (StartDeps, error)

BuildStartDeps constructs the production StartDeps from a cobra command. Returns an error if the repo cannot be opened or if a configured tracker (cfg.IssueTracker.Type != "") fails to initialise. When cfg.IssueTracker.Type == "" the returned deps.Tracker is nil and RunIssueStart falls through to the manual issue-input flow.

type StartPrompter added in v0.9.6

type StartPrompter interface {
	// Prompter contributes the three issue-input methods used by
	// issuepkg.GetFromUser and issuepkg.GetFromTracker.
	issuepkg.Prompter

	// PickUseTracker drives the "fetch from tracker?" toggle. Called only when
	// cfg.IssueTracker.Type != "". trackerFirst controls the pre-selected
	// option (true for `issue start`, false for `branch new`).
	PickUseTracker(ctx context.Context, trackerType string, trackerFirst bool) (use bool, err error)

	// PickUseWorktree drives the "worktree vs plain branch?" toggle. Called
	// only when cfg.Branch.UseWorktree == nil.
	PickUseWorktree(ctx context.Context) (use bool, err error)

	// PickBaseBranch presents a picker over all local git branches.
	// defaultBase is pre-selected. Called only when --parent was not explicitly
	// provided and the repo has more than one local branch.
	PickBaseBranch(ctx context.Context, defaultBase string, branches []string) (baseBranch string, err error)

	// ConfirmCreateBranch gates client.CreateBranch. message is the full
	// human-readable "Create branch %q based on %q?" string.
	ConfirmCreateBranch(ctx context.Context, message string) (confirmed bool, err error)

	// ConfirmCreateWorktree gates client.CreateWorktree. message is the full
	// "Create worktree %q at %q based on %q?" string.
	ConfirmCreateWorktree(ctx context.Context, message string) (confirmed bool, err error)

	// PickTrackerStatus drives the tracker status-picker form. An empty return
	// signals "no selection" — the caller decides whether to treat that as
	// skip or abort.
	PickTrackerStatus(ctx context.Context, issueID, trackerType string, statuses []string) (string, error)

	// ResolveBranchConflict owns the conflict-resolution loop. It checks
	// whether b's name already exists locally and, if so, drives the operator
	// through a picker (checkout / variant / abort). Returns (b, nil) on the
	// clean no-collision path. Returns (nil, nil) to signal "stop here, do
	// not create or persist" (operator chose abort or checked out the
	// existing branch). Returns (nil, err) on input or git failures.
	ResolveBranchConflict(ctx context.Context, client BranchClient, b *branch.Branch, picked *issuepkg.Issue) (*branch.Branch, error)
}

StartPrompter resolves every user-facing decision in the issue-start flow. The production implementation drives huh forms; the test implementation in start_prompter_test.go returns canned values.

Methods correspond to the huh forms in the pre-refactor flow. The order below mirrors the order calls happen in RunIssueStart. Note: PickIssueFromTracker covers a single form that lets the operator pick both the issue and its branch type, so the mapping is interface→form, not 1:1 for every UI element.

Jump to

Keyboard shortcuts

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