submit

package
v0.24.2 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2026 License: GPL-3.0 Imports: 26 Imported by: 0

Documentation

Overview

Package submit implements change submission handling. This is used by the various 'submit' commands in the CLI.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BatchOptions added in v0.17.0

type BatchOptions struct {
	UpdateOnlyDefault bool `config:"submit.updateOnly" help:"Default value for --update-only in batch submit operations." hidden:"" default:"false"`
}

BatchOptions defines options that are only available to batch submit operations.

type BatchRequest

type BatchRequest struct {
	Branches     []string // required
	Options      *Options
	BatchOptions *BatchOptions // required
}

BatchRequest is a request to submit one or more change requests.

type GitRepository

type GitRepository interface {
	PeelToCommit(ctx context.Context, ref string) (git.Hash, error)
	PeelToTree(ctx context.Context, ref string) (git.Hash, error)
	BranchUpstream(ctx context.Context, branch string) (string, error)
	SetBranchUpstream(ctx context.Context, branch string, upstream string) error
	Var(ctx context.Context, name string) (string, error)
	CommitMessageRange(ctx context.Context, start string, stop string) ([]git.CommitMessage, error)
	RemoteFetchRefspecs(ctx context.Context, remote string) ([]git.Refspec, error)
}

GitRepository is a subset of the git.Repository interface that is used by the submit handler.

type GitWorktree

type GitWorktree interface {
	Push(ctx context.Context, opts git.PushOptions) error
}

GitWorktree is a subset of the git.Worktree interface that is used by the submit handler.

type Handler

type Handler struct {
	Log        *silog.Logger    // required
	View       ui.View          // required
	Repository GitRepository    // required
	Worktree   GitWorktree      // required
	Store      Store            // required
	Service    Service          // required
	Browser    browser.Launcher // required

	// TODO: these should not be a func reference
	// this whole memoize thing is a bit of a hack
	FindRemote           func(ctx context.Context) (string, error)                          // required
	OpenRemoteRepository func(ctx context.Context, remote string) (forge.Repository, error) // required
	// contains filtered or unexported fields
}

Handler implements support for submission of change requests.

func (*Handler) Remote

func (h *Handler) Remote(ctx context.Context) (string, error)

Remote returns the remote name for the current repository, memoizing the result.

func (*Handler) RemoteRepository

func (h *Handler) RemoteRepository(ctx context.Context) (forge.Repository, error)

RemoteRepository returns the remote repository for the current repository, memoizing the result.

func (*Handler) Submit

func (h *Handler) Submit(ctx context.Context, req *Request) error

Submit submits a single branch to a remote repository, creating or updating a change request as needed.

func (*Handler) SubmitBatch

func (h *Handler) SubmitBatch(ctx context.Context, req *BatchRequest) error

SubmitBatch submits a batch of branches to a remote repository, creating or updating change requests as needed.

type NavCommentDownstack int

NavCommentDownstack specifies which downstack CRs to include in navigation comments.

const (
	// NavCommentDownstackAll includes all downstack CRs
	// (both open and merged).
	//
	// This is the default.
	NavCommentDownstackAll NavCommentDownstack = iota

	// NavCommentDownstackOpen includes only open downstack CRs,
	// excluding merged ones.
	NavCommentDownstackOpen
)
func (d NavCommentDownstack) String() string

String returns the string representation of the NavCommentDownstack.

func (d *NavCommentDownstack) UnmarshalText(bs []byte) error

UnmarshalText decodes NavCommentDownstack from text.

type NavCommentSync int

NavCommentSync specifies the scope of navigation comment updates.

const (
	// NavCommentSyncBranch updates navigation comments
	// only for branches that are being submitted.
	//
	// This is the default.
	NavCommentSyncBranch NavCommentSync = iota

	// NavCommentSyncDownstack updates navigation comments
	// for all submitted branches and their downstack branches.
	NavCommentSyncDownstack
)
func (s NavCommentSync) String() string

String returns the string representation of the NavCommentSync.

func (s *NavCommentSync) UnmarshalText(bs []byte) error

UnmarshalText decodes a NavCommentSync from text. It supports "branch" and "downstack" values.

type NavCommentWhen int

NavCommentWhen specifies when a navigation comment should be posted (or updated if it already exists).

const (
	// NavCommentAlways always posts a navigation comment.
	// This is the default.
	NavCommentAlways NavCommentWhen = iota

	// NavCommentNever disables posting navigation comments.
	// If an existing comment is found, it is left as is.
	NavCommentNever

	// NavCommentOnMultiple posts a navigation comment
	// only if there are multiple branches in the stack
	// that the current branch is part of.
	NavCommentOnMultiple
)
func (f NavCommentWhen) String() string
func (f *NavCommentWhen) UnmarshalText(bs []byte) error

UnmarshalText decodes a NavCommentWhen from text. It supports "true", "false", and "multiple" values.

type OpenWeb

type OpenWeb int

OpenWeb defines options for the --web flag.

const (
	// OpenWebNever indicates that CRs should not be opened in a browser.
	OpenWebNever OpenWeb = iota

	// OpenWebAlways indicates that CRs should always be opened in a browser.
	OpenWebAlways

	// OpenWebOnCreate indicates that CRs should be opened in a browser
	// only when they are first created.
	OpenWebOnCreate
)

