trace

package
v0.40.0 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package trace is the vocabulary of what f10 leaves on the host for a reader of the history: the git trailers a step's commit carries. Render and Parse sit side by side so the lines the binary writes are the lines the board reads back; docs/traces.md is the spec and testdata/trailers its conformance suite.

Index

Constants

View Source
const (
	KeyTask   = "Task"
	KeyStep   = "Step"
	KeyReview = "Review"
)

The three trailer keys, version 1 of the spec.

View Source
const StateVersion = 1

StateVersion is the `v` every block written today carries; a block with another version reads as no state.

Variables

View Source
var (
	// ErrBadCount is a state count below zero.
	ErrBadCount = errors.New("trace: state counts are zero or more")
	// ErrBadAfter is a base task id with whitespace in it.
	ErrBadAfter = errors.New("trace: a base task id has no whitespace")
)
View Source
var (
	// ErrBadStep is a step name outside `[a-z][a-z0-9-]*`.
	ErrBadStep = errors.New("trace: a step is a lowercase token")
	// ErrBadTask is a task id with whitespace in it.
	ErrBadTask = errors.New("trace: a task id has no whitespace")
	// ErrBadReview is a review count below zero.
	ErrBadReview = errors.New("trace: review counts are zero or more")
)

Functions

func CarryState

func CarryState(body, from string) string

CarryState copies the block from holds into body as it is, bytes and all, where PutState would put a new one; a from without a block leaves body as it was. It is what a body rewritten from scratch with traces off does with the block the old body held: no block is written, and the one already there is not dropped.

func PutState

func PutState(body string, s State) (string, error)

PutState writes s into body: the first block is replaced where it is and any later one removed; a body without one gets the block appended after a blank line. Nothing else in the body changes.

func Render

func Render(t Trailers) (string, error)

Render writes the trailer lines in fixed order: every Task:, then Step:, then Review:, each newline-terminated. A zero value renders as "". It refuses a value Parse would not read back the same way.

func RenderState

func RenderState(s State) (string, error)

RenderState writes the block for s, one line, no trailing newline, with V set to StateVersion. It refuses a value ParseState would not read back the same way, or that would break the comment.

func Rewrite

func Rewrite(body string, u Update) (string, error)

Rewrite is PutState of Merge over the state body already holds: what a step does to a PR body.

func StripState

func StripState(body string) string

StripState removes every block from body, each with the line it had to itself and the blank line above it, for a commit message built from a PR body: the block describes the PR, not the commit.

Types

type Parsed

type Parsed struct {
	Trailers

	Steps   []string `json:"steps,omitempty"`
	Reviews []Review `json:"reviews,omitempty"`
}

Parsed is what Parse reads out of a whole message. A squash merge concatenates several commits, so every Step: and Review: line is kept in order; Step and Review are the last of each.

func Parse

func Parse(message string) Parsed

Parse reads every trailer line a message holds. Nothing in a message is an error: history nobody controlled is still read, and a message with no trailer parses to a zero value.

type Review

type Review struct {
	Round   int `json:"round"`
	Fixed   int `json:"fixed"`
	Skipped int `json:"skipped"`
}

Review is a resolve's fix commit in counts: the round it settled, and how many findings it fixed and skipped.

type State

type State struct {
	V      int      `json:"v"`
	Task   string   `json:"task,omitempty"`
	Riders []string `json:"riders,omitempty"`
	Step   string   `json:"step"`
	Round  int      `json:"round,omitempty"`
	Open   int      `json:"open,omitempty"`
	Asks   int      `json:"asks,omitempty"`
	After  string   `json:"after,omitempty"`
}

State is the hidden block a PR body carries: where the task stands now, as the last step that ran left it. Task is the lead's id, Riders the rest of a bundle, After the base task's id. Round, Open and Asks are a review's counts: the round, the findings awaiting a verdict, and the questions waiting on a person outside the run's own turn. The JSON key order is the struct's, which is the spec's.

func Merge

func Merge(prev State, u Update) State

Merge is the state a rewrite leaves: the update's step, task, riders and after, and each count from the update where it was passed, else from prev. A prev that was no state is the zero value, so nothing carries.

func ParseState

func ParseState(body string) (State, bool)

ParseState reads the first block a body holds. No block, JSON that does not parse, a version other than StateVersion, or a count below zero is no state, never an error: a body nobody controlled is still read. Unknown keys are ignored.

type Trailers

type Trailers struct {
	Tasks  []string `json:"tasks,omitempty"`
	Step   string   `json:"step,omitempty"`
	Review *Review  `json:"review,omitempty"`
}

Trailers is what one commit message says about its task and step. Tasks holds every member of a bundle, lead first; Step the step whose work the commit carries; Review the counts on a resolve fix.

func (Trailers) Zero

func (t Trailers) Zero() bool

Zero reports a value with nothing to write.

type Update

type Update struct {
	Step   string
	Task   string
	Riders []string
	After  string
	Round  *int
	Open   *int
	Asks   *int
}

Update is what one rewrite changes. Step, Task, Riders and After are set every time; a count left nil keeps the value the block already holds, and a count set to zero clears it.

Jump to

Keyboard shortcuts

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