Skip to content

Support trusted pull_request_target and repository_dispatch review callers - #54

Merged
FlyOverCoderKY merged 1 commit into
mainfrom
t3/openrouter-pr-target-support
Nov 6, 2026
Merged

FlyOverCoderKY merged 1 commit into
mainfrom
t3/openrouter-pr-target-support

Conversation

@FlyOverCoderKY

Copy link
Copy Markdown
Contributor

Summary

Adds two optional, default-branch caller events to the shared OpenRouter review workflow. Existing pull_request and workflow_dispatch callers keep their current job selection, permissions, and behavior.

  • pull_request_target (opened, reopened, ready_for_review, synchronize) keeps the pull_request first-pass / follow-up split. It runs only for PRs that target the default branch.
  • repository_dispatch from the default branch is a first pass, like workflow_dispatch. Callers map client_payload into with: (pr_number, review_level, and the new optional expected_head_sha). The reusable workflow never reads client_payload directly.
  • review-config resolves the PR number, pass, and event head/base/before SHAs explicitly and rejects a PR number that differs from the triggering PR. github.sha is never treated as the PR head.
  • Head-bound gate check. The gate exposes gate_pr_number, gate_head_sha, gate_conclusion, and gate_review_url outputs. The new openrouter-review-gate-check.yml entry point publishes that result (success or failure) as a GitHub Actions check run named review / openrouter-first-pass-gate (configurable via gate_check_name) on the exact head the gate evaluated.

Permissions compatibility

All six current org callers grant actions: write, contents: read, pull-requests: write, and statuses: write at the top level, with no job override and no checks: write. GitHub checks reusable-job permissions before runtime conditions, so a checks: write job inside openrouter-code-review.yml would reject those callers on their next pin bump. The check publisher is therefore its own entry point and the only job that requests checks: write. The review workflow requests no scope beyond what callers grant today, and a contract test enforces that.

Where checks land

On public repositories, GitHub records pull_request_target runs (head_sha, head_branch, and the check suite) on the PR head. The native gate job check therefore already reports on the reviewed commit. Default-branch dispatch runs record the default-branch tip instead. In auto mode the publisher acts only for those runs. It publishes only from default-branch refs and skips a head that moved after evaluation.

Checkout isolation

Jobs that hold the OpenRouter key keep the reviewed head as inert data:

  • persist-credentials: false, with submodules and LFS explicitly off.
  • No local actions and no package scripts.
  • Python runs with -P and a trusted PYTHONPATH. Git only reads objects.
  • A reviewed commit that contains the reserved .trusted-review-org or .trusted-review-action paths (including a symlink) is refused before the trusted checkouts.

Profile provenance

Python (profile_github, profile_completion, profile_requests, profile_gate) and profile_consumer.mjs stay aligned:

  • repository_dispatch must run on the default branch, and the caller blob at the run's default-branch commit must match the trusted caller.
  • pull_request_target runs report the PR head, not the commit whose caller ran. The caller is proven through the head branch: every same-repository PR from that branch must target the default branch with no BASE_REF_CHANGED_EVENT or AUTOMATIC_BASE_CHANGE_SUCCEEDED_EVENT. The run also needs the exact reusable pin, a run head equal to the receipt head, and a PR whose head branch matches the run. A receipt for an older head never satisfies a newer one.
  • Explicit deep / cancel still require a maintainer and a default-branch dispatch (workflow_dispatch or repository_dispatch).
  • The Node consumer now also requires pull-request review runs to match the receipt head. Python already enforced this.
  • Bot-sent repository_dispatch reviews wake profile completion the same way bot-sent workflow_dispatch reviews do.

Tests

  • python -m unittest discover -s tests: 155 tests (was 114). New coverage includes:
    • legacy pull_request / workflow_dispatch job selection, evaluated from the workflow if: expressions;
    • both new events, their first-pass / follow-up split, and dispatch event types that never act as PR actions;
    • rejection of non-default-branch dispatches, retargeted or non-default bases, stale heads, mismatched PR numbers or head branches, and untrusted events;
    • the PR-context step and the gate's head and conclusion outputs, run under bash;
    • the reserved-path guard.
  • node --test: 55 tests (was 37), including the new gate-check.test.mjs (payload, name, SHA, update-in-place, auto/always modes, moved heads, forged inputs).
  • actionlint 1.7.12 passes on all three workflows.

No caller changes are required. Callers adopt the new events by advancing their pin and adding the second job shown in the README.

🤖 Generated with Claude Code

…llers

The reusable review workflow now admits two default-branch caller events
alongside pull_request and workflow_dispatch, which keep their current job
selection, permissions, and behavior.

- pull_request_target (opened, reopened, ready_for_review, synchronize)
  keeps the first-pass / follow-up split and runs only for PRs that target
  the default branch.
- repository_dispatch from the default branch is a first pass. Callers map
  client_payload into pr_number, review_level, and the new optional
  expected_head_sha input, which fails the review and gate closed when the
  live PR head moved.
- A new review-config step resolves the PR number, pass, and event head,
  base, and before SHAs explicitly, and rejects mismatched PR numbers.
- The gate exposes the evaluated head and conclusion as gate_* workflow
  outputs. The new openrouter-review-gate-check.yml entry point publishes
  that result as a GitHub Actions check run on the exact evaluated head for
  default-branch dispatch runs. It is the only job that requests
  checks: write, so existing callers keep working without new scopes.
- Reviewed checkouts stay inert data: submodules and LFS are explicitly
  off, and a commit containing the reserved trusted checkout paths is
  refused.
- Bot-sent repository_dispatch reviews wake profile completion like
  bot-sent workflow_dispatch reviews.

Profile provenance (Python and the Node consumer) admits the new events.
repository_dispatch runs must be on the default branch with a matching
caller blob. pull_request_target runs report the PR head, so their caller is
proven through the head branch: every same-repository PR from it must
target the default branch with no recorded base change. They also need the
exact reusable pin, a run head equal to the receipt head, and a matching PR
head branch. The Node consumer now also requires pull-request review runs
to match the receipt head.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@FlyOverCoderKY
FlyOverCoderKY merged commit a40c5eb into main Nov 6, 2026
8 checks passed
@FlyOverCoderKY
FlyOverCoderKY deleted the t3/openrouter-pr-target-support branch November 6, 2026 18:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant