Help us shape the future of Go! Take the 2026 Go Developer Survey

submit

package
v0.30.1 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2026 License: MIT Imports: 21 Imported by: 0

Documentation

Overview

Package submit provides functionality for submitting stacked branches as pull requests.

Package submit provides functionality for submitting stacked branches as pull requests.

Package submit provides functionality for submitting stacked branches as pull requests.

Package submit provides functionality for submitting stacked branches as pull requests.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Action

func Action(ctx context.Context, deps Deps, opts Options, handler Handler) error

Action performs the submit operation with an event handler for progress feedback.

func GetPRBody

func GetPRBody(ctx context.Context, branch engine.Branch, editInline bool, existingBody string) (string, error)

GetPRBody gets the PR body, prompting if needed

func GetPRTitle

func GetPRTitle(ctx context.Context, prompter handler.TextInputPrompter, branch engine.Branch, editInline bool, existingTitle string, scope engine.Scope) (string, error)

GetPRTitle gets the PR title, prompting if needed

func GetReviewers

func GetReviewers(reviewersFlag string) ([]string, []string, error)

GetReviewers gets reviewers from flag or prompts user

func GetReviewersWithPrompt

func GetReviewersWithPrompt(prompter handler.TextInputPrompter, reviewersFlag string) ([]string, []string, error)

GetReviewersWithPrompt gets reviewers, prompting if flag is empty

func ValidateBranchesToSubmit

func ValidateBranchesToSubmit(ctx context.Context, deps Deps, branches []string) ([]string, error)

ValidateBranchesToSubmit validates that branches are ready to submit and returns the submittable subset. Branches that are not restacked on their in-submission parent (or whose base no longer matches an out-of-submission parent remotely) are pruned together with their descendants, with a warning per pruned subtree, so the rest of the stack still submits. An error is returned only when nothing in scope is submittable.

Types

type BranchInfo

type BranchInfo struct {
	Name     string
	Action   engine.SubmitAction
	PRNumber *git.PRNumber
}

BranchInfo contains information about a branch for submission tracking.

type BranchPlanEvent

type BranchPlanEvent struct {
	Regenerated *PRContentPreview // present for regeneration dry runs
	BranchName  string
	Action      engine.SubmitAction
	PRNumber    *git.PRNumber // existing PR number for updates, nil for creates
	IsCurrent   bool
	Empty       bool // branch has no commits relative to its parent
	Skipped     bool
	SkipReason  string
}

BranchPlanEvent indicates what will happen to each branch.

type BranchProgressEvent

type BranchProgressEvent struct {
	BranchName string
	Status     BranchStatus
	URL        string // set on success
	Error      error  // set on failure
}

BranchProgressEvent indicates per-branch submission progress.

type BranchStatus

type BranchStatus string

BranchStatus represents the status of a branch during submission.

const (
	StatusPending    BranchStatus = "pending"
	StatusSubmitting BranchStatus = "submitting"
	StatusSyncing    BranchStatus = "syncing"
	StatusDone       BranchStatus = "done"
	StatusError      BranchStatus = "error"
	StatusSkipped    BranchStatus = "skipped"
)

BranchStatus values for tracking submission progress.

type BranchWarningEvent added in v0.22.0

type BranchWarningEvent struct {
	BranchName string
	Warning    string
}

BranchWarningEvent surfaces a non-fatal warning raised while submitting a branch (e.g. labels or reviewers could not be applied). Warnings must flow through the handler rather than direct console output: the interactive runner quiets the console while the TUI is active, so direct writes during the submission phase are silently dropped.

type ChannelHandler

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

ChannelHandler is a Handler that sends events to a channel. Useful for async consumers like the dashboard.

func NewChannelHandler

func NewChannelHandler(bufferSize int) *ChannelHandler

NewChannelHandler creates a new ChannelHandler with a buffered channel.

func (*ChannelHandler) Close

func (h *ChannelHandler) Close()

Close closes the event channel. Should be called when the action is complete.

func (*ChannelHandler) Confirm

func (h *ChannelHandler) Confirm(_ string, defaultYes bool) (bool, error)

Confirm auto-confirms with the default value. Dashboard operations don't support interactive confirmation.

func (*ChannelHandler) Events

func (h *ChannelHandler) Events() <-chan Event

Events returns the event channel for reading.

func (*ChannelHandler) IsInteractive

func (h *ChannelHandler) IsInteractive() bool

IsInteractive returns false - dashboard/channel handlers are not interactive.

func (*ChannelHandler) OnEvent

func (h *ChannelHandler) OnEvent(e Event)

