prroute

package
v0.193.0 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: MIT Imports: 6 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
const MaxBranchCandidates = 50

MaxBranchCandidates is how many branch names BranchCandidates reads from one text.

View Source
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

View Source
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

func BranchCandidates(text string) []string

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

func DistinctiveRef(ref string) bool

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 NamesAny added in v0.169.0

func NamesAny(ms []Mention, repo string, pr int64) bool

NamesAny reports whether any of ms names pull request pr of repo.

func NamesBranch added in v0.169.0

func NamesBranch(text, ref string) bool

NamesBranch reports whether text spells branch ref as a whole token: ref is one of BranchCandidates(text).

func ValidRef

func ValidRef(s string) bool

ValidRef reports whether s is a branch name this feature stores.

Types

type Kind

type Kind string

Kind is how a session authored a pull request.

const (
	// KindPRCreate: the session ran `gh pr create`, which printed the new pull
	// request's URL.
	KindPRCreate Kind = "gh-pr-create"
	// KindPush: the session ran `git push`, which named the remote repository
	// and a branch it updated.
	KindPush Kind = "git-push"
)

type Mention added in v0.169.0

type Mention struct {
	Owner, Repo string
	PR          int64
}

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

func Mentions added in v0.169.0

func Mentions(text string) []Mention

Mentions is the pull requests text names, in order of appearance (URLs first), distinct, at most MaxMentions. A bare "#N" is not one.

func (Mention) Names added in v0.169.0

func (m Mention) Names(repo string, pr int64) bool

Names reports whether m names pull request pr of repo ("<owner>/<name>", as session_prs stores it): the same name and number, and the same owner when m named one.

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

func ParseMail(body string) (Ref, bool)

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 Signal

type Signal struct {
	Kind    Kind
	Repo    string
	PR      int64
	HeadRef string
}

Signal is one authorship report: Repo and PR for KindPRCreate (HeadRef too when the create named its head branch), Repo and HeadRef for KindPush.

func (Signal) Valid

func (s Signal) Valid() bool

Valid reports whether s is a well-formed report: a known kind, a repo, a positive PR for a create (none for a push), a branch for a push (optional for a create), each in this package's grammar.

Jump to

Keyboard shortcuts

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