Documentation
¶
Overview ¶
Package onair answers one question - which commit is actually running - by comparing three truth tiers: HEAD (latest commit on the tracked branch), Green (latest commit whose CI pipeline passed) and Live (what the running artifact reports about itself).
The core is pure: it asks abstract questions through three seams - Forge (git + CI truth), LiveProvider (what is running, per component) and Identity (who is viewing, for attribution) - and returns a Report. Rendering lives in package render, concrete providers in packages gitlab and live, and wiring in cmd/onair. Host applications import this package directly, wire their own providers and render the Report however they like.
Index ¶
- func LooksLikeSHA(s string) bool
- func SameSHA(a, b string) bool
- func Serving(state string) bool
- func ShortSHA(sha string) string
- type AttributionMode
- type CommitInfo
- type Component
- type ComponentReport
- type Drift
- type Forge
- type ForgeInfo
- type GreenInfo
- type Identity
- type LiveConfidence
- type LiveInfo
- type LiveProvider
- type LiveReport
- type Params
- type Ref
- type Report
- type Rollout
- type RolloutReport
- type RolloutStatus
- type TaskConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func LooksLikeSHA ¶
LooksLikeSHA reports whether s has the shape of a full or abbreviated commit SHA (7 to 40 hex characters), as opposed to a tag or an image ref.
func SameSHA ¶
SameSHA reports whether two SHAs name the same commit, tolerating abbreviated forms: a probe typically reports a short SHA while a forge returns the full one. Anything shorter than 7 hex characters must match exactly - prefixes that short are not trustworthy.
Types ¶
type AttributionMode ¶
type AttributionMode string
AttributionMode gates the "yours" annotations.
const ( // AttributionOff - never annotate. AttributionOff AttributionMode = "off" // AttributionOn - always annotate against the configured identity. AttributionOn AttributionMode = "on" // AttributionAuto - annotate only if the viewer's email resolves to a // known git author in recent history; the noise disappears for people it // means nothing to. AttributionAuto AttributionMode = "auto" )
type CommitInfo ¶
type CommitInfo struct {
SHA string `json:"sha"`
Subject string `json:"subject,omitempty"`
Author string `json:"author,omitempty"`
AuthorEmail string `json:"-"`
At time.Time `json:"at,omitzero"`
URL string `json:"url,omitempty"`
Request string `json:"request,omitempty"` // e.g. "!1234"
RequestURL string `json:"requestUrl,omitempty"` // MR / PR link
TaskID string `json:"taskId,omitempty"` // e.g. "PROJ-123"
TaskURL string `json:"taskUrl,omitempty"`
Mine bool `json:"mine,omitempty"`
}
CommitInfo is a commit as the report presents it. Author emails are kept out of the JSON on purpose - the report is often shown beyond the dev team.
type Component ¶
type Component struct {
Name string
Live LiveProvider // nil -> Assumed
}
Component is a named deployable unit (backend, web, worker...) with its own live source.
type ComponentReport ¶
type ComponentReport struct {
Name string `json:"name"`
Live *LiveReport `json:"live"`
Error string `json:"error,omitempty"`
}
ComponentReport is one component's Live answer. Live is nil only when nothing could be established at all (no provider and no Green to assume).
type Drift ¶
type Drift struct {
// Leader is the most-ahead component; the others are measured against it.
Leader string `json:"leader"`
Message string `json:"message"` // e.g. "web 1 behind backend"
}
Drift flags components that report different Live commits when they should move together (your backend shipped, your web didn't).
type Forge ¶
type Forge interface {
// Head returns the latest commit on the tracked branch (the HEAD tier).
Head(ctx context.Context, branch string) (Ref, error)
// LatestGreen returns the newest commit on branch whose CI pipeline
// passed (the Green tier).
LatestGreen(ctx context.Context, branch string) (Ref, error)
// Resolve returns full commit metadata for a SHA, short SHA or tag.
Resolve(ctx context.Context, sha string) (Ref, error)
// Behind counts how many commits `to` has that `from` does not.
Behind(ctx context.Context, from, to string) (int, error)
// Recent returns up to limit latest commits on branch. Used by the
// attribution auto-gate to build the recent-history author set.
Recent(ctx context.Context, branch string, limit int) ([]Ref, error)
// CommitURL returns a browsable URL for a commit.
CommitURL(sha string) string
// RequestURL returns a browsable URL for a merge/pull request id.
RequestURL(id string) string
}
Forge is the umbrella seam for a git host (GitLab, GitHub, Gitea...). It answers the abstract questions every host can answer; concrete implementations are swappable, so GitLab-first does not mean GitLab-only.
type ForgeInfo ¶
type ForgeInfo struct {
Kind string `json:"kind"`
Host string `json:"host,omitempty"`
Repo string `json:"repo"`
Branch string `json:"branch"`
}
ForgeInfo describes the forge for the report header; it carries no behavior.
type GreenInfo ¶
type GreenInfo struct {
CommitInfo
Pipeline string `json:"pipeline,omitempty"`
BehindHead int `json:"behindHead,omitempty"`
}
GreenInfo is the Green tier: the latest commit with a passing pipeline.
type Identity ¶
type Identity interface {
// ViewerEmails returns the viewer's known emails; may be empty.
ViewerEmails(ctx context.Context) ([]string, error)
}
Identity answers who is viewing the report, for "yours" attribution. The CLI reads git config user.email; a host application hands in the logged-in user's email.
type LiveConfidence ¶
type LiveConfidence string
LiveConfidence states how much we actually know about the Live tier. It is a first-class field, not a boolean, so the renderer can be honest. Ranked highest first: Probed, Reported, Recorded, Assumed.
const ( // Probed - the running artifact self-reported its commit (highest // fidelity). Probed LiveConfidence = "probed" // Reported - a user-supplied command asserted the running commit; truth // we did not observe ourselves. Reported LiveConfidence = "reported" // Recorded - the forge's deployment record for an environment: the commit // CI deployed, not what the host runs now. Recorded LiveConfidence = "recorded" // Assumed - no live source at all; Green stands in, clearly labeled. Assumed LiveConfidence = "assumed" )
func (LiveConfidence) Weaker ¶
func (c LiveConfidence) Weaker(other LiveConfidence) bool
Weaker reports whether c is a weaker claim than other. An unknown confidence ranks weakest, so it never passes for a stronger one.
type LiveInfo ¶
type LiveInfo struct {
// SHA is a full or short commit SHA, or anything the Forge can resolve
// to one (a tag, an image-ref suffix).
SHA string
BuiltAt time.Time // zero when the provider cannot know
// State is the container state as the provider reported it, verbatim.
// Empty (unknown), "running" and "healthy" mean serving; see Serving.
State string
Confidence LiveConfidence
// Rollout is a deploy newer than SHA that has not succeeded; nil when
// there is none or the provider cannot see deploys.
Rollout *Rollout
}
LiveInfo is what a LiveProvider can know on its own: a commit-ish and, sometimes, when it was built, the container's state and a newer deploy that has not succeeded. The engine resolves the rest through the Forge.
type LiveProvider ¶
LiveProvider answers what is actually running for one component. A nil provider means the Assumed fallback: Live is taken to be Green, labeled as an assumption - the engine implements that itself because only it knows Green.
type LiveReport ¶
type LiveReport struct {
CommitInfo
Confidence LiveConfidence `json:"confidence"`
BuiltAt time.Time `json:"builtAt,omitzero"`
// State is the provider-reported container state, absent when unknown or
// when Live is assumed from Green.
State string `json:"state,omitempty"`
BehindGreen int `json:"behindGreen,omitempty"`
BehindHead int `json:"behindHead,omitempty"`
// Rollout is a newer deploy that is pending or failed.
Rollout *RolloutReport `json:"rollout,omitempty"`
}
LiveReport is the Live tier for one component, with its confidence and how far it lags the other tiers. Keep the numbers separate: Live is N behind Green is M behind HEAD - never collapse them.
func (*LiveReport) Serving ¶
func (l *LiveReport) Serving() bool
Serving reports whether this Live is serving traffic: true unless the provider reported a state other than running or healthy.
type Params ¶
type Params struct {
Project string
Environment string
Forge Forge
ForgeInfo ForgeInfo
// Branch is the tracked branch, default "main"; Collect copies it into
// the report's Forge.Branch.
Branch string
Components []Component
Identity Identity // nil -> no attribution
Attribution AttributionMode // default AttributionAuto
// Identities is the alias map: one person, many emails (work vs
// personal, forge noreply). Any match pulls in the whole group.
Identities map[string][]string
Task *TaskConfig
// RecentLimit is how deep the attribution auto-gate looks for authors;
// default 50.
RecentLimit int
}
Params configures a single Collect run: one project, one environment.
type Ref ¶
type Ref struct {
SHA string
Subject string
AuthorName string
AuthorEmail string
At time.Time
URL string
}
Ref is a resolved commit reference on the tracked branch.
type Report ¶
type Report struct {
Project string `json:"project"`
Environment string `json:"environment"`
// Forge.Branch is always the branch Collect tracked.
Forge ForgeInfo `json:"forge"`
Head *CommitInfo `json:"head,omitempty"`
Green *GreenInfo `json:"green,omitempty"`
Components []ComponentReport `json:"components"`
Drift *Drift `json:"drift"`
Attribution AttributionMode `json:"attribution"`
// Errors carries degradation notes (a tier that could not be fetched, an
// identity lookup that failed). A failed provider is on its component's
// Error instead. Presence of errors never prevents a report: degrade
// gracefully, render something useful.
Errors []string `json:"errors,omitempty"`
}
Report is the core's whole output and a public API: its JSON shape only changes additively. Rendering it is the host's job - the CLI's tty renderer and an admin popover are just two consumers.
type Rollout ¶
type Rollout struct {
SHA string
Status RolloutStatus
StartedAt time.Time // zero when unknown
}
Rollout is a deploy of SHA that is in flight or failed.
type RolloutReport ¶
type RolloutReport struct {
CommitInfo
Status RolloutStatus `json:"status"`
StartedAt time.Time `json:"startedAt,omitzero"`
}
RolloutReport is a deploy newer than Live that has not succeeded.
type RolloutStatus ¶
type RolloutStatus string
RolloutStatus is the state of a deploy that is not (yet) live.
const ( // RolloutPending - the deploy is running. RolloutPending RolloutStatus = "pending" // RolloutFailed - the deploy failed, so the older Live commit kept running. RolloutFailed RolloutStatus = "failed" )
type TaskConfig ¶
type TaskConfig struct {
// Pattern is a regexp matched against the commit subject; the whole
// match is the task id (e.g. `PROJ-\d+`).
Pattern string
// URL is the link template; "{id}" is replaced with the matched id.
URL string
}
TaskConfig links task-tracker ids found in commit subjects (Jira, Linear, ...) to their URLs. Ported as-is from Ruby onair's task: config.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
onair
command
Command onair answers "which commit is actually running" for the project described by .onair.yml.
|
Command onair answers "which commit is actually running" for the project described by .onair.yml. |
|
Package config loads and validates .onair.yml.
|
Package config loads and validates .onair.yml. |
|
Package gitlab implements the onair.Forge seam against the GitLab REST API.
|
Package gitlab implements the onair.Forge seam against the GitLab REST API. |
|
Package live provides the host-side LiveProvider implementations: probe (the /-/version convention), command (the universal adapter - any CLI's output is the answer) and static (a ref handed in directly, e.g.
|
Package live provides the host-side LiveProvider implementations: probe (the /-/version convention), command (the universal adapter - any CLI's output is the answer) and static (a ref handed in directly, e.g. |
|
Package render turns a Report into output.
|
Package render turns a Report into output. |