OnEvent sends the event to the channel. Non-blocking: if the channel is full, the event is dropped.

type CompletionEvent

type CompletionEvent struct {
	Outcome  CompletionOutcome
	Message  string        // human-readable detail, e.g. "All PRs up to date"
	Duration time.Duration // elapsed run time; set when branches were submitted
}

CompletionEvent indicates the action has finished.

func (CompletionEvent) Success

func (e CompletionEvent) Success() bool

Success reports whether the run ended without failure or cancellation.

type CompletionOutcome added in v0.22.0

type CompletionOutcome string

CompletionOutcome classifies how a submit run ended, so handlers can decide presentation without string-matching messages.

const (
	OutcomeComplete        CompletionOutcome = "complete"          // branches were submitted
	OutcomeUpToDate        CompletionOutcome = "up-to-date"        // nothing needed submitting
	OutcomeDryRun          CompletionOutcome = "dry-run"           // plan reported, nothing submitted
	OutcomeCanceled        CompletionOutcome = "canceled"          // user declined a confirmation
	OutcomeNothingToSubmit CompletionOutcome = "nothing-to-submit" // no branches in scope / untracked
	OutcomeOnTrunk         CompletionOutcome = "on-trunk"          // checked out on trunk; nothing to submit from here
	OutcomeFailed          CompletionOutcome = "failed"            // at least one branch failed
)

CompletionOutcome values.

type Config added in v0.30.1

type Config interface {
	GitHubStack() bool
	LinearStacks() bool
}

Config lists the configuration getters submit reads. A nil Config behaves as if no configuration was loaded.

type Deps added in v0.30.1

type Deps struct {
	Engine Engine
	Out    output.Output
	Log    output.Logger
	// GitHub returns the client, or nil when GitHub is unavailable. It is a
	// function so the client is only built when submit actually needs it.
	GitHub func() github.Client
	// GitHubError explains why GitHub returned nil, when known. May be nil.
	GitHubError func() error
	// GHRunner runs the GraphQL queries that sync PR info before validation.
	GHRunner github.GitCommandRunner
	// PRSync refreshes PR footers and titles after the submission phase.
	PRSync actions.PRSync
	// Restack is what --restack runs actions.RunRestack with.
	Restack   actions.RestackDeps
	Snapshots actions.Snapshots
	Prompts   handler.Prompter
	// Verify reflects the global --verify flag; false skips push hooks.
	Verify bool
	Config Config
}

Deps are the collaborators submit needs. Adapters build them from their own runtime state; the action never sees bootstrap types.

type Engine added in v0.30.1

type Engine interface {
	engine.BranchReader
	actions.MetadataPushEngine
	TrackBranch(ctx context.Context, branchName string, parentBranchName string) error
	ListManagedWorktrees(ctx context.Context) ([]engine.WorktreeInfo, error)
	GetStackRootForBranch(branch engine.Branch) string
	MarkBranchesSubmitPending(ctx context.Context, branchNames []string) error
	ClearBranchesSubmitPending(ctx context.Context, branchNames []string) error
	PushBranches(ctx context.Context, remote string, specs []git.PushSpec, opts git.PushOptions) git.PushResults
	UpsertPrInfo(ctx context.Context, branch engine.Branch, prInfo *engine.PrInfo) error
	BatchUpsertPrInfo(ctx context.Context, updates map[string]*engine.PrInfo) error
	GetStackIDsForBranches(branches engine.Branches) []string
	PushStackMetadata(ctx context.Context, stackIDs []string) error
}

Engine lists exactly the engine methods submit calls beyond the read-only branch surface: tracking an untracked target, the managed-worktree lookup for display, the pending-submit marker, branch and metadata pushes, and the PR-info writes.

type Event

type Event interface {
	// contains filtered or unexported methods
}

Event represents a feedback event from the submit action. Implementations should use type switches to handle specific event types.

type GitHubStackSkippedEvent added in v0.26.0

type GitHubStackSkippedEvent struct {
	Reason string
}

GitHubStackSkippedEvent reports that native GitHub Stack sync was enabled by config but did not run, either because the submitted branches are ineligible or because the Stacks API call failed. Configured sync is best-effort so the submit still succeeds; the explicit --with-native-stack flag fails instead.

type GitHubStackSyncedEvent added in v0.26.0

type GitHubStackSyncedEvent struct {
	Number       github.StackNumber
	PullRequests []git.PRNumber
	Action       github.StackSyncAction
}

GitHubStackSyncedEvent reports that submit reconciled GitHub's native Stack metadata after every PR in the selected chain was submitted.

type Handler

