Documentation
¶
Overview ¶
Package prroute is deterministic PULL-REQUEST → SESSION routing's pure half: which pull request a review mail is about (ParseMail), and the shape of an authorship report (Signal) — which pull request a session created, or which branch it pushed — as a host's PostToolUse hook sends it to POST /api/pr-sessions (internal/api/pr_routes.go). It holds no store and makes no network call. docs/plugins.md#a-pull-request-review-mail.
Index ¶
Constants ¶
const MaxBranchCandidates = 50
MaxBranchCandidates is how many branch names BranchCandidates reads from one text.
const MaxMentions = 20
MaxMentions is how many pull-request mentions Mentions reads from one text: a message is bounded work however many it spells.
const MaxReviewFindings = 50
MaxReviewFindings bounds Review.Findings: the gate keeps a handful per lane, and the paste has a size cap.
Variables ¶
var ( // RepoPattern is a repository as the mail and a transcript name it. RepoPattern = regexp.MustCompile(`^[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+$`) )
Functions ¶
func BranchCandidates ¶ added in v0.169.0
BranchCandidates is every distinctive branch name (DistinctiveRef) text spells as a whole token, distinct, at most MaxBranchCandidates, in order. A token is a run of branch-name bytes, read from its start or from just after "refs/heads/", "/tree/" or "...", up to its end or to a "..."; a trailing '.' ends a sentence, not the name. So "feat/x" is spelled by "feat/x.", "refs/heads/feat/x", "github.com/o/r/tree/feat/x" and "main...feat/x", but not by "feat/x-2", "origin/feat/x" or "feat/x.v2". Case-sensitive, as git's names are.
func DistinctiveRef ¶ added in v0.169.0
DistinctiveRef reports whether branch ref is one a message can name: a stored branch name (ValidRef) at least five bytes long that holds a '/', a digit, or — split on '-' and '_' into two or more parts — a part of three or more letters that is not a dictionary word. Never "main", "master", "develop", "follow-up", "read-only" or "gh-pages".
func NamesBranch ¶ added in v0.169.0
NamesBranch reports whether text spells branch ref as a whole token: ref is one of BranchCandidates(text).
Types ¶
type Finding ¶ added in v0.211.0
type Finding struct {
// ID is the finding's short id, "f_" and 12 lower-case hex.
ID string
// Severity is the finding's severity (lower-case letters), "" when absent
// or not one.
Severity string
}
Finding is one finding's id and severity, both validated: muster prints them OUTSIDE the untrusted fence (internal/api's hqReviewPreface), so only text in these grammars is kept.
type Mention ¶ added in v0.169.0
Mention is a pull request a text names. Owner is "" when the text named the repository alone ("infra-config#12"). Owner and Repo are lower-cased (GitHub's names are case-insensitive).
type Ref ¶
type Ref struct {
// Repo is "<owner>/<repo>", lower-cased (GitHub's names are case-insensitive).
Repo string
// PR is the pull request's number.
PR int64
// HeadSHA is the reviewed head commit (40 lower-case hex).
HeadSHA string
// HeadRef is the pull request's head branch, "" when the mail names none.
HeadRef string
}
Ref is the pull request a review mail names.
func ParseMail ¶
ParseMail is the pull request mail body names, read from the LAST fenced ```json block of the body. ok is false for anything malformed — no such block, invalid JSON, a missing or invalid repo, pr or head_sha, or a head_ref that is present and not a branch name — and the caller then routes nothing by it.
🔴 THE LAST BLOCK DECIDES, AND AN EARLIER ONE IS NEVER A FALLBACK: the gate writes its machine-readable block last, and a body may quote other JSON before it (a finding's excerpt). A fence is matched as CommonMark matches it — closed only by a backtick run at least as long as the one that opened it — so a block the gate fenced with more backticks than any run inside it is read whole, and a fenced block of another kind hides what is inside it.
type Review ¶ added in v0.211.0
type Review struct {
Ref
// ReviewID is the block's review_id, "" when it is absent or not in
// reviewIDPattern.
ReviewID string
// Findings is the block's findings that carry a well-formed id, in the
// block's order, at most MaxReviewFindings.
Findings []Finding
// Listed is how many entries the block's findings array holds, ids or
// not: whether the round HAS findings, which Findings (well-formed ids
// only, bounded) cannot tell. 0 for a round with none — its mail asks
// nothing to answer finding by finding — and 0 when FindingsKnown is false.
Listed int
// FindingsKnown says the block HAS a findings key holding a JSON array.
// Without it — the key missing, or a value of another shape — whether the
// round has findings is UNKNOWN, never "none": Listed 0 then proves
// nothing.
FindingsKnown bool
}
Review is what a review mail's machine block says beyond Ref: the round's id and its findings' short ids — what HQ's PR-review respond channel takes (`finding` as the short id WITH `pr`) to answer one.
func ParseReview ¶ added in v0.211.0
ParseReview is ParseMail with the round's review_id and its findings' ids: ok exactly when ParseMail's is (the same block, the same rules). A finding without a well-formed id is left out, never repaired; a review_id or severity outside its grammar reads as "".