finish

package
v0.63.0 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2026 License: MIT Imports: 37 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 ChecksBudget = 20 * time.Minute

ChecksBudget is how long a pending head may hold a finish, interactive or driven, before it is refused as if red.

View Source
const JanitorStamp = "janitor.stamp"

JanitorStamp's mtime is the last run.

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 ChecksPoll = 15 * time.Second

ChecksPoll is how often a waiting finish reads the checks again.

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

ClosingRE reads any closing keyword before any issue number.

Functions

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 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 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 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 KeepOpen

func KeepOpen(body, number string) string

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

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) (*drivestore.Lease, error)

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 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 Run added in v0.62.0

func Run(ctx context.Context, w, progress io.Writer, t *target.Target, req Request, out *Finished) error

Run finishes the task req names in t's project, writing the report to w and the janitor's lines to progress.

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

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 ChecksError added in v0.60.0

type ChecksError struct {
	URL    string
	Checks forge.HeadChecks
	Waited time.Duration
}

A ChecksError refuses a merge on the head's checks, with nothing changed; Waited is how long this finish waited on them.

func (ChecksError) Error added in v0.60.0

func (e ChecksError) Error() string

func (ChecksError) Pending added in v0.60.0

func (e ChecksError) Pending() bool

Pending reports a head whose checks were still running when refused.

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 *trackerdriver.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)
	// Outcome, when set, takes what the finish did, for a caller that does
	// not read the report
	Outcome *Finished
	// 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
	// ChecksWait is how long a pending head may hold the merge; zero refuses it
	// at once, for the drive, which holds the task itself
	ChecksWait time.Duration
	// DeferSelfClose leaves the caller's own workspace open and names it in
	// Outcome, for a caller in another process (the daemon), whose close
	// would end the client before it printed the report
	DeferSelfClose bool
}

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 Finished added in v0.62.0

type Finished struct {
	Task            string
	PR              string
	Commit          string
	RemovedWorktree bool
	RemovedBranch   bool
	ClosedWorkspace bool
	// CloseWorkspace is the caller's own workspace a deferred self-close
	// leaves to the caller, which focuses FocusWorkspace first; "" for none
	CloseWorkspace, FocusWorkspace string
}

Finished is what a finish did: the task, the PR it merged or left, the merge commit, and what it removed.

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
	// IgnoreChecks merges past red or pending checks; --yes never implies it,
	// since automated finishes pass --yes
	IgnoreChecks bool
	// Empty closes a task whose never-pushed branch adds nothing to the
	// default branch; --yes never implies it, since automated finishes pass --yes
	Empty 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 Request added in v0.62.0

type Request struct {
	Token string // the task id, any bundle member, or "" for the branch's
	Close string // the riders the PR delivers: ids, all or none
	Flags Flags
	// Cwd and Workspace are where the caller runs; a finish from inside the
	// task's own workspace closes it last
	Cwd, Workspace string
	// DeferSelfClose leaves that close to the caller (FinishInput)
	DeferSelfClose bool
}

A Request is a finish as its caller words it.

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

Directories

Path Synopsis
Package finishtest holds the janitor fixture, which both finish's janitor tests and the drive's watch tests start from.
Package finishtest holds the janitor fixture, which both finish's janitor tests and the drive's watch tests start from.

Jump to

Keyboard shortcuts

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