finish

package
v0.58.0 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: MIT Imports: 34 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
const JanitorEvery = 6 * time.Hour

JanitorEvery is how long start and finish wait between two janitor runs.

View Source
const JanitorStamp = "janitor.stamp"

JanitorStamp's mtime is the last run.

View Source
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.

View Source
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

View Source
var ClosingRE = regexp.MustCompile(fmt.Sprintf(closingKeyword, `\d+`))

ClosingRE reads any closing keyword before any issue number.

View Source
var ErrNotMerged = errors.New("its request has not merged on the host, and only merged work is finished here")
View Source
var ErrPullBusy = errors.New("another finish held the pull")

ErrPullBusy is another finish holding the pull's lease past mainPullWait.

View Source
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

func AttemptRows(in FinishInput, branch string, rows []drives.Task) func(drives.Task) bool

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

func BodyCloses(body string, riders []ref.Ref) []string

BodyCloses is the riders body closes on merge, in bundle order: a rider under `Part of`, or not named at all, stays open.

func CloseAgain

func CloseAgain(body, number string) string

CloseAgain undoes KeepOpen.

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

func CloseSeries(dir string, end archive.SeriesEnd) (string, error)

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

func CloseTaskFor(t *target.Target, h hostops.Host) func(context.Context, ref.Ref) error

CloseTaskFor closes the task on the host only where the host is the tracker.

func ClosedChange

func ClosedChange(dir string, end archive.SeriesEnd) (string, bool)

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

func ClosingLine(number string) string

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

func DeferredPullNote(err error, main, def string) string

DeferredPullNote names why the pull failed and what settles it.

func Finish

func Finish(ctx context.Context, w io.Writer, in FinishInput) error

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

func FinishTarget(ctx context.Context, in FinishInput) (string, string, bool, error)

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

func FinishedEvent(id, by string, at time.Time) ledger.Event

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

func JanitorDefault(ctx context.Context, main string) (string, error)

JanitorDefault falls back to the main checkout's branch only with no origin.

func JanitorDue

func JanitorDue(stamp string, now time.Time) bool

func KeepOpen

func KeepOpen(body, number string) string

KeepOpen turns `Closes #12` into `Part of #12`, so the merge leaves it open.

func KeptName

func KeptName(ctx context.Context, main, branch string, ids []string) string

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

func LandingBase(ctx context.Context, dir, def string) (string, error)

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 Lease

func Lease(root, id string) (*drives.Lease, error)

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

func ProcessPlace() (string, string, error)

ProcessPlace is this process's directory and workspace, for finish's self-close check.

func ReadPendingPull

func ReadPendingPull(root string) (string, string)

func Ref

func Ref(ctx context.Context, t *target.Target, token string) (ref.Ref, string, string, error)

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

func ReleaseDependents(ctx context.Context, dir, branch, def string, merged bool) ([]string, error)

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

func RemoveImages(root storage.Root, id string) string

RemoveImages drops the images `task read` downloaded for the task; a failure is a note, since the task is finished either way.

func RetryPendingPull

func RetryPendingPull(ctx context.Context, root, main string) (string, bool)

RetryPendingPull retries a pull a finish deferred. It reports "" with no pull pending, else what happened, and whether the pull is still pending.

func SpikePlan

func SpikePlan(path string) bool

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.

func TaskSpike

func TaskSpike(checkout string, root storage.Root, id string) string

TaskSpike is the task's spike report, "" for none: the shared one, else one the checkout keeps in its own storage. A plan that is not a spike's wins over a report, so a report left from an earlier spike never closes a task planned again as something else.

func TouchStamp

func TouchStamp(stamp string, now time.Time) error

Types

type BranchSize

type BranchSize struct {
	Lines, Md, Files int
	Base             string
}

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.

func InputFor

func InputFor(t *target.Target, main string, h hostops.Host, task ref.Ref) FinishInput

InputFor fills what comes from the task and the project's settings, so the command, the drive and the watcher all take the same ones; each caller then sets only its own fields.

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

type ForeignPullError struct {
	URL    string
	Author string
}

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

func (j *Sweeper) Request(ctx context.Context, b StaleBranch) (*forge.PR, error)

Request is the request that decides b: an open one when any is, else the newest; nil when there is none.

func (*Sweeper) SweepUnpushed

func (j *Sweeper) SweepUnpushed(ctx context.Context, b StaleBranch) (time.Time, bool)

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.

Jump to

Keyboard shortcuts

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