gate

package
v0.0.57 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2026 License: Apache-2.0 Imports: 16 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 gate decides whether a run's change is ready, from structure alone: the result's commit is on the PR's branch and carries the change's Change: trailer, and every acceptance item in the run's recorded plan revision has an outcome, for the latest result's commit, that names who vouched. It reads only the record and the commit's facts; it never runs a team's code, checks or tests, and never weighs an outcome's verdict: passed, failed and judged all count, since judging the code is the harness's business.

Index

Constants

View Source
const (
	StatusKind    = "run.status"
	StatusContext = "physa/record"
)

StatusKind is the intent that sends a stored verdict to the forge, and StatusContext the context of the commit status it sets there. A team that wants the hold requires that status in its branch protection.

View Source
const (
	Ready = "ready"
	Held  = "held"
	None  = "none"
)

The verdict's words: ready, held, and none for a run that ended in error or was stopped.

View Source
const (
	NoResult    = "no-result"
	NotOnBranch = "not-on-branch"
	NoTrailer   = "no-trailer"
	Missing     = "missing"
	Stale       = "stale"
	NoVoucher   = "no-voucher"
	Undecided   = "undecided"
)

The kinds of reason that hold a change, in the fixed order Decide gives them, and Undecided for a result whose verdict is not decided yet.

Variables

This section is empty.

Functions

func BranchRefs

func BranchRefs(branch string) []string

BranchRefs returns the refs tried for a branch, in order: the local branch, then origin's.

func Options

func Options(env []string, newForge func(root string) forge.Forge) []state.IntentKind

Options returns the gate's two intent kinds, to pass in state.Options: run.gate, which internal/state/run writes with every result and outcome, and run.status, which the gate writes with every verdict it stores for a result. env is the environment git runs in. newForge gives the forge of a repo root; nil, a nil forge or a forge that sets no commit status means no status is sent.

Types

type Facts

type Facts struct {
	Found    bool     `json:"found"`
	Refs     []string `json:"refs"`
	Resolved bool     `json:"resolved"`
	OnBranch bool     `json:"on_branch"`
	Changes  []string `json:"changes"`
}

Facts is what version control says about the result's commit: whether the commit is in the repository, the branch refs tried in order, whether any of them resolved, whether the commit is on the branch, and the values of the commit's own Change: trailer.

func ReadFacts

func ReadFacts(ctx context.Context, repo Repo, commit, branch string) (Facts, error)

ReadFacts reads the commit's facts for a result's commit and branch: whether the commit is in the repository, whether it is on the branch (it is the tip of, or part of the history of, the local branch or origin's, whichever resolve), and the values of its own Change: trailer. It only reads what the repository already holds, and never fetches. A commit that is not there has no other facts.

type Input

type Input struct {
	Items    []int     `json:"items"`
	Outcomes []Outcome `json:"outcomes"`
	Commit   string    `json:"commit"`
	Branch   string    `json:"branch"`
	Change   string    `json:"change"`
	Facts    Facts     `json:"facts"`
}

Input is everything Decide reads: the acceptance item numbers of the run's recorded plan revision in the plan's order, the run's outcomes in stored order, the latest result's commit and branch (empty when there is no result), the change's name as <pursuit>/<change>, and the commit's facts.

type Outcome

type Outcome struct {
	Item      int    `json:"item"`
	Verdict   string `json:"verdict"`
	Commit    string `json:"commit"`
	VouchedBy string `json:"vouched_by"`
}

Outcome is one outcome as the run recorded it: the acceptance item it is for, its verdict, the commit it is for and who vouched.

type Reason

type Reason struct {
	Kind string `json:"kind"`
	Item int    `json:"item,omitempty"`
	Text string `json:"text"`
}

Reason is one thing that holds a change: its kind, the acceptance item it is about (0, and left out of JSON, when it is not about an item) and one line naming the item or the fact.

type Repo

type Repo interface {
	Resolve(ctx context.Context, ref string) (id string, ok bool)
	IsAncestor(ctx context.Context, a, b string) bool
	Trailer(ctx context.Context, ref, key string) (vcs.Change, bool, error)
}

Repo is what the gate reads from version control: the commit a ref names, whether one commit is part of another's history, and the newest commit carrying a trailer. vcs.Repo satisfies it.

type Verdict

type Verdict struct {
	Verdict string   `json:"verdict"`
	Reasons []Reason `json:"reasons"`
}

Verdict is whether a change is ready or held, with every reason that holds it; Reasons is empty, never nil, when it is ready.

func Decide

func Decide(in Input) Verdict

Decide returns the change's verdict and every reason that holds it, in a fixed order: no result, then the commit not on the branch, then no Change: trailer for the change, then at most one reason per acceptance item in the plan's order (missing, stale or no voucher). An item is satisfied by any outcome for the latest result's commit that names who vouched; older outcomes are history and hold nothing. Decide is pure: it reads only in.

type View

type View struct {
	Verdict string   `json:"verdict"`
	Commit  string   `json:"commit,omitempty"`
	Reasons []Reason `json:"reasons"`
}

View is what a reader sees for a run: the verdict (ready, held, or none for a run that ended in error or was stopped), the commit it is for when there is one, and what holds the change; Reasons is empty, never nil.

func Seen

func Seen(tx *state.Tx, r staterun.Run) (View, error)

Seen returns what a reader sees for the run r, in the caller's transaction, from the store alone: it never calls version control. A run that ended in error or was stopped shows none. A run with no result is held for that, with the stored reasons when a verdict was stored for no commit. A run whose stored verdict is for its latest result's commit shows it. A run with a result newer than the stored verdict, or none stored yet, is held as not decided yet: a verdict for another commit is never shown.

func Show

func Show(ctx context.Context, s work.Submitter, run int64) (View, error)

Show returns what a reader sees for the run, as Seen does, in one read of the store. An unknown run is refused.

Jump to

Keyboard shortcuts

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