Documentation
¶
Overview ¶
Package delivery hands a worktree job's branch over (GIT-02, design 2026-10-12-delivery-and-cost-estimate-design.md): merge it into the base branch, push it to a remote, or push it and open a pull / merge request on GitHub, GitLab or Gitea / Forgejo. It runs on the machine that owns the worktree — the server for a local job, the worker (through an internal exec job) otherwise — from a self-contained Plan, and never force-pushes.
Index ¶
- Constants
- Variables
- func BaseBranch(ctx context.Context, wtPath string) (main, branch string, err error)
- func CompareURL(provider string, r Remote, head, base string) string
- func DetectProvider(host, override string) string
- func GitOut(ctx context.Context, dir string, args ...string) (string, error)
- func MainCheckout(ctx context.Context, wtPath string) (string, error)
- func MergeBranch(ctx context.Context, wtPath, branch string, squash bool) (main, base string, err error)
- func Push(ctx context.Context, dir, remote, src, dst, proxy string) error
- func ResolveToken(ctx context.Context, provider, override string, env Env) string
- func TokenVars(provider, override string) []string
- func ValidMode(m string) bool
- type APIError
- type Client
- type Env
- type MergeConflictError
- type PR
- type PRRequest
- type Plan
- type Remote
- type Result
Constants ¶
const ( ModeNone = "none" ModeMerge = "merge" ModePush = "push" ModePR = "pr" )
Modes.
const ( StatePending = "pending" StateMerged = "merged" StatePushed = "pushed" StatePROpened = "pr_opened" StateFailed = "failed" StateSkipped = "skipped" )
States of a delivery.
const ( ProviderAuto = "auto" ProviderGitHub = "github" ProviderGitLab = "gitlab" ProviderGitea = "gitea" // Gitea and Forgejo share the API )
Providers.
Variables ¶
var ( ErrMergeConflict = errors.New("worktree merge has conflicts") ErrMainNotReady = errors.New("main checkout is not ready for a merge") )
Merge errors (typed so callers map them to 409).
Functions ¶
func BaseBranch ¶
BaseBranch is the branch the main checkout of wtPath's repository is on — where a merge lands and the default target of a pull request.
func CompareURL ¶
CompareURL is the platform's web page for opening a request by hand ("" unknown).
func DetectProvider ¶
DetectProvider names the platform of host: github.com and gitlab.com by name, a self-hosted instance when its host says so (gitlab.*, gitea.*, forgejo.*, codeberg.org); "" when it cannot tell (set provider explicitly).
func GitOut ¶
GitOut runs git in dir and returns its trimmed stdout; a failure carries git's stderr.
func MainCheckout ¶
MainCheckout returns the main working tree of the repository a linked worktree belongs to.
func MergeBranch ¶
func MergeBranch(ctx context.Context, wtPath, branch string, squash bool) (main, base string, err error)
MergeBranch merges branch (checked out in the worktree wtPath) into its repository's main checkout: --no-ff with a merge commit, or --squash plus one commit. The main checkout must have no tracked changes and be on a named branch; a conflict is fully undone before the typed error is returned. It returns the main checkout and the branch merged into.
func Push ¶
Push pushes local ref src to refs/heads/dst on remote — never forced: a remote branch that moved elsewhere is an error naming the rejection. A non-empty proxy overrides git's http.proxy for this push only.
func ResolveToken ¶
ResolveToken reads the platform token on this machine: the configured / default variables, else the logged-in CLI (`gh auth token`, `glab auth token`).
Types ¶
type Client ¶
type Client struct {
Provider string
Remote Remote
Token string
HTTP *http.Client
// APIBase overrides the derived API root (tests, unusual installs).
APIBase string
}
Client opens requests on one platform.
type Env ¶
type Env struct {
Lookup func(string) (string, bool)
// RunTokenCLI runs a token helper (`gh auth token`); nil = exec it.
RunTokenCLI func(ctx context.Context, name string, args ...string) (string, error)
HTTPBase string // API base override (tests)
}
Env lets the caller supply the environment and the CLI token helpers (tests).
type MergeConflictError ¶
type MergeConflictError struct {
Files []string
}
MergeConflictError reports a conflict after the main checkout has been restored.
func (*MergeConflictError) Error ¶
func (e *MergeConflictError) Error() string
func (*MergeConflictError) Unwrap ¶
func (e *MergeConflictError) Unwrap() error
type PR ¶
type PR struct {
URL string
Number int
Existed bool // an open request for the same head was found and reused
}
PR is an opened (or already open) request.
type PRRequest ¶
type PRRequest struct {
Title string
Body string
Head string // the pushed branch
Base string // target branch
Draft bool
Labels []string
}
PRRequest is what a pull / merge request is opened with.
type Plan ¶
type Plan struct {
Mode string `json:"mode"`
JobID string `json:"job_id"`
Worktree string `json:"worktree"` // the job's worktree (absolute, on the executing machine)
Branch string `json:"branch"` // the local branch (gofer/<job>)
RemoteBranch string `json:"remote_branch"` // pushed as
Remote string `json:"remote"`
Base string `json:"base,omitempty"` // "" = the main checkout's branch
AllowPush bool `json:"allow_push"`
PushBase bool `json:"push_base,omitempty"`
Squash bool `json:"squash,omitempty"`
Cleanup bool `json:"cleanup,omitempty"`
Draft bool `json:"draft,omitempty"`
Labels []string `json:"labels,omitempty"`
Provider string `json:"provider,omitempty"` // auto | github | gitlab | gitea
TokenEnv string `json:"token_env,omitempty"` // variable NAME; "" = the provider's defaults
Proxy string `json:"proxy,omitempty"` // push + API proxy; "" = git's http.proxy, then the environment
Title string `json:"title"`
Body string `json:"body"`
}
Plan is one delivery, self-contained so it can be carried to the machine that owns the worktree (an internal exec job reads it as JSON on stdin).
type Remote ¶
type Remote struct {
Host string // host[:port] of the web / API endpoint
Path string // owner/repo (GitLab: group/sub/repo), without .git
}
Remote is a parsed git remote URL.
func ParseRemote ¶
ParseRemote reads https://host/owner/repo(.git), ssh://git@host[:port]/owner/repo and scp-style git@host:owner/repo. An ssh port is dropped (the API is on https).
type Result ¶
type Result struct {
Mode string `json:"mode"`
State string `json:"state"`
Branch string `json:"branch,omitempty"`
Remote string `json:"remote,omitempty"`
Base string `json:"base,omitempty"`
Provider string `json:"provider,omitempty"`
PRURL string `json:"pr_url,omitempty"`
PRNumber int `json:"pr_number,omitempty"`
CompareURL string `json:"compare_url,omitempty"`
Note string `json:"note,omitempty"`
Error string `json:"error,omitempty"`
At int64 `json:"at"`
}
Result is what a delivery did.