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 RemoteURL(ctx context.Context, dir, remote string) (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 RefResult
- type Remote
- type Result
- type WaitAssetsOptions
- type WaitAssetsResult
- type WaitCIOptions
- type WaitCIResult
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") // ErrIndexLocked: the main checkout's .git/index.lock is still held once the wait // elapsed. The lock is NEVER deleted — another git process owns it. ErrIndexLocked = errors.New("git index.lock is still held") )
Merge errors (typed so callers map them to 409).
var StepPollFloor = time.Second
StepPollFloor is the shortest interval between two platform polls. A package variable so tests can shorten it; the step's own interval comes from its `with` block.
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, and uncommitted .gofer/tracker/ changes survive the undo. 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 RemoteURL ¶ added in v0.181.0
RemoteURL is the URL a remote points at (`git remote get-url`), for parsing the platform and repository out of it. An empty remote means origin.
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 RefResult ¶ added in v0.181.0
type RefResult struct {
Ref string `json:"ref"`
Kind string `json:"kind"` // branch | tag
Remote string `json:"remote"`
SHA string `json:"sha"`
}
RefResult is one ref pushed and verified against the remote.
func PushRefs ¶ added in v0.181.0
func PushRefs(ctx context.Context, dir, remote string, refs []string, proxy string) ([]RefResult, error)
PushRefs pushes every ref to remote and verifies the remote now holds the same sha. A name that resolves to a local branch is pushed to refs/heads/<name>, a local tag to refs/tags/<name>. Nothing is ever forced: a remote ref that moved elsewhere makes git reject the push and the rejection is returned as-is. After the push every ref is read back with `git ls-remote`, so a "successful" push that did not land (a hook, a mirror) is a failure here rather than a silently wrong release.
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.
type WaitAssetsOptions ¶ added in v0.181.0
type WaitAssetsOptions struct {
Tag string
Assets []string // globs of asset file names
TimeoutMin int
IntervalSec int
Remote string
Env Env
}
WaitAssetsOptions is what `gofer/wait-assets` asks for.
type WaitAssetsResult ¶ added in v0.181.0
type WaitAssetsResult struct {
Provider string `json:"provider"`
Tag string `json:"tag"`
URL string `json:"url,omitempty"`
Assets []string `json:"assets"`
}
WaitAssetsResult is what the step reports.
func WaitAssets ¶ added in v0.181.0
func WaitAssets(ctx context.Context, dir string, o WaitAssetsOptions) (WaitAssetsResult, error)
WaitAssets polls the release of tag until every glob matches an uploaded asset.
type WaitCIOptions ¶ added in v0.181.0
type WaitCIOptions struct {
Ref string // branch, tag or sha whose checks to wait for
Required []string // check / workflow run names that MUST pass ("" = every check must pass)
CodeScanning bool // also fail on code scanning alerts reported for this ref
TimeoutMin int // default 40
IntervalSec int // default 20, never below StepPollFloor
Remote string // "" = origin
Env Env // HTTPBase / Lookup overrides (tests)
}
WaitCIOptions is what `gofer/wait-ci` asks for.
type WaitCIResult ¶ added in v0.181.0
type WaitCIResult struct {
Provider string `json:"provider"`
Ref string `json:"ref"`
Checks []string `json:"checks,omitempty"`
Alerts int `json:"code_scanning_alerts"`
}
WaitCIResult is what the step reports.
func WaitCI ¶ added in v0.181.0
func WaitCI(ctx context.Context, dir string, o WaitCIOptions) (WaitCIResult, error)
WaitCI polls the platform until every check of ref has finished. It fails as soon as a required check fails, and it fails with the checks still running when the timeout elapses, so the workflow log names what was waited for.