prsnapshot

package
v0.175.5 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package prsnapshot is one bounded, single-observation read of a pull request's current state and check verdict: no poll loop, no confirming reread, no target-branch strict-freshness fence. It exists so `wb wait pr`'s own per-poll observation (cmd/wb/wait.go's former observePullRequest) and the herdr-session-transport daemon watcher (internal/prwatch) share exactly one implementation of "what does this pull request look like right now" — both already needed the identical renamed-required-check-aware logic (orchestrate.ObservePullRequestHead), and a caller keying a decision on that verdict must see the same one whichever command took the observation.

It never enforces the strict-freshness / candidate-contains-target fence orchestrate.WaitForPullRequestChecks (the merge-oriented logic behind `wb ci wait` and `wb pr land`) enforces: neither caller here merges anything, so a target branch simply advancing past this pull request's base is not this package's concern (herdr-session-transport Plan Task 6 review round 2, point 3).

Index

Constants

View Source
const (
	ReadsPerObservation         = 6
	ReadsPerInactiveObservation = 1
)

Reads of one observation, each a conditional (ETag) read of which a 304 answer is not charged to the rate limit. A test counts every one:

  • ReadsPerObservation: an open pull request, green, red or blocked: the pull request, its check runs, its Actions workflow runs, its commit statuses, the target's branch policy and its active rules. Naming a blocked required check reuses these reads.
  • ReadsPerInactiveObservation: a merged or closed pull request, lean only: the pull request alone, since the checks of a head that is no longer open are not read. Observe reads them as before.

Observe adds to the first the reads that explain a red head (see ObserveLean).

Variables

This section is empty.

Functions

This section is empty.

Types

type Snapshot

type Snapshot struct {
	Repository string
	Number     string
	// State is GitHub's raw pull-request state, exactly as the API reports
	// it: "open" or "closed". It is never rewritten to "merged" here — Merged
	// carries that fact instead, so a caller decides for itself how to
	// present the two together (cmd/wb/wait.go's waitTarget.State keeps its
	// own pre-existing "merged" overlay for backward compatibility; a new
	// caller such as internal/prwatch reads Merged directly).
	State     string
	Merged    bool
	Draft     bool
	Head      string
	Base      string
	Mergeable string
	URL       string
	// Checks and Failed are populated only while the pull request is open —
	// a closed pull request's head checks are no longer read at all.
	Checks   map[string]int
	Failed   []string
	Failures []orchestrate.CIFailureDetail
	// Blocked names a required check with no passing observation on this
	// head (orchestrate.HeadObservation.Blocked) — the renamed-workflow
	// trap. It is fetched only when nothing is pending or failed and Green
	// is still false, matching the same reserved-reads discipline the rest
	// of this observation follows.
	Blocked []string
	// Green is orchestrate.ObservePullRequestHead's own verdict: every
	// observed check passed or was skipped, AND the target's required-check
	// policy is fully satisfied. It is the one fact that decides pass vs.
	// fail; nothing in this package re-derives it from the check counts.
	Green bool
	Err   error
}

Snapshot is one observation of a pull request's current state: GitHub's own state/merged fact first, then — only while the pull request is still open — its head's check verdict. Err is set when the observation itself failed (a GitHub read error); every other field is then zero and must not be read.

func Observe

func Observe(ctx context.Context, repository, selector string) Snapshot

Observe takes exactly one observation of repository's pull request selector (a number or URL, as orchestrate.ReadPullRequest accepts it) — an exact head's checks, never a poll loop, never a confirming reread. A caller that needs a stable, confirmed terminal verdict takes a second observation itself, on its own outer cadence (`wb wait pr`'s bounded poll slice, or the daemon watcher's next tick), and compares the two; this package holds no state across calls.

func ObserveLean added in v0.175.0

func ObserveLean(ctx context.Context, repository, selector string) Snapshot

ObserveLean is Observe without the failure details: Failures stays empty. A caller that shows only that a check failed and its name (the cockpit fleet) saves the pull request, check, status and annotation reads that explaining a red head costs.

Jump to

Keyboard shortcuts

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