issueflow

package
v0.11.2 Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyTrackerStatus

func ApplyTrackerStatus(
	ctx context.Context,
	t tracker.Tracker,
	errW io.Writer,
	issueID, trackerType string,
	pick func(ctx context.Context, issueID, trackerType string, statuses []string) (string, error),
)

ApplyTrackerStatus fetches tracker statuses, prompts the user to pick one, and applies it. All errors are non-fatal warnings. A nil tracker is a no-op.

func RunIssueStart

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

RunIssueStart is the prompter-driven core of the issue-start flow. Called from cmd/issue's 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

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 HuhStartPrompter

type HuhStartPrompter struct{}

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

func NewHuhStartPrompter

func NewHuhStartPrompter() *HuhStartPrompter

NewHuhStartPrompter constructs the production huh-driven StartPrompter.

func (*HuhStartPrompter) ConfirmCreateBranch

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

func (*HuhStartPrompter) ConfirmCreateWorktree

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

func (*HuhStartPrompter) NotifyTrackerError

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

func (*HuhStartPrompter) PickBaseBranch

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

func (*HuhStartPrompter) PickIssueFromTracker

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

func (*HuhStartPrompter) PickIssueFromUser

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

func (*HuhStartPrompter) PickTrackerStatus

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

func (*HuhStartPrompter) PickUseTracker

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

func (*HuhStartPrompter) PickUseWorktree

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

func (*HuhStartPrompter) ResolveBranchConflict

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 StartDeps

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

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

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