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.
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 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.