Documentation
¶
Overview ¶
Package landing is the landing of a branch whose preflight passed: the gate (a preflight receipt naming the branch's head), a plain push of the branch to origin, and the merge the repository's own rules allow. `abcd land` is its front door for any branch; the implement loop's land stage (internal/core/implement/loop) shares its lane-free primitives, so the receipt lookup, the bounded runner, the forge client's invocation and the ruleset mirror's reading are spelled once.
The package is transport-agnostic: it never writes to stdout. What a step did comes back as a Result for the front door to render.
Index ¶
- Constants
- Variables
- func AutoAt(r layered.Roots, repoRoot, tip, name string) bool
- func AutonomousMerging(ctx context.Context, root string) (bool, string)
- func FetchDefault(git GitFunc, dir, def string) (string, error)
- func GH(dir string, args ...string) (string, error)
- func GHContext(parent context.Context, dir string, args ...string) (string, error)
- func Landed(git GitFunc, dir, def, sha string) (tracking string, on bool, err error)
- func OneVerdictLine(text string) error
- func Receipt(repoRoot, sha string) (string, error)
- func RecordApproval(repoRoot, sha string) (string, error)
- func RecordDeltaReview(repoRoot, head, base string, returns []ReviewReturn) (string, error)
- func RecordReview(repoRoot, sha string, returns []ReviewReturn) (string, error)
- func RecordsCommitShape(repoRoot, base, head string, issues []string) (string, error)
- func ReleaseHoldForTest(root, home string) (string, error)
- func RemoteTip(git GitFunc, dir, branch string) (string, error)
- func StatesFullPair(text, head string) error
- func StillArmed(forge ForgeCall, branch string, number int) (bool, error)
- func VerdictEnds(rest string) bool
- func WithdrawArming(forge ForgeCall, n, id string, auto, queued bool) error
- type Facilitator
- type FetchError
- type ForgeCall
- type GitFunc
- type ListError
- type MergeDecision
- type MergeQuery
- type MergeRule
- type MergedListingFullError
- type MirrorError
- type Options
- type Refusal
- type Result
- type ReviewReturn
- type Step
- type Switch
Constants ¶
const ( KeyPush = "land.push" KeyEnqueue = "land.enqueue" )
The landing's configuration keys, in .abcd/config.json and ~/.abcd.noindex/config.json, each a bool whose bundled default is true.
const ( KeyFacilitatorMode = "facilitator.mode" ModeHuman = "human" ModeAuto = "auto" )
KeyFacilitatorMode declares who merges: the repository's technical facilitator is a person (ModeHuman, the bundled default) or abcd (ModeAuto). It says nothing about abcd mode's facilitator state, which is whose answer the loop is waiting on right now.
const ( // MaxDeltaFiles is how many files a delta may touch, counted once each. MaxDeltaFiles = 3 // MaxDeltaLines is how many lines a delta may change, added and removed // together, summed over the branch's own commits. MaxDeltaLines = 30 )
The bound on a delta: the most a branch's own commits may change since the base head and still rest on its full pair. It is drawn around what the records show a delta is for, a one-sentence fix to a record.
const ( RoleMaintainer = "maintainer" RoleContributor = "contributor" RoleUnverified = "unverified" )
The author's role on the repository, as the merge gate reads it.
const ( // StatusDone: the step did its act. StatusDone = "done" // StatusSkipped: the step's act was already done (a receipt names HEAD). StatusSkipped = "skipped" // StatusOff: a configuration key or a flag turned the act off. StatusOff = "off" // StatusStopped: the step cannot act yet; its note says what to do, and // running abcd land again resumes it. StatusStopped = "stopped" // StatusLeft: the act is a person's, and land leaves it to them. StatusLeft = "left" // StatusLanded: the branch's head is already on the default branch. StatusLanded = "landed" )
The statuses a step reports.
const ( // ForgeTimeout is the longest one forge client call may run. ForgeTimeout = 2 * time.Minute // MaxOutput bounds what a forge client call may write to stdout. MaxOutput = 1 << 20 )
Bounds on what the landing runs.
const ApprovalsRelDir = TierRelDir + "/approvals"
ApprovalsRelDir holds the technical facilitator's recorded approvals, one file per commit named by its full object name, beside the review receipts. The forge refuses an author's approval of their own pull request, and the facilitator authors most of the pull requests abcd opens, so their approval is also an act abcd records (`abcd land --approve`), run by a person; the shell guard refuses it to an agent.
const ArmingsQuery = `` /* 299-byte string literal not displayed */
ArmingsQuery lists the open pull requests from one head branch, with what says whether each is armed (autoMergeRequest) or queued (isInMergeQueue), who did it, and the viewer's login: the forge clears autoMergeRequest as a pull request enters the queue, so both are read. A branch's name can be shared with forks, so the listing says whether more lie past the page, and a listing that does is no answer. The committed pre-push hook asks the same question.
const FetchedReadTimeout = 15 * time.Second
FetchedReadTimeout bounds ReadFetchedFacilitator as a whole: the shell guard asks it inside a host's hook, which may give up on a slow hook and run the command anyway, so a slow origin must end the read first, as human.
const MaxReviewReturnBytes = 1 << 20
MaxReviewReturnBytes bounds one review return read for a receipt.
const PRStateQuery = `` /* 501-byte string literal not displayed */
PRStateQuery is the forge's GraphQL query for a pull request's way to the merge: `gh pr view --json` has no merge-queue field (gh 2.100.0 refuses isInMergeQueue), so the state is read through the forge's API instead.
It also reads the viewer's login (whose arming is land's own), the review decision, when and by whom the arming was made, and the head's checks with whether this pull request requires each (isRequired takes the pull request's number; with neither it nor an id the forge refuses the field). Every field is pinned in ghcontract, and testdata/ holds the forge's answers to this query.
The checks are read a page at the forge's maximum (it refuses first:101, "exceeds the `first` limit of 100 records"), with whether more follow, and each with the time it finished (completedAt; a status's createdAt), which times the toggle's grace.
const ReceiptsRelDir = TierRelDir + "/preflight-receipts"
ReceiptsRelDir is where the preflight mints its receipts, one file named by the full commit id, in any worktree of the repository (scripts/preflight-receipt.sh). A receipt is a convenience check, not a security boundary: CI re-runs every gate on the pushed commit and is the authority, and the receipt says only that a preflight passed on a tree that matched the commit.
const Remote = "origin"
Remote is the one remote a branch lands through.
const ReviewReceiptsRelDir = TierRelDir + "/review-receipts"
ReviewReceiptsRelDir holds one review receipt per commit, named by its full object name, beside the preflight receipts (spc-2610161609350616 step 3). The merge gate reads one in auto mode.
const RulesetsRelDir = ".abcd/work/rulesets"
RulesetsRelDir is the committed mirror of the default branch's rulesets.
const TierRelDir = ".abcd/.work.local"
TierRelDir is the local-ephemeral tier of a checkout, repo-relative and slash-separated: gitignored, per worktree.
Variables ¶
var ErrModeUnreadable = errors.New("facilitator.mode cannot be read")
ErrModeUnreadable wraps a facilitator.mode the gate could not read, whose text a front door masks before printing: nothing is armed.
var ErrNoDefaultBranch = errors.New("the repository has no default branch to read " + KeyFacilitatorMode + " at")
ErrNoDefaultBranch is ReadDefaultFacilitator's answer for a repository with no default branch to read facilitator.mode at: one with no commit yet, say. It is not a refusal of anything a file declares, so a caller that only shows the mode (the status line) may stay quiet over it.
var ErrNoForgeClient = errors.New("the forge client `gh` is not installed")
ErrNoForgeClient is GH's answer when the forge client is not installed.
var MergeMethods = map[string]string{"MERGE": "--merge", "SQUASH": "--squash", "REBASE": "--rebase"}
MergeMethods maps a merge queue's method to the forge client's flag.
Functions ¶
func AutoAt ¶ added in v0.16.2
AutoAt reports whether the facilitator mode the merge gate reads at tip is auto.
func AutonomousMerging ¶ added in v0.16.0
AutonomousMerging is the status line's merging element, read: it reports whether the repository's facilitator.mode is auto, read through the merge gate's own resolver (readDefaultFacilitatorContext): the default branch's committed .abcd/config.json and the machine layer, never the working tree's copy, so an auto written only in the working tree changes neither the row nor the gate. The row reads the default branch as last fetched while the gate fetches first, so after the mode changes on origin the two can differ until the next fetch. Its git questions are bounded by ctx, the row's git share, and ask the network nothing. A repository with no default branch yet says nothing and notes nothing: there is nothing to merge into. Any other failure drops the element and returns the note saying why, masked, for the front door's stderr.
It lives here rather than in core/statusline because statusline cannot import this package: landing reaches ahoy (through embargo, capture and site), and ahoy reads statusline, so the import would close a cycle. The front door hands it to statusline as statusline.MergingMode.
func FetchDefault ¶
FetchDefault fetches the default branch def from origin into its remote-tracking ref through git, and returns the ref. A refused fetch is a *FetchError.
func GH ¶
GH runs the forge client the repository already uses (`gh`) with args from dir, bounded by ForgeTimeout and MaxOutput, with no prompt and no update notice. Its environment is scrubbed as the networked git runner's is (gitutil.ScrubbedEnv): an inherited GIT_DIR or an injected GIT_CONFIG_* cannot aim the client's own git reads at another repository. Every value that comes from a record or a branch rides in its flag's own argument (--flag=value) at the caller, so none can be read as a flag of its own.
func GHContext ¶ added in v0.16.0
GHContext is GH bound to ctx as well as to ForgeTimeout: the client is killed at whichever ends first, and its output is read to EOF before it is waited for (procgroup.RunToEOF), so a client that answered is read whole however late its output closes, and a process it started that still holds that output open holds the call no further than the bound: a caller's own deadline (the away mode's stop check, which lists the forge under ten seconds) holds.
func Landed ¶
Landed fetches the default branch def and reports whether sha is on it as origin holds it (an ancestor of, or equal to, its tip): the one ancestry check by which a landing proves a head merged, the implement loop's and `abcd land`'s. A squash or rebase merge leaves no such ancestry; mergedAt is the forge's half of the proof for it. A refused fetch is a *FetchError; any other error is git unable to answer, which is not a no.
func OneVerdictLine ¶ added in v0.16.2
OneVerdictLine reports a return with more than one line opening as a Verdict, naming a line to reword: the first that is not the exact heading. The implement loop's reader and this one both ask it, since only the exact heading is read for a verdict word, and any other such line may state another.
func Receipt ¶
Receipt finds the preflight receipt for sha in any worktree git lists for the repository at repoRoot, as the pre-push hook's check does, and returns its path, or "" when none names sha. A receipt must be a regular file, never a symlink.
func RecordApproval ¶ added in v0.16.0
RecordApproval records the technical facilitator's approval of the commit sha, the full object name of a commit the repository at repoRoot holds, in that checkout's local tier, and returns the record's path. It is the act `abcd land --approve` runs for a person; nothing in abcd runs it on its own, and the shell guard refuses it to an agent.
func RecordDeltaReview ¶ added in v0.16.2
func RecordDeltaReview(repoRoot, head, base string, returns []ReviewReturn) (string, error)
RecordDeltaReview writes the review receipt for the commit head, resting on the full pair base has: a review pair as RecordReview takes one, each return also stating that it read base..head, over a delta that stands (judgeDelta). Anything short of that is refused and nothing is written. A delta never replaces a full pair already recorded for head.
func RecordReview ¶ added in v0.16.0
func RecordReview(repoRoot, sha string, returns []ReviewReturn) (string, error)
RecordReview writes the review receipt for the commit sha in the local tier of the checkout at repoRoot, once the review pair's returns pass the stop rule: at least two returns, no two the same text, each stating the commit on its first line (statesHead) and each stating a passing verdict. Anything short of that is refused, naming the return, and nothing is written. sha must be the full object name of a commit the repository holds. A return that states a delta is refused: it is a delta's (RecordDeltaReview).
func RecordsCommitShape ¶ added in v0.16.2
RecordsCommitShape says why the commits from base to head are not what a landing's records commit holds, "" when they are: every path a plain-text markdown file of mode 100644, none under a record folder spelled in another case, and no issue's record moved but those named in issues, what the full round was told of. A record changed where it stands is not bounded: a landing's own relink touches other records, and a pair reads it. History is read as stored. The error is git's, when it could not say.
func ReleaseHoldForTest ¶ added in v0.15.1
ReleaseHoldForTest is releaseHold, for the implement loop's parity test, which reads it from outside this package.
func RemoteTip ¶ added in v0.16.2
RemoteTip is the commit origin's branch is at, asked of origin itself, or "" when origin has no such branch.
func StatesFullPair ¶ added in v0.16.2
StatesFullPair reports why a build-loop reviewer's return does not state, on its first line, that it read head as a whole, by the rule a receipt reads it.
func StillArmed ¶ added in v0.16.2
StillArmed is the read-back after a withdrawal, for a caller that lets gh name the checkout's repository: whether the forge still reports pull request number from branch armed or queued. gh exits 0 on some failures, so the forge's word is asked, not the call's.
func VerdictEnds ¶ added in v0.16.2
VerdictEnds reports whether what follows a verdict word on its line leaves it a verdict: the implement loop's reader and this one share the rule.
func WithdrawArming ¶ added in v0.16.2
WithdrawArming takes pull request n, node id id, off the forge's merge path: auto-merge off first, so the forge cannot queue it again between the two calls, then out of the queue. `gh pr merge --disable-auto` does not dequeue, so the queue entry takes the forge's own mutation. A dequeue that fails after auto-merge came off says so.
Types ¶
type Facilitator ¶ added in v0.16.0
type Facilitator struct {
Key string `json:"key"`
Mode string `json:"mode"`
Layer string `json:"layer"`
Origin string `json:"origin"`
// HomeRefused says a refused home decided the mode (human), so Origin is
// the reason, not a file.
HomeRefused bool `json:"home_refused,omitempty"`
}
Facilitator is facilitator.mode as resolved: the mode, and the layer and origin that decided it. Layer is "bundled" (Origin "bundled") when no layer declares the key; otherwise Origin names the file that set it (".abcd/config.json", or the machine file in its tilde form), or, for a refused home, why the machine layer could not be read.
func ReadDefaultFacilitator ¶ added in v0.16.0
func ReadDefaultFacilitator(cwd string) (Facilitator, error)
ReadDefaultFacilitator resolves facilitator.mode for the repository holding cwd as the merge gate does (readFacilitatorAt), at the tip of the default branch git tracks for it (gitutil.DefaultRef), with the machine layer of the caller's home (layered.HomeRoots, as RootsFor resolves it). The board reads the mode through it; the shell guard reads ReadFetchedFacilitator. A repository with no default branch to read is an error (ErrNoDefaultBranch): a caller that cannot read the mode takes it as human.
func ReadFetchedFacilitator ¶ added in v0.16.0
func ReadFetchedFacilitator(cwd string) (Facilitator, error)
ReadFetchedFacilitator is ReadDefaultFacilitator for a caller that judges an act by the mode and so must not take it from refs an agent can move (`git remote set-head`, `git update-ref` on a remote-tracking ref): the shell guard, deciding a merge command. It asks Remote which branch is its default and at which commit (git ls-remote --symref), fetches that branch, and reads the mode at the commit Remote named, from the local object store, all within FetchedReadTimeout. A remote that cannot be asked, a fetch that fails or runs out of time, and a tip the fetch did not bring are errors, which the caller counts as human: it never falls back to the checkout's last fetch. So is a checkout where the forge client would act on another remote than Remote (one named upstream or github, which gh prefers, or one gh repo set-default chose), whose mode this read would not be. The fetch writes what any fetch of the branch writes (its remote-tracking ref), never origin/HEAD and never FETCH_HEAD, and starts no maintenance. The network calls run as Net's do, with the person's own git configuration and credentials and never a prompt, so a private repository reads as it fetches.
It trusts Remote's URL as the checkout's configuration names it: an agent that rewrites the URL is out of its reach, as the guard's limit says.
type FetchError ¶
FetchError is a fetch of the default branch git refused.
func (*FetchError) Error ¶
func (e *FetchError) Error() string
func (*FetchError) Unwrap ¶
func (e *FetchError) Unwrap() error
type ForgeCall ¶ added in v0.16.0
ForgeCall runs the forge client with args and returns its stdout, or an error carrying its stderr (so a 404 can be told from any other failure).
type GitFunc ¶
GitFunc runs one networked git command (a fetch or a push) from dir: gitutil.Net, or a test's seam.
type ListError ¶
type ListError struct{ Err error }
ListError is a ruleset mirror whose listing git refused.
type MergeDecision ¶ added in v0.16.0
type MergeDecision struct {
Arm bool
Method string
Why string
// Unread marks a decision not to arm that rests on an answer the gate could
// not read: a forge read that failed, or receipts it could not judge. It is
// no refusal of the head, so nothing is withdrawn on it.
Unread bool
}
MergeDecision is the merge gate's answer to a MergeQuery: whether to arm, with which forge flag, and why.
func DecideMerge ¶ added in v0.16.0
func DecideMerge(q MergeQuery) (MergeDecision, error)
DecideMerge gathers the merge gate's inputs for q and decides. Its error is only a facilitator.mode that cannot be read (wrapping ErrModeUnreadable, sanitised); a forge answer that cannot be read is a reason in the decision, never an arming.
type MergeQuery ¶ added in v0.16.0
type MergeQuery struct {
// RepoRoot is a checkout of the repository: its object store holds the
// default branch's tip, and its worktrees the receipts and approvals.
RepoRoot string
// Roots supplies the machine layer (Home, HomeRefused); its Repo is not
// read.
Roots layered.Roots
// Tip is the default branch's tip as just fetched, and TipName how it is
// named ("origin/main"); Default is the branch's name.
Tip, TipName, Default string
// Rule is the ruleset mirror's merge rule at Tip.
Rule MergeRule
// Repo is the repository as the forge names it ("owner/name"), or gh's
// "{owner}/{repo}" for the checkout's own.
Repo string
// PR is the pull request's number and Head its head commit, the one the
// landing gated.
PR, Head string
// Forge runs the forge client, its error carrying stderr.
Forge ForgeCall
}
MergeQuery is what the merge gate is asked about one pull request.
type MergeRule ¶
type MergeRule struct {
Method string
}
MergeRule is the ruleset mirror read at a commit: the merge queue's method ("" when no merge queue gates the default branch). A pull-request rule's approval requirement is not read: ruling AM1, which armed only where one required a person's approval, is retired, and the merge gate (facilitator.go) reads approvals from the forge itself.
func ReadMergeRule ¶
ReadMergeRule reads the ruleset mirror at the commit base in the repository at repoRoot, for the default branch def. A missing mirror requires nothing. The base is a commit of the default branch (a lane's base, or the merge base of a branch with the default branch), so the branch's own commits cannot change the rule it lands by. at names base in a refusal ("the lane's base"). A mirror that cannot be read is a *MirrorError, a listing git refused a *ListError.
type MergedListingFullError ¶
MergedListingFullError is a listing of a branch's merged pull requests that the bound filled with none at the head: the proof may lie past the bound, so the listing cannot say the head has not merged.
func (*MergedListingFullError) Error ¶
func (e *MergedListingFullError) Error() string
type MirrorError ¶
MirrorError is a ruleset mirror that cannot be read into a merge rule: Reason says what is wrong and Fix what settles it. A caller adds what to run once it is settled.
func (*MirrorError) Error ¶
func (e *MirrorError) Error() string
type Options ¶
type Options struct {
// Branch is the branch to land; "" is the checkout's current branch.
Branch string
// NoPush and NoEnqueue are --no-push and --no-enqueue.
NoPush bool
NoEnqueue bool
// Roots are where land.push and land.enqueue are read: the working
// directory's repository layer and the machine layer. The landed branch's
// own checkout is read as a repository layer beside them.
Roots layered.Roots
// Forge runs the forge client with args from dir.
Forge func(dir string, args ...string) (string, error)
// Git runs one networked git command (a push, a fetch, or the ls-remote
// that asks origin for its default branch) from dir.
Git GitFunc
// Gate runs the preflight in the branch's checkout at dir.
Gate func(dir string) error
// GateOutput receives the preflight's output; nil discards it.
GateOutput io.Writer
// Sleep pauses between the forge readings that wait for land's own push
// to show; nil is time.Sleep.
Sleep func(time.Duration)
// Announce is the options the announcements before the push are made
// with (announce.go): its Home "" is Roots.Home, its Embargo nil the
// check `abcd announce` uses, its ForgeUser nil the forge's user
// endpoint, asked only when git's identity does not name the sender.
Announce claim.Options
}
Options are one landing's inputs and its seams. A nil seam takes the real one: Forge is GH, Git is gitutil.Net (the networked git runner, hooks running), Gate runs `make preflight`.
type Refusal ¶
Refusal is a landing refused: Reason says why, Fix what settles it. Held marks a landing a release being cut holds (releaseHold): contention, which the surface exits 3 on, as every verb that backs off does.
type Result ¶
type Result struct {
Branch string `json:"branch"`
Head string `json:"head"`
Checkout string `json:"checkout"`
Default string `json:"default_branch"`
Push Switch `json:"push"`
Enqueue Switch `json:"enqueue"`
PR int `json:"pull_request,omitempty"`
PRURL string `json:"pull_request_url,omitempty"`
// Pushed is the commit the push step sent, the head the gate checked.
Pushed string `json:"pushed,omitempty"`
// Landed is set when the head was already on the default branch, or the
// forge lists PR as merged at it.
Landed bool `json:"landed,omitempty"`
Steps []Step `json:"steps"`
// Notices are lines the landing shows beside its steps, whatever its
// outcome: each release dated ahead that the release hold did not count.
Notices []string `json:"notices,omitempty"`
}
Result is the landing's report, filled as far as it got: a refused landing returns the steps it completed beside the refusal.
type ReviewReturn ¶ added in v0.16.0
ReviewReturn is one reviewer's return: the name it is recorded under and its text, which states what it read and states its verdict under one `### Verdict` heading.
type Step ¶
type Step struct {
Name string `json:"name"`
Status string `json:"status"`
Note string `json:"note"`
Command string `json:"command,omitempty"`
}
Step is what one step of the landing did.
type Switch ¶
type Switch struct {
Key string `json:"key"`
On bool `json:"on"`
Layer string `json:"layer"`
Origin string `json:"origin"`
}
Switch is one of the landing's two outward acts as configured: whether it is on, and the layer and origin that decided it — the bundled default when no layer turned it off, else the highest layer that did.