Skip to main content

Crate pr_review_core

Crate pr_review_core 

Source
Expand description

pr-review-core — reusable engine for an advisory AI PR reviewer.

Pulls a pull request’s diff, reviews it with a Claude model via OpenRouter, and posts a line-anchored inline review plus an advisory summary comment. Provider-agnostic across GitHub and Bitbucket. Bot identity and any extra prompt are injected through config::Config so consumers (bot binaries) supply their own branding.

Modules§

agent
Agentic reviewer: the model is given the PR diff plus read-only tools (read_file, list_dir, grep) over a clone of the repo, investigates cross-file context on its own, then returns the same structured review the diff-only path produces.
backend
Pluggable review backend: the seam that decides how a Review is produced from a PR’s diff and repo context.
blast
Blast radius: for the definitions a PR changes, find who calls them and which tests reference them, computed from the agent’s clone. This seeds the agentic reviewer with the cross-file context it would otherwise have to rediscover by hand (grep → read → repeat), and backs the references tool.
command
PR comment commands (T3.9): /review, /ask <question>, and /describe.
complexity
Deterministic complexity metrics for a PR’s changed functions — a cheap, LLM-free risk signal (idea borrowed from trusty-tools). For each function a change touches, we compute cyclomatic complexity (McCabe: 1 + decision points) and an approximate cognitive complexity (nesting-weighted count of control-flow structures, à la SonarSource), and grade it A–F.
config
Environment configuration, loaded once at process start.
deps
Dependency vulnerability scan (T3.8) via the OSV.dev API.
diff
Minimal unified-diff parser. Produces the set of line numbers (on the new side of each file) that appear in the diff, so we only anchor inline comments to lines the provider will accept — anchoring outside the diff is rejected (GitHub 422 / Bitbucket 400).
llm
OpenRouter chat-completions client. Sends the review prompt to a Claude model via OpenRouter and parses the structured review back.
prompt
The review prompt. Asks the model for a STRUCTURED JSON review so findings can be posted as inline comments anchored to file + line.
providers
Provider abstraction so the same review flow works against GitHub or Bitbucket. Enum dispatch (rather than dyn Trait) keeps the async methods object-safe without an async_trait dependency.
repo
Repo workspace for the agentic reviewer: a shallow clone of the PR head, plus the read-only tools the model uses to investigate cross-file context (read_file, list_dir, grep). All paths are sandboxed to the clone root.
repo_config
Per-repo config file (.prbot.toml) support.
review
Orchestrator: fetch the diff, run the structured AI review, anchor findings to diff lines, render a summary, and (unless dry-run) post the review.
structure
Structural context: tell the review model WHICH functions/symbols a PR’s changed lines belong to, computed cheaply from the diff (and, when possible, the full new-side files) without the agentic clone.
webhook
GitHub webhook helpers — signature verification and pull_request payload parsing. Kept separate from the HTTP layer so it’s easy to unit-test.

Constants§

VERSION
This crate’s version, for consumers that report which engine they are running.

Functions§

clip
Clip a string to at most n characters (char-safe — never splits a UTF-8 codepoint). Used to keep API error bodies short in messages.