type Handler interface {
	// OnEvent is called for each event during submission.
	// Handlers should use type switches to handle specific event types.
	OnEvent(event Event)

	// Confirm prompts for user confirmation when the --confirm flag is used.
	// Returns (confirmed, error).
	// Non-interactive handlers should return (defaultYes, nil).
	Confirm(message string, defaultYes bool) (bool, error)

	// IsInteractive returns true if the handler supports interactive prompts.
	// Used to determine whether to prompt for actions like tracking untracked branches.
	IsInteractive() bool
}

Handler receives events from the submit action and handles user interaction. Implementations should handle events appropriately for their UI context (interactive terminal, non-interactive, dashboard, etc.)

type Info

type Info struct {
	BranchName string
	Head       string
	Base       string
	HeadSHA    string
	BaseSHA    string
	Action     engine.SubmitAction
	PRNumber   *git.PRNumber
	Metadata   *PRMetadata
}

Info contains information about a branch to submit

type JSONBranchResult added in v0.22.0

type JSONBranchResult struct {
	Branch      string            `json:"branch"`
	Action      string            `json:"action,omitempty"` // "create" or "update"
	Status      string            `json:"status"`           // pending, done, error, skipped
	PR          *git.PRNumber     `json:"pr,omitempty"`
	URL         string            `json:"url,omitempty"`
	SkipReason  string            `json:"skip_reason,omitempty"`
	Error       string            `json:"error,omitempty"`
	Warnings    []string          `json:"warnings,omitempty"`
	Regenerated *PRContentPreview `json:"regenerated,omitempty"`
}

JSONBranchResult is one branch's plan and result in submit JSON output.

type JSONGitHubStackResult added in v0.26.0

type JSONGitHubStackResult struct {
	Number       github.StackNumber `json:"number"`
	PullRequests []git.PRNumber     `json:"pull_requests"`
	Action       string             `json:"action"`
}

JSONGitHubStackResult identifies native GitHub Stack metadata reconciled by submit.

type JSONHandler added in v0.22.0

type JSONHandler struct {
	Result *JSONResult
	// contains filtered or unexported fields
}

JSONHandler collects submit events into a JSONResult.

func NewJSONHandler added in v0.22.0

func NewJSONHandler() *JSONHandler

NewJSONHandler creates a handler that collects submit results as JSON data.

func (*JSONHandler) Confirm added in v0.22.0

func (h *JSONHandler) Confirm(_ string, defaultYes bool) (bool, error)

Confirm auto-confirms with the default value — JSON output is non-interactive.

func (*JSONHandler) IsInteractive added in v0.22.0

func (h *JSONHandler) IsInteractive() bool

IsInteractive returns false — JSON handlers never prompt.

func (*JSONHandler) OnEvent added in v0.22.0

func (h *JSONHandler) OnEvent(e Event)

OnEvent implements Handler.

func (*JSONHandler) SetError added in v0.22.0

func (h *JSONHandler) SetError(err error)

SetError records a run-level error on the result.

type JSONResult added in v0.22.0

type JSONResult struct {
	Outcome  CompletionOutcome  `json:"outcome"`
	Message  string             `json:"message,omitempty"`
	Error    string             `json:"error,omitempty"`
	Branches []JSONBranchResult `json:"branches"`
	// GitHubStacks contains every native GitHub Stack reconciled during submit.
	GitHubStacks []JSONGitHubStackResult `json:"github_stacks,omitempty"`
	// GitHubStackSkips contains every reason configured native Stack sync skipped
	// an otherwise submitted component.
	GitHubStackSkips []string `json:"github_stack_skips,omitempty"`
	// GitHubStack is retained for backwards compatibility when exactly one
	// native Stack was reconciled. Use GitHubStacks for new consumers.
	GitHubStack *JSONGitHubStackResult `json:"github_stack,omitempty"`
	// GitHubStackSkipped is retained for backwards compatibility when exactly
	// one component was skipped. Use GitHubStackSkips for new consumers.
	GitHubStackSkipped string `json:"github_stack_skipped,omitempty"`
}

JSONResult is the machine-readable summary of a submit run.

type MetadataOptions

type MetadataOptions struct {
	Text PRTextSource
	// EditTitle and EditBody are the resolved per-field prompt decisions.
	EditTitle       bool
	EditBody        bool
	Draft           bool
	Publish         bool
	Reviewers       string
	ReviewersPrompt bool
	// Config-driven options
	ConfigDraft     bool     // Default draft mode from config (used for new PRs)
	ConfigReviewers []string // Default reviewers from config
	ConfigLabels    []string // Default labels from config
	ConfigAssignees []string // Default assignees from config
}

