Documentation
¶
Overview ¶
Package rules reads a repository's vx.toml: what text merges cannot see.
[[unique]] files matching glob may not share a key, e.g. two
migrations with the same number; or, with content
(and scope), lines inside them may not share a value,
e.g. two fields numbered 12 in one proto message
[[generated]] files matching glob are generated by command: vx never
text-merges them and tells people to regenerate
[checks] required = commands vx land should run (--run)
[[policy]] how changes to some paths land: fast (default), gated
(required checks run by vx and passing) or human (a
person approves first)
The package is pure: it reads trees and blobs through a blob.Store, so the server (land, ship, rebase) and the CLI (vx sync, vx land) apply the same rules to the same trees.
Index ¶
- Constants
- Variables
- func Check(ctx context.Context, s blob.Store, r Rules, base, tree hash.Hash) ([]engine.Warning, error)
- func ContentKeys(content, scope *regexp.Regexp, data []byte) map[string][]int
- func Files(ctx context.Context, s blob.Store, tree hash.Hash, g Glob) ([]string, error)
- func KeyOf(key *regexp.Regexp, path string) (string, bool)
- func MatchGlob(pattern, path string) bool
- func MergeOptions(ctx context.Context, s blob.Store, trees ...hash.Hash) []engine.MergeOption
- func MissingChecks(r Rules, ran []string) []string
- func NotVerified(command string) string
- func ShellQuote(s string) string
- type Approver
- type Decision
- type Error
- type Generated
- type Glob
- type MissingCheck
- type Mode
- type Policy
- type Problem
- type Rules
- type Unique
Constants ¶
const ( RebaseAuto = "auto" // rebase when it replays cleanly, else say which files conflict RebaseNotify = "notify" // only say that the effort is behind, and whether it would conflict RebaseOff = "off" // do nothing )
[automation] rebase values.
const File = "vx.toml"
File is where a repository keeps its rules: the root of the tree.
const WarningRule engine.WarningKind = "rule"
WarningRule marks a warning about a vx.toml rule.
Variables ¶
var Modes = []Mode{ModeFast, ModeGated, ModeHuman}
Modes lists the modes in vx.toml spelling, least strict first.
Functions ¶
func Check ¶
func Check(ctx context.Context, s blob.Store, r Rules, base, tree hash.Hash) ([]engine.Warning, error)
Check reports [unique] violations in tree as warnings of kind WarningRule, limited to keys used by a file that is new or changed between base and tree, so a clash that predates the change is not repeated on every land. base may be zero: every file counts as new. Content rules (see content.go) report values used more often in tree than in base, with Decl = "SCOPE VALUE" (or "VALUE" outside scopes).
Each warning has Name = the rule name, Decl = the shared key, Files = the full paths of every file using it (sorted), Path = the first of them that changed, and a Detail for people:
migration 008 is used by 008_effort_rebases.sql and 008_orgs.sql (rule migration in vx.toml)
func ContentKeys ¶ added in v0.5.0
ContentKeys returns the values content matches in data, each prefixed with its scope ("LandResponse 12"; without scope, or outside every scope, just "12"), with the 1-based lines they are on. scope may be nil.
func Files ¶
Files lists the files of tree that match g, sorted. Only the glob's literal directory is read.
func MatchGlob ¶
MatchGlob reports whether path matches pattern; an invalid pattern matches nothing.
func MergeOptions ¶
MergeOptions are the engine options of a merge whose sides are trees: the [[generated]] rules of every one of them, so a generated file is never text-merged whichever side declared it. A vx.toml that does not parse adds nothing (the land reports it).
func MissingChecks ¶
MissingChecks returns the required checks of r that are not in ran (commands vx ran, compared after trimming spaces), in vx.toml order.
func NotVerified ¶
NotVerified describes a required check vx did not run:
required check `go vet ./...` (vx.toml) was not run by vx
func ShellQuote ¶ added in v0.4.0
ShellQuote quotes s as one sh word, in single quotes.
Types ¶
type Approver ¶ added in v0.4.0
Approver is a parsed approvers entry.
func ParseApprover ¶ added in v0.4.0
ParseApprover parses "user:HANDLE" or "team:ORG/TEAM".
type Decision ¶ added in v0.4.0
type Decision struct {
Mode Mode // ModeFast when no policy matches
// Paths are the changed files under the policies of Mode, sorted: the
// files that make this land gated or human.
Paths []string
// Require are the checks of every matching gated or human policy, in
// vx.toml order without repeats.
Require []string
// Approvers has one list per matching human policy that names
// approvers: a person approves only when they are in every list.
Approvers [][]string
// Policies describe the policies of Mode that matched (Policy.Describe).
Policies []string
}
Decision is the policy that applies to a land: the strictest of the policies whose paths match a file the land changes.
func Combine ¶ added in v0.4.0
Combine returns the strictest of decisions, for example the policies of the effort head's vx.toml and of the snapshot's: a change can make its own policy stricter but never weaker. The checks of every gated or human decision add up; the paths, approvers and policies are those of the strictest mode.
func (Decision) LandCommand ¶ added in v0.4.0
LandCommand is the vx land that runs every check of d, quoted for sh:
vx land --run 'go vet ./...' --run 'go test ./...'
func (Decision) Missing ¶ added in v0.4.0
func (d Decision) Missing(passed, failed []string) []MissingCheck
Missing returns the checks of d that did not run by vx and pass: passed are the commands vx ran that passed (compared after trimming spaces), failed those it ran that failed. Each entry says which.
type Generated ¶
Generated says files matching Glob are generated by Command: vx never text-merges them and tells people to regenerate instead.
type Glob ¶
type Glob struct {
// contains filtered or unexported fields
}
Glob matches slash-separated repository paths. A "*" matches any run of characters within one path segment, "?" one character within a segment, and a "**" segment any number of segments (zero or more):
internal/store/migrations/*.sql files directly in that directory gen/** every file under gen/ **/*_string.go a file of that name at any depth api/**/types.go api/types.go, api/v1/types.go, ...
Paths have no leading slash. Character classes and braces are not supported, so a glob means the same thing to everyone reading vx.toml.
func CompileGlob ¶
CompileGlob checks a glob and prepares it for matching. Errors say what is wrong and how to write it instead.
func (Glob) Dir ¶
Dir is the literal directory every matching path lives under, "" for the repository root: the part of the tree a scan has to read.
type MissingCheck ¶ added in v0.4.0
type MissingCheck struct {
Command string
Failed bool // vx ran it and it failed; otherwise vx did not run it
}
MissingCheck is a required check a gated land lacks.
type Mode ¶ added in v0.4.0
type Mode string
Mode is how a landing policy lands changes to its paths.
const ( // ModeFast lands at once and checks afterwards: what vx always did. ModeFast Mode = "fast" // ModeGated lands only when every required check ran by vx (vx land // --run) and passed in this land, on exactly what lands. ModeGated Mode = "gated" // ModeHuman is gated, and then a person approves before the change // lands: until then it waits as a pending review and the effort head // does not move. ModeHuman Mode = "human" )
Landing modes, from the least to the most strict.
type Policy ¶ added in v0.4.0
type Policy struct {
Paths []string // globs
Mode Mode
// Require are the checks a gated or human land needs, run by vx and
// passing: the policy's own require, or [checks] required when the
// policy does not set it.
Require []string
// Approvers limit who approves a human land: "user:HANDLE" or
// "team:ORG/TEAM". Empty: anyone with write on the repository.
Approvers []string
Line int // line of the [[policy]] header in vx.toml; 0 when not known
}
Policy is one [[policy]] of vx.toml: how changes to Paths land.
type Rules ¶
type Rules struct {
Unique []Unique
Generated []Generated
RequiredChecks []string
// Rebase is [automation] rebase: what vx does with an open effort when
// its base branch moves. Empty means RebaseAuto.
Rebase string
Policies []Policy
Source string // e.g. "vx.toml at 3f2a1c9d0e7b"; empty: none
// Ignored says what of vx.toml this vx does not know (keys or tables
// of a newer vx) and so left out: a rule with an unknown key is
// ignored as a whole. "vx.toml line 15: rule [[unique]] "proto-field"
// uses key "scope", which this vx does not know; ...".
Ignored []string
}
Rules are a repository's vx.toml.
func At ¶
At returns the rules in vx.toml at the root of tree. Without a vx.toml there are no rules and no error. Source says where they came from.
func Parse ¶
Parse parses vx.toml. Syntax errors, unknown keys, invalid globs and regular expressions are errors (*Error) that say the line and what is wrong.
func (Rules) GeneratedMatcher ¶
GeneratedMatcher compiles the [[generated]] globs once. The returned function reports whether path is generated and by which command (the first matching rule wins). Invalid globs match nothing.
func (Rules) RebaseMode ¶ added in v0.4.0
RebaseMode is the [automation] rebase setting, RebaseAuto by default.
type Unique ¶
type Unique struct {
Name string
Glob string
Key string
Content string // optional, instead of Key: a regular expression matched against each line
Scope string // optional, with Content: a regular expression whose first group names a scope
}
Unique says that files matching Glob may not share the first group of Key, matched against the file's base name (for example two migrations with the same number). With Content instead of Key, the rule looks inside the files: the first group of Content, matched against each line, may not be used twice, within each scope that Scope starts (see content.go).