跳到正文
DEV Community· Gaurav Sharma·· 4 小時前AI 評分64

MergeJudge 如何在 GitHub 為 AI 智能體的 Pull Request 設置審查門檻(毋須逐行閲讀)

How to gate AI agent pull requests on GitHub (without reading every line)

AI 導讀

這篇教學示範如何用作者自建的 MergeJudge 在 GitHub 為 AI 智能體提交的 Pull Request 設置審查門檻,依確定性規則分為 auto、review 或 block,AI 只能提高、不能放寬風險級別。

正文

Coding agents open more pull requests than people can read line by line. The goal isn't to read less — it's to spend human attention on the PRs that actually need it, and to make sure no agent can merge, or loosen the review rules, on its own.

If "good enough to merge" means "whatever the model thinks today", you get noisy line comments, and nothing stops an agent PR from quietly editing the instructions or workflow files it's reviewed with.

This walkthrough sets up AI pull request review where the repository holds the rules:

  1. Deterministic rules put every PR in a lane: auto (low risk), review (a human must look) or block.
  2. An AI model reads the diff and adds line comments, but can only make the lane stricter, never looser.
  3. The rules and policy are read from the base branch, never from the PR branch.

I'll use MergeJudge, an AI pull request reviewer with an open-source (MIT) engine I built for this, as the example. Disclosure up front: it's my project. The core ideas — base-branch config, a deterministic rules floor, and human-merged rule changes — carry over to any setup.

Real examples on GitHub (no install needed)

Before setting anything up, you can see what the output looks like on three real PRs:

Option A: Two-click GitHub App (free AI reviews on public repos)

If you don't want to manage YAML or keys first, install the GitHub App from https://mergejudge.si/guide/cloud. Public repositories get up to 10 free AI reviews per month out of the box with no API key and no config file. For private repos or higher volume, bring your own key or run the local CLI runner (npx mergejudge-runner setup), which uses your existing Claude Code or Codex login.

Option B: Self-hosted GitHub Action (no MergeJudge account)

If you want everything to run inside your own GitHub Actions runner with no MergeJudge account:

Step 1: Add your provider key as a repo secret

Pick Anthropic, OpenAI, z.ai or any OpenAI-compatible endpoint:

gh secret set AI_API_KEY

(Or set provider: none to run deterministic rules only with no key.)

Step 2: Add .github/workflows/mergejudge.yml

name: MergeJudge
on:
  pull_request:
    types: [opened, synchronize, reopened, ready_for_review, labeled, unlabeled]
permissions:
  contents: read
  pull-requests: write
  checks: write
jobs:
  lane:
    if: github.event.pull_request.head.repo.full_name == github.repository
    runs-on: ubuntu-latest
    steps:
      - uses: gauravsharmaGG/mergejudge-runner@v1
        env:
          AI_API_KEY: ${{ secrets.AI_API_KEY }}
        with:
          provider: anthropic        # or openai, zai, openai-compatible, none
          model: claude-sonnet-4-5   # any model your provider supports

Open a PR and you get one sticky summary comment, a mergejudge/lane check (success = auto, neutral = review, failure = block) and inline comments on the diff.

Step 3: Put non-negotiable paths in .mergejudge.yml on your default branch

Anything that always requires a human — like .github/**, auth, or database migrations — shouldn't depend on a prompt noticing it:

lanes:
  protected:
    - ".github/**"
    - "deploy/**"
    - "**/auth/**"
    - "**/migrations/**"

Protected paths always land in at least review, with or without an AI provider. Because .mergejudge.yml and AGENTS.md are read from the base branch tip, a PR opened by an agent cannot weaken the rules for its own review.

Step 4: Put judgement rules in AGENTS.md

If you already keep an AGENTS.md or CLAUDE.md in your repo for coding agents, add a ## Code review section in plain English (for example, "Every new HTTP handler under src/api/ must check resource authorization"). MergeJudge reads it from the base branch and uses it to raise the lane when violated.

What this setup does not do

來源:DEV Community · dev.to