Documentation
¶
Overview ¶
Package app holds the use cases. Both the cobra commands and the MCP tools call into it, so no behaviour lives anywhere else.
Index ¶
- Variables
- func FindPRTemplate(topLevel string) (string, bool)
- func PRsFor(prs []forge.PullRequest) map[string]forge.PullRequest
- func Slug(s string) string
- type App
- func (a *App) CachedPRs(repo git.Repo) ([]forge.PullRequest, cache.State, time.Time)
- func (a *App) Checkout(ctx context.Context, repo git.Repo, name string) error
- func (a *App) Create(ctx context.Context, repo git.Repo, o CreateOptions) (CreateResult, error)
- func (a *App) Modify(ctx context.Context, repo git.Repo, o ModifyOptions) (ModifyResult, error)
- func (a *App) Navigate(ctx context.Context, repo git.Repo, req stack.NavRequest) (stack.NavResult, error)
- func (a *App) RefreshPRs(ctx context.Context, repo git.Repo) ([]forge.PullRequest, error)
- func (a *App) Restack(ctx context.Context, repo git.Repo, o RestackOptions) (RestackResult, error)
- func (a *App) Submit(ctx context.Context, repo git.Repo, o SubmitOptions) (SubmitResult, error)
- func (a *App) Sync(ctx context.Context, repo git.Repo, o SyncOptions) (SyncResult, error)
- func (a *App) Trunk(ctx context.Context, repo git.Repo) (string, error)
- func (a *App) View(ctx context.Context, repo git.Repo, o ViewOptions) (*View, error)
- type CommitInfo
- type CreateOptions
- type CreateResult
- type Deps
- type ModifyOptions
- type ModifyResult
- type PRMode
- type PRSnapshot
- type PRText
- type Phase
- type Prompter
- type RestackOptions
- type RestackResult
- type Row
- type StagingMode
- type SubmitOptions
- type SubmitResult
- type SubmittedPR
- type SyncOptions
- type SyncResult
- type SyncedStack
- type View
- type ViewOptions
Constants ¶
This section is empty.
Variables ¶
var ErrNoForge = stack.New(stack.KindUnsupported, "no forge configured for pull requests")
ErrNoForge is returned when no forge adapter is configured.
Functions ¶
func FindPRTemplate ¶
FindPRTemplate returns the repository's pull request template, if any, with YAML front matter removed. The lookup mirrors gh: a regular file named pull_request_template.* in .github/, the root, or docs/.
func PRsFor ¶
func PRsFor(prs []forge.PullRequest) map[string]forge.PullRequest
PRsFor picks the pull request to show for each branch: an open or draft PR wins over merged, which wins over closed; ties go to the most recent.
Types ¶
type App ¶
type App struct {
// contains filtered or unexported fields
}
App exposes the use cases.
func (*App) Create ¶
func (a *App) Create(ctx context.Context, repo git.Repo, o CreateOptions) (CreateResult, error)
Create stages, creates a branch on top of the current one, commits and registers the branch with the backend.
func (*App) Modify ¶
func (a *App) Modify(ctx context.Context, repo git.Repo, o ModifyOptions) (ModifyResult, error)
Modify amends (or adds to) the current branch and restacks its descendants.
func (*App) Navigate ¶
func (a *App) Navigate(ctx context.Context, repo git.Repo, req stack.NavRequest) (stack.NavResult, error)
Navigate moves along the current stack (up/down/top/bottom) and checks out the destination. The pure computation lives in stack.Navigate.
func (*App) RefreshPRs ¶
RefreshPRs fetches pull requests from the forge and updates the cache.
func (*App) Restack ¶
func (a *App) Restack(ctx context.Context, repo git.Repo, o RestackOptions) (RestackResult, error)
Restack rebases the current stack locally (no fetch).
func (*App) Submit ¶
func (a *App) Submit(ctx context.Context, repo git.Repo, o SubmitOptions) (SubmitResult, error)
Submit pushes the current stack and creates or updates its pull requests.
func (*App) Sync ¶
func (a *App) Sync(ctx context.Context, repo git.Repo, o SyncOptions) (SyncResult, error)
Sync fetches, updates trunk, restacks and pushes every stack, the way `gt sync` does: the one you are on first, then every other stack whether it is checked out or not and whichever worktree holds it. gh stack syncs the stack of the branch checked out where it runs and only knows the stacks in that worktree's metadata, so a stack that is not checked out gets one of its branches checked out in its home worktree for the duration and the previous branch restored afterwards. Merged branches are deleted according to stack.sync.prune.
type CommitInfo ¶
CommitInfo identifies a commit for output.
type CreateOptions ¶
type CreateOptions struct {
// Name is the explicit branch name (used as-is, no prefix).
Name string
// Message paragraphs for the commit; empty opens the editor when
// something is staged.
Message []string
Staging StagingMode
// Insert is accepted for parity but unsupported by the gh-stack backend.
Insert bool
// UseAI drafts the branch name (and the message when none is given).
UseAI bool
NoVerify bool
}
CreateOptions mirrors `gt create`.
type CreateResult ¶
type CreateResult struct {
Branch string `json:"branch"`
Parent string `json:"parent"`
Commit *CommitInfo `json:"commit,omitempty"`
// NewStack is true when the branch started a new stack on trunk.
NewStack bool `json:"newStack"`
}
CreateResult reports what happened.
type Deps ¶
type Deps struct {
Git *git.Client
Meta stack.Metadata
Tracker stack.Tracker
Restack stack.Restacker
Submit stack.Submitter
Sync stack.Syncer
Forge forge.Forge
AI ai.Drafter
Cache *cache.Store
Config *config.Config
Log *slog.Logger
Prompter Prompter
// Progress, when set, wraps slow operations (backend calls, AI calls) so
// the CLI can show a headline and spinner. It must run fn and return its
// error. The phase says what kind of work it is; the message is the
// headline without decoration ("Submitting stack").
Progress func(ctx context.Context, phase Phase, message string, fn func(ctx context.Context) error) error
}
Deps are the ports an App needs. Optional ports may be nil; the use cases that need them return KindUnsupported / KindNotInstalled errors.
type ModifyOptions ¶
type ModifyOptions struct {
// NewCommit creates a commit instead of amending (-c).
NewCommit bool
Staging StagingMode
Message []string
// Edit opens the editor when amending (-e); ignored with NewCommit.
Edit bool
ResetAuthor bool
NoVerify bool
// Continue / Abort resume or abandon an interrupted restack.
Continue bool
Abort bool
}
ModifyOptions mirrors `gt modify`.
type ModifyResult ¶
type ModifyResult struct {
Branch string `json:"branch"`
Commit CommitInfo `json:"commit"`
// Amended is false when a new commit was created.
Amended bool `json:"amended"`
// ForcedNewCommit is true when the branch had no commits of its own, so
// amending would have rewritten the parent's commit.
ForcedNewCommit bool `json:"forcedNewCommit"`
// Restacked lists the branches above that were rebased.
Restacked []string `json:"restacked"`
}
ModifyResult reports what happened.
type PRSnapshot ¶
type PRSnapshot struct {
PRs []forge.PullRequest `json:"prs"`
}
PRSnapshot is the cached forge state.
type Phase ¶
type Phase string
Phase names a kind of long running work. The CLI decorates each phase the same way every time (see docs/style.md); use cases only pick the phase.
type Prompter ¶
type Prompter interface {
Confirm(question string, defaultYes bool) (bool, error)
Select(question string, options []string) (int, error)
}
Prompter asks the user a question. It is nil under --no-interactive and in the MCP server, in which case use cases must fall back to a default or return KindInteractionRequired.
type RestackOptions ¶
RestackOptions mirrors `gt restack`.
type RestackResult ¶
type RestackResult struct {
Scope stack.Scope `json:"scope"`
// Branches that the scope covered, bottom to top.
Branches []string `json:"branches"`
// BottomBehindTrunk is true when the stack's bottom branch does not
// contain the local trunk tip: the local-only restack never rebases
// onto trunk, so `git stack sync` is needed for that.
BottomBehindTrunk bool `json:"bottomBehindTrunk"`
Trunk string `json:"trunk"`
Bottom string `json:"bottom"`
}
RestackResult reports what was rebased.
type Row ¶
type Row struct {
Name string
// Depth is 0 for a trunk, 1 for a bottom branch, and so on.
Depth int
// Parent is the branch below (empty for trunks and untracked branches).
Parent string
IsTrunk bool
IsCurrent bool
// Tracked is false for branches that are in no stack.
Tracked bool
// NeedsRestack is true when the parent's tip is not in the branch's
// history.
NeedsRestack bool
Head string
LastCommit time.Time
// Worktree is the path of another worktree the branch is checked out in.
Worktree string
// PR is the known pull request, if any. State is StateUnknown until the
// forge has been consulted.
PR *forge.PullRequest
// StackIndex identifies the stack within View.Graph (-1 for trunks and
// untracked branches).
StackIndex int
}
Row is one line of the stack tree, in display order.
type StagingMode ¶
type StagingMode int
StagingMode mirrors Graphite's -a / -u / -p flags.
const ( StageNone StagingMode = iota StageAll StageUpdate StagePatch )
type SubmitOptions ¶
type SubmitOptions struct {
// Draft / Publish force the state of new PRs. With neither, the
// configured default applies (ask interactively, else draft).
Draft bool
Publish bool
// NoEdit skips the backend's interactive PR editor.
NoEdit bool
// DryRun reports what would happen without pushing.
DryRun bool
// UseAI drafts title and body for every new PR.
UseAI bool
// Texts supplies title/body per branch (the MCP path). Branches without
// a PR need an entry unless UseAI is set or the editor can open.
Texts map[string]PRText
// UpdateOnly is accepted for parity but unsupported by gh stack.
UpdateOnly bool
}
SubmitOptions mirrors `gt submit`.
type SubmitResult ¶
type SubmitResult struct {
Stack []string `json:"stack"`
PullRequests []SubmittedPR `json:"pullRequests"`
Draft bool `json:"draft"`
DryRun bool `json:"dryRun"`
// Output is the backend's own output (captured runs only).
Output string `json:"output,omitempty"`
Notices []string `json:"notices,omitempty"`
}
SubmitResult reports the outcome.
type SubmittedPR ¶
type SubmittedPR struct {
Branch string `json:"branch"`
Number int `json:"number,omitempty"`
URL string `json:"url,omitempty"`
State forge.State `json:"state,omitempty"`
Created bool `json:"created"`
// WouldCreate is set in dry runs for branches without a PR.
WouldCreate bool `json:"wouldCreate,omitempty"`
// TextUpdated is true when a supplied or drafted title/body was applied.
TextUpdated bool `json:"textUpdated,omitempty"`
}
SubmittedPR is one line of the result.
type SyncOptions ¶
type SyncOptions struct {
// Prune deletes merged branches whatever stack.sync.prune says (gt -f).
Prune bool
// All is accepted for gt parity; every stack is synced anyway.
All bool
}
SyncOptions mirrors `gt sync`.
type SyncResult ¶
type SyncResult struct {
Output string `json:"output,omitempty"`
Notices []string `json:"notices,omitempty"`
// Aborted is true when any stack's sync was refused.
Aborted bool `json:"aborted"`
// Pruned is true when merged branches were deleted (by policy, flag or
// confirmation at the prompt).
Pruned bool `json:"pruned"`
// Stacks lists what was synced, the current stack first.
Stacks []SyncedStack `json:"stacks"`
}
SyncResult reports the outcome.
type SyncedStack ¶ added in v0.1.1
type SyncedStack struct {
// Branch is the branch gh stack ran from (identifies the stack).
Branch string `json:"branch"`
// Worktree is where it ran: the worktree holding the stack's metadata.
Worktree string `json:"worktree"`
// CheckedOut is true when Branch had to be checked out in that worktree
// for the sync (and the previous branch restored afterwards).
CheckedOut bool `json:"checkedOut,omitempty"`
// Aborted is true when gh stack refused to sync (the remote stack
// diverged) without changing anything.
Aborted bool `json:"aborted"`
}
SyncedStack is one stack that was synced.
type View ¶
type View struct {
Repo git.Repo
Current string
Graph *stack.Graph
// Rows lists trunks and their stacks in display order, then untracked
// branches when requested.
Rows []Row
}
View is the rendered state of the repository's stacks.
func (*View) ApplyPRs ¶
func (v *View) ApplyPRs(prs []forge.PullRequest)
ApplyPRs decorates rows with forge state. Rows whose branch has no PR in prs keep the backend snapshot, if any.
type ViewOptions ¶
type ViewOptions struct {
// CurrentStackOnly limits rows to the stack of the current branch (and
// its trunk).
CurrentStackOnly bool
// IncludeUntracked adds local branches that are in no stack.
IncludeUntracked bool
// SkipRestackCheck avoids the per-branch ancestry check (completion).
SkipRestackCheck bool
// PRs selects how pull-request state is obtained (default: none).
PRs PRMode
}
ViewOptions controls View.