item

package
v0.2.0 Latest Latest
Warning

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

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

Documentation

Overview

Package item is the work item: one document per unit of work (ADR-002), moved through the state machine by the decider (ADR-006).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IssueKey

func IssueKey(host, repo string, number int) string

IssueKey is the store key for a GitHub issue's item on the forge at host.

func Key

func Key(t tracker.Ref) string

Key is the store key for an item: item/<host>/<the tracker's own key>, with a GitHub key as a path, so identity is the system's own and never a configured name (ADR-002).

func PRKey

func PRKey(host, repo string, number int) string

PRKey is the store key for an adopted pull request's item: the pull request is the work.

Types

type Item

type Item struct {
	Key    string      `json:"key"`
	Kind   string      `json:"kind"` // originate or adopt
	Lane   string      `json:"lane"`
	Ticket tracker.Ref `json:"ticket"`
	Forge  string      `json:"forge"` // the code's forge host: github.com
	Repo   string      `json:"repo"`  // owner/name on Forge
	// Number is the GitHub issue or pull request number when the ticket is one; 0 otherwise.
	Number int    `json:"number,omitempty"`
	State  State  `json:"state"`
	Reason string `json:"reason,omitempty"`
	Branch string `json:"branch,omitempty"`
	PR     int    `json:"pr,omitempty"`
	PRHead string `json:"pr_head,omitempty"`
	// CICountedSHA is the head commit whose failing CI the failure counters already include, so a
	// failure that stays failed across polls is counted once. Empty until a failure is counted.
	CICountedSHA string `json:"ci_counted_sha,omitempty"`
	// NoCI is when ynf first saw the head commit with no check or status at all, kept only while
	// that is true: the decision to escalate reads it.
	NoCI     *NoCI `json:"no_ci,omitempty"`
	Attempts int   `json:"attempts"`
	// Counters are the deterministic counters decisions read (ADR-008): reaction retries and
	// per-signature failures.
	Counters map[string]int `json:"counters,omitempty"`
	LastRun  *Run           `json:"last_run,omitempty"`
	Feedback string         `json:"feedback,omitempty"` // what the next run is told, e.g. CI output
	NextDue  *time.Time     `json:"next_due,omitempty"`
	Lease    *Lease         `json:"lease,omitempty"`
	// Trace is where the item's history can be followed in telemetry (ynr ADR-002).
	Trace   *Trace    `json:"trace,omitempty"`
	Created time.Time `json:"created"`
	Updated time.Time `json:"updated"`
}

Item is the work item document. It has two references (ADR-002): its ticket, what the work is, and its code, where the change goes: a forge host, a repository, and its branch and pull request.

func (Item) BranchName

func (it Item) BranchName() string

BranchName is the deterministic branch ynf uses for an originated item (ADR-005: idempotent side effects): ynf/issue-77 for a GitHub issue, ynf/plat-881 for a key from elsewhere, and ynf/adhoc-<the id's last 8> for work started from a prompt.

func (*Item) Bump

func (it *Item) Bump(name string) int

Bump increments a counter on a copy-safe map.

func (Item) Counter

func (it Item) Counter(name string) int

Counter returns a counter's value.

func (Item) Ref

func (it Item) Ref() string

Ref is how people name the item: github.com/eyelock/ynh#77.

func (Item) Subject

func (it Item) Subject() string

Subject is the event subject for an item: its ticket's reference.

type Lease

type Lease struct {
	Owner     string    `json:"owner"`
	Epoch     int64     `json:"epoch"`
	StepID    string    `json:"step_id"`
	Acquired  time.Time `json:"acquired_at"`
	ExpiresAt time.Time `json:"expires_at"`
}

Lease is an exclusive claim (ADR-005).

func (*Lease) Held

func (l *Lease) Held(now time.Time) bool

Held reports whether the lease is live at now.

type NoCI

type NoCI struct {
	SHA   string    `json:"sha"`
	Since time.Time `json:"since"`
}

NoCI marks a head commit that has had no check or status of any kind since Since.

type Run

type Run struct {
	ID       string    `json:"id"`
	Outcome  string    `json:"outcome"`
	Changed  []string  `json:"changed,omitempty"`
	Detail   string    `json:"detail,omitempty"`
	Finished time.Time `json:"finished"`
}

Run is the last run's result, as the decider needs it.

type SpanRef

type SpanRef struct {
	TraceID string `json:"trace_id"`
	SpanID  string `json:"span_id"`
}

SpanRef names a span by its trace id and span id, as lowercase hex.

type State

type State string

State is a work item's place in the state machine.

const (
	Intake      State = "intake"
	Ready       State = "ready"
	Running     State = "running"
	Proposed    State = "proposed"  // pull request open, waiting on CI
	InReview    State = "in_review" // CI green, waiting on a human
	Done        State = "done"      // merged
	Closed      State = "closed"    // ticket or pull request closed without merging
	Escalated   State = "escalated" // a human must decide
	Quarantined State = "quarantined"
	Ignored     State = "ignored"
)

States, in the order an originated item usually moves through them.

func (State) Final

func (s State) Final() bool

Final reports whether the item is finished for good.

func (State) Settled

func (s State) Settled() bool

Settled reports whether ynf has nothing more to do without a human or an outside change.

type Trace

type Trace struct {
	// Step is the last step's span, which the next step links to.
	Step *SpanRef `json:"step,omitempty"`
	// Intake is the ynf.intake span of an event recorded for the item that no step has linked to
	// yet, such as a detached start's, which a later step in another process picks up.
	Intake *SpanRef `json:"intake,omitempty"`
}

Trace holds the span ids that link an item's history across steps and processes, kept in the store beside the item so it works on every provider. Nothing in ynf reads telemetry back: these are ids ynf wrote, used only to make span links.

Jump to

Keyboard shortcuts

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