func (*OpenWeb) Decode

func (w *OpenWeb) Decode(ctx *kong.DecodeContext) error

Decode decodes CLI flags for OpenWeb. The following forms are supported:

--web=[true|false|created]
--web  // equivalent to --web=true

func (OpenWeb) IsBool

func (w OpenWeb) IsBool() bool

IsBool returns true to indicate that OpenWeb is a boolean flag. This is needed for Kong to render its help correctly.

type Options

type Options struct {
	DryRun bool `short:"n" help:"Don't actually submit the stack"`
	Fill   bool `short:"c" help:"Fill in the change title and body from the commit messages"`
	// TODO: Default to Fill if --no-prompt?
	Draft   *bool   `negatable:"" help:"Whether to mark change requests as drafts"`
	Publish bool    `` /* 134-byte string literal not displayed */
	Web     OpenWeb `` /* 135-byte string literal not displayed */

	NavComment          NavCommentWhen      `` /* 199-byte string literal not displayed */
	NavCommentSync      NavCommentSync      `` /* 188-byte string literal not displayed */
	NavCommentDownstack NavCommentDownstack `` /* 201-byte string literal not displayed */
	NavCommentMarker    string              `` /* 168-byte string literal not displayed */

	Force      bool  `help:"Force push, bypassing safety checks"`
	NoVerify   bool  `help:"Bypass pre-push hooks when pushing to the remote." released:"v0.15.0"`
	UpdateOnly *bool `short:"u" negatable:"" help:"Only update existing change requests, do not create new ones"`

	// DraftDefault is used to set the default draft value
	// when creating new Change Requests.
	//
	// --draft/--no-draft will override this value.
	DraftDefault bool `config:"submit.draft" help:"Default value for --draft when creating change requests." hidden:"" default:"false"`

	Labels           []string `name:"label" short:"l" help:"Add labels to the change request. Pass multiple times or separate with commas."`
	ConfiguredLabels []string `name:"configured-labels" help:"Default labels to add to change requests." hidden:"" config:"submit.label"` // merged with Labels

	Reviewers           []string         `` /* 133-byte string literal not displayed */
	ConfiguredReviewers []string         `` /* 134-byte string literal not displayed */
	ReviewersAddWhen    ReviewersAddWhen `` /* 146-byte string literal not displayed */

	Assignees           []string `` /* 159-byte string literal not displayed */
	ConfiguredAssignees []string `` // merged with Assignees
	/* 134-byte string literal not displayed */

	// ListTemplatesTimeout controls the timeout for listing CR templates.
	ListTemplatesTimeout time.Duration `hidden:"" config:"submit.listTemplatesTimeout" help:"Timeout for listing CR templates" default:"1s"`

	// Template specifies the template to use when multiple templates are available.
	// If set, this template will be automatically selected instead of prompting the user.
	// The value should match the filename of one of the available templates.
	Template string `hidden:"" config:"submit.template" help:"Default template to use when multiple templates are available"`
}

Options defines options for the submit operations.

Options translate into user-facing command line flags or configuration options, so care must be taken when adding things here.

type Request

type Request struct {
	// Branch is the name of the branch to submit.
	Branch string // required

	// Title and Body are the title and body of the change request.
	Title, Body string // optional

	// Options are the options for the submit operation.
	Options *Options // optional
}

Request is a request to submit a single branch to a remote repository.

type ReviewersAddWhen added in v0.23.0

type ReviewersAddWhen int

ReviewersAddWhen specifies when configured reviewers should be added to change requests.

const (
	// ReviewersAddWhenAlways adds configured reviewers
	// to all change requests regardless of draft status.
	//
	// This is the default.
	ReviewersAddWhenAlways ReviewersAddWhen = iota

	// ReviewersAddWhenReady adds configured reviewers
	// only when the change request is not a draft.
	ReviewersAddWhenReady
)

func (ReviewersAddWhen) String added in v0.23.0

func (r ReviewersAddWhen) String() string

String returns the string representation of the ReviewersAddWhen.

func (*ReviewersAddWhen) UnmarshalText added in v0.23.0

func (r *ReviewersAddWhen) UnmarshalText(bs []byte) error

UnmarshalText decodes ReviewersAddWhen from text. It supports "always" and "ready" values.

type Service

type Service interface {
	LoadBranches(context.Context) ([]spice.LoadBranchItem, error)
	VerifyRestacked(ctx context.Context, name string) error
	LookupBranch(ctx context.Context, name string) (*spice.LookupBranchResponse, error)
	UnusedBranchName(ctx context.Context, remote string, branch string) (string, error)
	ListChangeTemplates(context.Context, string, forge.Repository) ([]*forge.ChangeTemplate, error)
}

Service provides access to the Spice service.

type Store

type Store interface {
	BeginBranchTx() *state.BranchTx
	Trunk() string

	LoadPreparedBranch(ctx context.Context, name string) (*state.PreparedBranch, error)
	SavePreparedBranch(ctx context.Context, b *state.PreparedBranch) error
	ClearPreparedBranch(ctx context.Context, name string) error
}

Store provides read/write access to the state store.

Jump to

Keyboard shortcuts

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