Documentation
¶
Overview ¶
Package finish closes a task: it decides what landing means, lands the request, archives what the task leaves and cleans up its checkout, workspace and branch.
Index ¶
- Constants
- Variables
- func AttemptRows(in FinishInput, branch string, rows []drives.Task) func(drives.Task) bool
- func BodyCloses(body string, riders []ref.Ref) []string
- func CloseAgain(body, number string) string
- func CloseChoice(task ref.Ref, value string, resolve func(string) (ref.Ref, error)) ([]string, error)
- func CloseSeries(dir string, end archive.SeriesEnd) (string, error)
- func CloseTaskFor(t *target.Target, h hostops.Host) func(context.Context, ref.Ref) error
- func ClosedChange(dir string, end archive.SeriesEnd) (string, bool)
- func ClosingLine(number string) string
- func ClosingLines(in FinishInput) string
- func DeferredPullNote(err error, main, def string) string
- func Finish(ctx context.Context, w io.Writer, in FinishInput) error
- func FinishTarget(ctx context.Context, in FinishInput) (string, string, bool, error)
- func FinishedEvent(id, by string, at time.Time) ledger.Event
- func Janitor(ctx context.Context, in JanitorInput) ([]string, error)
- func JanitorDefault(ctx context.Context, main string) (string, error)
- func JanitorDue(stamp string, now time.Time) bool
- func KeepOpen(body, number string) string
- func KeptName(ctx context.Context, main, branch string, ids []string) string
- func LandingBase(ctx context.Context, dir, def string) (string, error)
- func Lease(root, id string) (*drives.Lease, error)
- func MergeBody(in FinishInput, description, method string) string
- func ProcessPlace() (string, string, error)
- func ReadPendingPull(root string) (string, string)
- func Ref(ctx context.Context, t *target.Target, token string) (ref.Ref, string, string, error)
- func ReleaseDependents(ctx context.Context, dir, branch, def string, merged bool) ([]string, error)
- func RemoveImages(root storage.Root, id string) string
- func RetryPendingPull(ctx context.Context, root, main string) (string, bool)
- func SpikePlan(path string) bool
- func SweepIfDue(ctx context.Context, w io.Writer, stamp string, now time.Time, ...)
- func TaskSpike(checkout string, root storage.Root, id string) string
- func TouchStamp(stamp string, now time.Time) error
- type BranchSize
- type FinishInput
- type Flags
- type ForeignPullError
- type JanitorInput
- type RidersError
- type StaleBranch
- type Sweeper
Constants ¶
const JanitorEvery = 6 * time.Hour
JanitorEvery is how long start and finish wait between two janitor runs.
const JanitorStamp = "janitor.stamp"
JanitorStamp's mtime is the last run.
const MainPullKey = "main-pull"
MainPullKey is the lease every finish pulling the main checkout takes, so two finishes at once (a drive's, the watcher's, the command) never race on origin's refs.
const PendingPullFile = "pending-pull"
PendingPullFile, in the storage root every checkout shares, records a deferred pull as "<default branch> <merge sha>". Only the newest sha matters, since origin's branch holds every earlier merge too.
Variables ¶
var ClosingRE = regexp.MustCompile(fmt.Sprintf(closingKeyword, `\d+`))
ClosingRE reads any closing keyword before any issue number.
var ErrNotMerged = errors.New("its request has not merged on the host, and only merged work is finished here")
var ErrPullBusy = errors.New("another finish held the pull")
ErrPullBusy is another finish holding the pull's lease past mainPullWait.
var RecordSize = func(ctx context.Context, dir, branch, task string, s BranchSize) { place := ledger.Where(ctx, dir) ledger.Record(ledger.Event{ At: time.Now(), Project: place.Project, ProjectLocal: place.ProjectLocal, Checkout: place.Checkout, Branch: branch, Session: state.Session(), Task: task, Kind: ledger.TaskSized, Source: ledger.Observed, Payload: ledger.NewPayload(ledger.Payload{ "lines": s.Lines, "md_lines": s.Md, "files": s.Files, "base": s.Base, }), }) }
RecordSize puts the size in the ledger for `f10 stats`; a test swaps it.
Functions ¶
func AttemptRows ¶
AttemptRows matches the rows of the attempt finish acted on, since one attempt finished leaves the task's others alive. A bare finish, or one that found the lone <id>-* branch, types no suffix: the branch's ending names the attempt, the same way the branch index finds it.
func BodyCloses ¶
BodyCloses is the riders body closes on merge, in bundle order: a rider under `Part of`, or not named at all, stays open.
func CloseChoice ¶
func CloseChoice(task ref.Ref, value string, resolve func(string) (ref.Ref, error)) ([]string, error)
CloseChoice reads --close; a token outside the bundle is a typo, refused.
func CloseSeries ¶
CloseSeries ends the task's series even when it had no review rounds, since the archive is what counts a task's PRs for its lore change; a series already closed with the same PR or head (finish run again) adds none.
func CloseTaskFor ¶
CloseTaskFor closes the task on the host only where the host is the tracker.
func ClosedChange ¶
ClosedChange is the change of the PR end closed, when the newest archived PR is that one: a finish run again after its merge reports on it, not on the next series.
func ClosingLine ¶
ClosingLine is the line a commit or a PR body closes issue number with.
func ClosingLines ¶
func ClosingLines(in FinishInput) string
ClosingLines closes the lead and the riders --close names once the commit reaches origin's default branch; written whatever traces says, since it is the task's own reference. Other trackers, a driver's included, are not closed by a commit, as on the PR path.
func DeferredPullNote ¶
DeferredPullNote names why the pull failed and what settles it.
func Finish ¶
Finish runs in the order the refusals need: every refusal before anything changes, the report before anything local goes, and the workspace close last, since on the self-close path the close ends this process.
func FinishTarget ¶
FinishTarget is the task's branch and the checkout holding it, main's or a worktree's. A branch checked out nowhere is a refusal: finish cleans up only what start made.
func FinishedEvent ¶
FinishedEvent records a finish that ran in this process, where no hook sees it; by names who ran it, "" for the drive.
func Janitor ¶
func Janitor(ctx context.Context, in JanitorInput) ([]string, error)
Janitor reports a line per removal, and per branch kept for a reason worth knowing.
func JanitorDefault ¶
JanitorDefault falls back to the main checkout's branch only with no origin.
func KeptName ¶
KeptName is kept/ and the branch's name with the task's ids taken out, so no task lookup finds it; numbered when taken.
func LandingBase ¶
LandingBase is the local default branch, or origin's copy when the local one is only behind it, so origin's commits are never folded into the merge.
func MergeBody ¶
func MergeBody(in FinishInput, description, method string) string
MergeBody is the host commit's body: the description minus its state block, then a Task: line per member, so a squash still names what it shipped. A rebase, or glab's plain merge (""), keeps the branch's trailers.
func ProcessPlace ¶
ProcessPlace is this process's directory and workspace, for finish's self-close check.
func ReadPendingPull ¶
func Ref ¶
Ref is the task a token names, its suffix, and for a bare call the branch checked out here, which picks it among suffixed siblings. The session's task is refused: nothing else would stand between it and a merge.
func ReleaseDependents ¶
ReleaseDependents clears other branches' `start --after` dependency on the finished one and marks them landed: their pr must target the default branch now, and their next ship or catchup must bring it in first. merged says the finished branch's code reached the default branch.
func RemoveImages ¶
RemoveImages drops the images `task read` downloaded for the task; a failure is a note, since the task is finished either way.
func RetryPendingPull ¶
RetryPendingPull retries a pull a finish deferred. It reports "" with no pull pending, else what happened, and whether the pull is still pending.
func SweepIfDue ¶
func SweepIfDue(ctx context.Context, w io.Writer, stamp string, now time.Time, run func(context.Context) ([]string, error), )
SweepIfDue never fails the command that ran it: an error is one warning. The stamp moves first, so commands in quick succession run it once.
Types ¶
type BranchSize ¶
BranchSize is what a task changed, lockfiles, generated code and snapshots left out.
type FinishInput ¶
type FinishInput struct {
Main string // the main checkout: host and git commands run here
Root string // the shared storage root, for the pull's lease; "" takes none
Driver *driver.Driver // nil without one
Task ref.Ref
Change string // the lore change this merge closes; finish fills it from the task's series
Suffix string
Branch string // a bare call's own branch, "" to look it up by task and suffix
Host hostops.Host
Method string // the merge method project.md declares, "" for none
Traces bool // traces: on; the squash or merge commit's body ends in the task's trailers
// HostCloses: a merge's closing keyword closes the task (target.HostCloses)
HostCloses bool
// LoreStore feeds the report's lore line and the pre-merge check (nil reads
// nothing); gate is lore_gate: warn notes a failing check, block refuses
LoreStore *lore.Store
Gate string
Cwd string // where the command runs: inside the worktree is the self-close case
Workspace string // HERDR_WORKSPACE_ID: the workspace this process runs in, or ""
Flags Flags
Storage storage.Root // the same root as root, for task files: plans, findings, handoffs
// Title reads the task's title for a squash merged here, nil for none
Title func(context.Context) (string, error)
// Close is the riders the PR delivers, closed with the lead; nil, no
// --close answer yet, refuses a bundle's merge unless FollowBody
Close []string
// FollowBody takes a nil Close from the PR body's closing keywords, for
// the drive and the watcher, which have no one to ask
FollowBody bool
// Sweep runs the janitor before the workspace closes, since a self-close
// ends the process; nil for none
Sweep func(context.Context)
// Progress names each action as it starts, for drive's record; nil for none
Progress func(string)
// Handoff takes the lines a merge prints under its report, for drive's report; nil for none
Handoff func([]string)
// Deferred takes a deferred pull's note, for drive's report; nil for none
Deferred func(string)
// Subtasks is every subtask, closed ones kept, for a parent with no branch;
// nil, like ErrNoParentLink, is a tracker with no parent link
Subtasks func(context.Context, ref.Ref) ([]stack.ChildRow, error)
// CloseTask closes a parent its subtasks delivered; nil where the tracker is
// not the host, which f10 has no "done" word for
CloseTask func(context.Context, ref.Ref) error
}
FinishInput is everything finish needs once the target is settled, so the flow can be tested without a checkout.
type Flags ¶
type Flags struct {
Yes bool // close the workspace finish runs in, after the report
Merge bool // merge the PR even when someone else opened it
LeaveOpen bool // --local: leave the PR open and clean up only what is here
Keep bool // a spike's experiment is committed onto a kept/ branch, not discarded
// MergedOnly refuses all but an already merged request: the watcher never merges
MergedOnly bool
}
Flags are the caller's choices; everything else finish derives.
type ForeignPullError ¶
A ForeignPullError is a refusal: nothing changed, the choice is the user's.
func (ForeignPullError) Error ¶
func (e ForeignPullError) Error() string
type JanitorInput ¶
type JanitorInput struct {
Main string
Host *hostops.Host // nil without a host CLI: only branches never pushed qualify
Prefix string
Storage storage.Root
Dry bool
// LocalOnly: the watcher asks the network nothing before the host
LocalOnly bool
}
JanitorInput is everything the janitor needs, so it runs in a test without a checkout.
func JanitorFor ¶
func JanitorFor(t *target.Target) JanitorInput
type RidersError ¶
type RidersError struct {
// contains filtered or unexported fields
}
A RidersError is a bundle finished without --close: nothing changed.
func (RidersError) Error ¶
func (e RidersError) Error() string
type StaleBranch ¶
type StaleBranch struct {
Name string
Ids []string // the tasks it ships, a bundle's lead first
LocalSHA string // "" where the branch is not
// contains filtered or unexported fields
}
func TaskBranches ¶
func TaskBranches(ctx context.Context, in JanitorInput, def string) ([]StaleBranch, map[string]bool, error)
TaskBranches reads a branch as finish does: its link or recorded bundle, else its name. On origin a bare id counts only in the shapes start creates, so a name merely mentioning one is someone else's. held is every branch a checkout has, main's included.
type Sweeper ¶
type Sweeper struct {
In JanitorInput
Def string
Lines []string
// contains filtered or unexported fields
}
A Sweeper is one janitor run: its lines, and the host login read once.
func (*Sweeper) Request ¶
Request is the request that decides b: an open one when any is, else the newest; nil when there is none.
func (*Sweeper) SweepUnpushed ¶
SweepUnpushed removes a branch finish would read as never pushed once its changes are in the default branch; its work ended with its last commit.