Help us shape the future of Go! Take the 2026 Go Developer Survey

gate

package
v0.38.0 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2026 License: MIT Imports: 23 Imported by: 0

Documentation

Overview

Package gate runs a gate: a list of checks, each a command whose result is read against thresholds decided in advance (docs/spec/gates.md). No model is ever asked whether to pass. On a merge request, the thresholds read only the findings the change adds (ADR-0049): each SARIF check runs again at the merge base, and its results are compared.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Run

func Run(repo, name string) *verdict.Verdict

Run runs every check and returns the gate's verdict, every finding counted: on a schedule, a release, or by hand. A check that could not run, or whose output cannot be read, fails the gate unless marked optional.

Types

type Added added in v0.36.0

type Added struct {
	Base     string       `json:"base"` // the merge base they are counted since
	Checks   []CheckCount `json:"checks"`
	Findings []Finding    `json:"findings"`
	// Present: on main after a merge (Options.Keep), the fingerprint of
	// every finding HEAD holds, new or not: what one found earlier is
	// still there while it is named here.
	Present []string `json:"present,omitempty"`
}

Added is what a gate found a change adds, for what shows it on the merge request (ADR-0049, step 3): each check's count, and the findings themselves, placed and named by a fingerprint.

func RunNew added in v0.36.0

func RunNew(repo, name, since string) (*verdict.Verdict, *Added)

RunNew runs the gate on a change: the thresholds read only the findings it adds since the merge base of since and HEAD, and a suppression it adds counts as one (ADR-0049). Added is what the change adds, for what shows it on the merge request; nil when the gate did not run.

func RunWith added in v0.38.0

func RunWith(repo, name string, o Options) (*verdict.Verdict, *Added)

RunWith runs the gate as o says.

type Check

type Check struct {
	ID       string         `yaml:"id"`
	Run      string         `yaml:"run"`
	Output   string         `yaml:"output"` // exit | sarif
	Max      map[string]int `yaml:"max"`    // per SARIF level: error, warning, note
	Optional bool           `yaml:"optional"`
	Timeout  string         `yaml:"timeout"` // e.g. "10m"; default 10 minutes
	// New says who tells a merge request's new findings, for a SARIF
	// check: rerun (the default), the engine, running it again at the
	// merge base; tool, the tool itself, given WORKLINE_BASE.
	New string `yaml:"new"`
	// BaseTimeout caps the run at the merge base; by default twice the
	// head's, a minute at least, the check's timeout at most.
	BaseTimeout string `yaml:"base-timeout"`
	// Config: the files the tool reads its config from, beside those its
	// name tells, the head's copied over the merge base.
	Config []string `yaml:"config"`
	// Fix is the command that fixes what the check finds, a formatter's:
	// said with its findings, which are not shown line by line.
	Fix string `yaml:"fix"`
}

Check is one command of a gate.

type CheckCount added in v0.36.0

type CheckCount struct {
	ID     string `json:"id"`
	Output string `json:"output"` // exit or sarif
	New    int    `json:"new"`
	// Before: the findings there before the change, not counted; -1 when
	// the tool told the new ones itself, the rest not known, or none were read.
	Before int    `json:"before"`
	Failed bool   `json:"failed,omitempty"` // an exit check that did not pass
	Kept   bool   `json:"kept,omitempty"`   // the merge base's findings read as main kept them, not run again there
	Error  string `json:"error,omitempty"`  // the check did not work: nothing it found is known
	Fix    string `json:"fix,omitempty"`    // the command that fixes what it finds: a formatter's
}

CheckCount is how one check of a gate ended on a change.

type Finding added in v0.36.0

type Finding struct {
	Check   string `json:"check"`
	Tool    string `json:"tool,omitempty"`
	Rule    string `json:"rule,omitempty"`
	Level   string `json:"level"` // SARIF's: error, warning, note
	Path    string `json:"path,omitempty"`
	Line    int    `json:"line,omitempty"`
	Message string `json:"message,omitempty"`
	// Fingerprint holds no line number: the finding's identity, as the
	// comparison reads it, and how many alike come before it in its file.
	// It stays while the finding only moves (GitLab's Code Quality reads
	// it).
	Fingerprint string `json:"fingerprint"`
}

Finding is one result a change adds, as the tool wrote it.

type Gate

type Gate struct {
	Criteria string            `yaml:"criteria"`
	Checks   []Check           `yaml:"checks"`
	Enforce  map[string]string `yaml:"enforce"`
}

Gate is one named gate.

func Load

func Load(repo, name string) (*Gate, error)

Load reads the gates declared in <repo>/.workline/config.yaml.

func (*Gate) Validate

func (g *Gate) Validate() []verdict.Finding

Validate refuses a gate whose verdict would be decided while reading the results: every counted output needs its thresholds up front.

type Options added in v0.38.0

type Options struct {
	// Since: the change's start. Only the findings it adds since the
	// merge base of Since and HEAD count; empty, every one.
	Since string
	// Kept: the folder of the findings kept by commit (ADR-0050). A SARIF
	// check's findings at the merge base are read there when kept with
	// the same command, config and tool, rather than run again.
	Kept string
	// Keep: HEAD's findings are written there, every one of each SARIF
	// check: main after a merge, the next merge requests' base. Added
	// then names them all (Present), and is given with no change too.
	Keep bool
}

Options says how a gate runs.

Jump to

Keyboard shortcuts

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