Skip to content

About

Repository using Copilot AI harness to review pull requests within an organisation

Topics

Resources

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

🤖 GitHub Code Review Bot

Linux Foundation Source Code License OpenSSF Scorecard

Scheduled AI review of pull requests across the lfreleng-actions organisation, in two modes:

  • Approve. A reusable workflow selects open, human-authored, non-draft pull requests with green CI, runs one Copilot CLI review session per pull request, and approves the changes that are trivial or that a code review finds low risk. It posts nothing else: a pull request it cannot approve appears in the run report for a human, and the pull request itself stays untouched.
  • Antagonistic. On dispatch and every four hours, the same pipeline reads pull requests opened by coding bots (Code Monkey, the Copilot coding agent) as a hostile reviewer would, and posts its findings as one comment review with each finding on its line. It never approves: a maintainer still reviews and approves every pull request. A Code Monkey pull request with findings goes back to Code Monkey for a revision round, for three antagonistic rounds at most; after that a maintainer takes over. When a live run leaves a named or selected pull request without a review, it posts one notice comment saying why. A dispatch with review_human_authors on also reviews the named pull requests that an OWNER or MEMBER opened; those never go back for a revision round.

📚 Documentation

https://lfreleng-actions.github.io/github-code-review-bot/

Credential setup, validation and operating notes live in docs/setup/README.md. The design document covers the architecture, the trust model, the selection rules, the ledger and the data contracts.

How it works

select (trusted)       review (untrusted, matrix)      apply (trusted, matrix)
  App read token         model PAT alone                 verify evidence
  ledger + skip rules    packet + head checkout          corroborate, re-read
  selection.json ------> one JSON verdict ------------>  approve or report
  1. Select fetches the prior ledger, scans the organisation (or the pull requests named in a dispatch), drops drafts, bot authors, red or pending CI, conflicts, pull requests already approved or awaiting Copilot, and heads a previous run assessed. It records a bounded packet per survivor: metadata, commits, CI, reviews and every file's diff.
  2. Review runs once per pull request on its own runner with the model credential alone, egress blocked to the hosts a review session needs, and no sudo or Docker. The agent reads the packet and an unprivileged checkout of the head commit and emits one verdict: trivial, low-risk or needs-human, with a summary and findings.
  3. Apply verifies the evidence, corroborates a trivial claim with a deterministic classifier, holds back any verdict that reports a finding or an injection attempt, applies hard vetoes (new write permissions, unpinned actions, new secrets, pull_request_target, workflow_run, removed action inputs, curl | sh), re-reads the live pull request and, on the live path alone, mints a pull-requests: write token for that one repository and posts an APPROVE review marked as automated.
  4. Report gathers every result through a bounded fetch into a run report and publishes the next run's ledger, which records a result when the run's apply job provably uploaded it.

In the antagonistic mode, Select keeps the listed bots' pull requests instead of humans', the agent emits findings anchored to diff lines rather than a tier, and Apply checks each anchor against the diff and posts one COMMENT review under a second App that never approves. A separate job then hands Code Monkey's reviewed pull requests back to it for revision, under a three-round cap. In a live run, two more jobs list the pull requests the run left without a review and post one notice comment on each, under the same App. See docs/DESIGN.md §19.

Schedule and dispatch

code-review-cron.yaml runs every three hours on weekdays and twice a day at weekends, and stays in dry-run until the rollout in the design document clears it. A manual dispatch chooses the model, an optional reasoning effort and AI credit cap for each session, the approvable tiers, a cap, and either repositories to scan or specific pull requests to review:

pypi-version-check-action/pull/157, pypi-version-check-action/pull/158
pypi-version-check-action#157 lfreleng-actions/pypi-version-check-action#158

code-review-antagonistic.yaml runs on dispatch, defaulting to GPT-6 Astra and a dry run; Code Monkey dispatches it for its own pull requests once their Copilot review is clean. It also scans live every fourth hour at minute 41, for a bot pull request that turned clean outside a Code Monkey run, with the same selection rules and caps, once the ANTAGONISTIC_SCAN_ENABLED repository variable is true; dispatches run whatever its value. To dispatch by hand:

gh workflow run code-review-antagonistic.yaml \
  -f dry_run=false -f pull_requests='repo#12'

Reusable workflow

jobs:
  code-review:
    permissions:
      pull-requests: read
      contents: read
      actions: read
    # Pin to an immutable release commit SHA; the tag rides along as a
    # comment. The trusted jobs receive your App private key.
    # yamllint disable-line rule:line-length
    uses: lfreleng-actions/github-code-review-bot/.github/workflows/code-review.yaml@<commit-sha>  # vX.Y.Z
    with:
      org: 'your-org'
      mode: 'approve'  # or 'antagonistic' with approve_tiers: 'none'
      dry_run: true
      approve_tiers: 'trivial,low-risk'
      harden_runner_allowlist: '@<allow-list commit sha>'
      # harden_runner_supplemental_allowlist: 'your-org/.github@<sha>'
      # harden_runner_supplemental_unpinned: false
      # harden_runner_extra_endpoints: 'example.com:443'
      github_app_client_id: ${{ vars.YOUR_APP_CLIENT_ID }}
    secrets:
      copilot_token: ${{ secrets.COPILOT_CLI_TOKEN }}
      github_app_private_key: ${{ secrets.YOUR_APP_PRIVATE_KEY }}

Live runs need a GitHub App installed on the organisation with the permissions in the setup guide, a second App for the antagonistic mode, and a personal fine-grained PAT carrying Copilot Requests and no repository grants.

Development

uv run python -B -m unittest discover -s tests -v
prek run --all-files
zizmor --persona auditor .github/workflows/

Fuzzing

Two Atheris harnesses under fuzz/ feed untrusted agent text to the code that judges it. fuzz_verdict.py covers verdict extraction and the sanitisers in review_policy.py. fuzz_comment.py covers the comment Markdown pass in comment_markdown.py and the containment comment_body.py adds before posting. Each harness names the documented contract it checks. tests/test_fuzz_harnesses.py replays every seed in the normal suite, without Atheris. To fuzz by hand, install Atheris outside this project and run a harness from the repository root:

pip install atheris
python fuzz/fuzz_verdict.py -max_total_time=60   # fuzz from its seeds
python fuzz/fuzz_comment.py crash-<hash>         # replay one input

About

Repository using Copilot AI harness to review pull requests within an organisation

Topics

Resources

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Used by

Contributors

Languages