MetadataOptions contains options for PR metadata collection

type Options

type Options struct {
	Branch               string
	StackRange           engine.StackRange
	Force                bool
	DryRun               bool
	Confirm              bool
	UpdateOnly           bool
	Always               bool
	Text                 PRTextSource
	Restack              bool
	Draft                bool
	Publish              bool
	Edit                 bool
	EditTitle            bool
	EditDescription      bool
	NoEdit               bool
	NoEditTitle          bool
	NoEditDescription    bool
	Reviewers            string
	TeamReviewers        string
	MergeWhenReady       bool
	RerequestReview      bool
	View                 bool
	Web                  bool
	Comment              string
	TargetTrunk          string
	IgnoreOutOfSyncTrunk bool
	SubmitFooter         bool // Whether to include PR footer (from config)
	NoLabels             bool // Skip applying default labels from config
	NoAssignees          bool // Skip applying default assignees from config
	CreateGitHubStack    bool // Create native GitHub Stack metadata after submitting PRs

	// Config-driven options (these are merged with flags)
	ConfigDraft       bool     // Default draft mode from config
	ConfigGitHubStack bool     // Sync native GitHub Stack metadata for eligible submits
	ConfigWeb         string   // When to open browser from config (always/created/never)
	ConfigLabels      []string // Default labels from config
	ConfigReviewers   []string // Default reviewers from config
	ConfigAssignees   []string // Default assignees from config
}

type PRContentPreview added in v0.29.0

type PRContentPreview struct {
	Title string `json:"title"`
	Body  string `json:"body"`
}

PRContentPreview is the replacement text proposed by submit --regenerate. Generated stack sections are added by the normal footer synchronization.

type PRMetadata

type PRMetadata struct {
	Title         string
	Body          string
	IsDraft       bool
	Reviewers     []string
	TeamReviewers []string
	Labels        []string // Labels to apply to the PR
	Assignees     []string // Assignees to apply to the PR
}

PRMetadata contains PR metadata

func PreparePRMetadata

func PreparePRMetadata(ctx context.Context, deps Deps, branch engine.Branch, opts MetadataOptions, current map[git.PRNumber]github.PRContent) (*PRMetadata, error)

PreparePRMetadata prepares PR metadata for a branch. current holds PR content prefetched in bulk; a PR missing from it (or a nil map) is fetched directly.

type PRTextSource added in v0.29.0

type PRTextSource int

Options contains options for the submit command PRTextSource says where submit takes PR titles and descriptions from.

const (
	// PRTextExisting keeps each PR's existing text, generating only what is missing.
	PRTextExisting PRTextSource = iota
	// PRTextRegenerate rebuilds text from current commits, replacing what exists.
	PRTextRegenerate
)

type PlanningCompleteEvent added in v0.22.0

type PlanningCompleteEvent struct{}

PlanningCompleteEvent indicates that all BranchPlanEvents have been emitted. Handlers that buffer plan rows can render the complete plan before any confirmation prompt or submission starts.

type PreparingEvent

type PreparingEvent struct{}

PreparingEvent indicates the preparation/validation phase has started.

type RestackBranchEvent added in v0.30.1

type RestackBranchEvent struct {
	actions.RestackBranchEvent
}

RestackBranchEvent reports the outcome of restacking one branch before submit. It carries the same event every restacking command reports.

type RestackEvent

type RestackEvent struct {
	Started   bool
	Completed bool
	Summary   actions.RestackSummary
}

RestackEvent indicates restack phase status. Summary is set on completion.

type StackDisplayEvent

type StackDisplayEvent struct {
	Stack StackSnapshot
}

StackDisplayEvent indicates the initial stack visualization phase. Handlers can use this to display the branches that will be processed.

type StackSnapshot added in v0.22.0

type StackSnapshot struct {
	Branches      []string                       // branches in the stack, in order
	CurrentBranch string                         // currently checked out branch
	TrunkBranch   string                         // trunk/main branch name
	ParentMap     map[string]string              // branch -> parent
	FixedMap      map[string]bool                // branch -> is fixed (doesn't need restack)
	ScopeMap      map[string]string              // branch -> scope
	WorktreeMap   map[string]engine.WorktreePath // branch -> worktree path (for stack roots with managed worktrees)
}

StackSnapshot contains the branch relationships and metadata needed to render the stack being submitted. This is action-layer data; adapters decide how to visualize it.

type SubmissionStartEvent

type SubmissionStartEvent struct {
	Branches []BranchInfo
}

SubmissionStartEvent indicates the submission phase is beginning.

Jump to

Keyboard shortcuts

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