Self-hosted AI code review GitHub Action
Self-hosted AI code review with MergeJudge means running the open-source MergeJudge GitHub Action in your own GitHub Actions runner, with your own AI provider key: no MergeJudge account, and MergeJudge's servers are never called.
The MergeJudge GitHub Action runs the whole review inside your own GitHub Actions runner. It doesn't call the hosted MergeJudge service and doesn't need a MergeJudge account. It talks to the GitHub API with the workflow token. If you configure an AI provider, it sends the review prompt to that provider using your own key. With no key, it runs the deterministic rules only.
Every pull request gets a lane:
auto: low risk, not a guarantee (docs, styles and similar paths, under the size limit). Branch protection and required checks still apply.review: a human must look. The check is neutral and does not stop a merge on its own.block: do not merge. The check fails.
The lane comes from deterministic rules (protected paths, size, labels). The AI step adds line comments and rubric results, and it can only raise a lane, never lower it. The result is posted as a sticky comment and a mergejudge/lane check.
The Action and the review engine are open source (MIT): gauravsharmaGG/mergejudge-runner. What exactly is open source, and how the Action relates to the runner: Open-source AI pull request reviewer. How lanes are chosen: sort pull requests by risk.
auto on this page means low risk, not a guarantee. Branch protection and required checks still apply. The Action does not merge pull requests.
Use your own OpenAI API key in GitHub Actions
Store your own OpenAI key as a repository secret. MergeJudge does not issue keys and does not see this secret.
gh secret set OPENAI_API_KEYThis workflow is enough to review every pull request. The Action reads provider, model and api_key_env, loads the key from the environment, and calls https://api.openai.com/v1/chat/completions with it. The review asks for a JSON object (response_format: { type: "json_object" }). If the call fails, or the reply is not valid JSON after one retry, the review falls back to rules-only and says so.
# .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:
# Fork pull requests get no secrets. Skip them, or the run is rules-only and may fail to comment.
if: github.event.pull_request.head.repo.full_name == github.repository
runs-on: ubuntu-latest
steps:
- uses: gauravsharmaGG/mergejudge-runner@v1
env:
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
with:
provider: openai
model: your-model-name # example; use a model your OpenAI account offers
api_key_env: OPENAI_API_KEYmodel is required for the AI step. Without OPENAI_API_KEY the review is rules-only. Chat Completions is the default. Set provider.api: responses in .mergejudge.yml on the base branch only if you want OpenAI's Responses API instead. Learning, deep mode and a weekly proposal are in the full workflow below. Provider options: LLM providers.
Local models (OpenAI-compatible endpoint, for example Ollama)
This works when the endpoint speaks Chat Completions and the GitHub Actions runner can open a connection to it.
Set provider: openai-compatible and base_url to the server's /v1 URL. You must set base_url. If you leave it out, the request goes to https://api.openai.com/v1, not to your server. model is required, and it must be a model that server already has. api_key_env must name an environment variable that is set and non-empty: with no key, MergeJudge skips the model step. A local Ollama server ignores the key value. Ollama's own OpenAI-compatible API documents the key as required by clients and ignored by the server.
The Action sends POST {base_url}/chat/completions with a Bearer token, temperature: 0, max_tokens, and response_format: { type: "json_object" } on every review. A current local Ollama server accepts that JSON mode. Ollama's hosted cloud API does not support structured outputs, so do not point base_url at it. If the endpoint rejects the request, the review falls back to rules-only and says so.
http://127.0.0.1:11434/v1 is the job's own loopback. runs-on: ubuntu-latest cannot reach Ollama on your laptop. Run the job on a self-hosted runner on the machine where Ollama is already listening. This is the GitHub Action. The hosted GitHub App calls base_url from MergeJudge's servers, and the panel only saves an https URL, so a laptop address does not work there.
# .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: self-hosted
steps:
- uses: gauravsharmaGG/mergejudge-runner@v1
env:
OLLAMA_API_KEY: ${{ secrets.OLLAMA_API_KEY }} # any non-empty value; local Ollama ignores it
with:
provider: openai-compatible
base_url: http://127.0.0.1:11434/v1
model: your-model-name # a model this Ollama server has already pulled
api_key_env: OLLAMA_API_KEYAn OpenAI-compatible server you run somewhere else uses the same inputs with that server's https://…/v1 URL, on whatever runner can reach it. Do not use pull_request_target with a checkout of the pull request head.
What our servers see
MergeJudge's servers read the pull request diff from GitHub to run the rules. The GitHub Action does not call those servers. When an AI provider is configured, the diff is sent to that provider.
On the hosted GitHub App, that diff is processed to run the review and is not kept afterwards. A runner job holds the diff only until the review finishes, and it is deleted within about 48 hours. In deep-local mode (review.mode: deep and runner.code_source: local) the job carries no code, and the servers still read the diff for the rules and do not store it. Review findings can quote short lines of code and are kept for a limited time.
MergeJudge does not use your code to train models. The provider you configure is a separate controller: its terms decide whether it stores or trains on the prompt. With provider: none, or no key, there is no AI step. The field-by-field table for the Action is below. The privacy policy is at /privacy.
1. Add your AI key as a secret
Store the key as a repository (or organisation) secret. Use the GitHub UI under Settings → Secrets and variables → Actions → New repository secret, or the GitHub CLI:
gh secret set AI_API_KEYAI_API_KEY is your own Anthropic, OpenAI or z.ai key, stored as a GitHub secret. MergeJudge doesn't issue keys. Leave it out for free rules-only reviews.
The secret name is up to you. The workflow passes it in as an environment variable, and api_key_env tells MergeJudge which variable to read. MergeJudge doesn't log or post your key.
Supported provider values: anthropic, openai, zai, openai-compatible (any Chat Completions endpoint, set base_url), or none for rules-only. See LLM providers for example configs.
2. Allow the Action to open the learning PR
The scheduled learning run opens a pull request. By default, GitHub's GITHUB_TOKEN can't create PRs. Turn on Settings → Actions → General → Workflow permissions → Allow GitHub Actions to create and approve pull requests. You can skip this if you don't want learning proposals. Triage and feedback still work without it.
3. Add the workflow
# .github/workflows/mergejudge.yml
name: MergeJudge
on:
pull_request:
types: [opened, synchronize, reopened, ready_for_review, labeled, unlabeled]
issue_comment:
types: [created, edited] # feedback checkboxes arrive as "edited"
schedule:
- cron: "0 9 * * 1" # weekly learning proposal, Mondays 09:00 UTC
workflow_dispatch: {} # run the proposal by hand
permissions:
contents: write # learning branch + proposal PR (contents: read is enough for triage only)
pull-requests: write
checks: write
jobs:
lane:
# Skip issue comments that aren't MergeJudge feedback (saves minutes).
if: >
github.event_name != 'issue_comment' ||
contains(github.event.comment.body, 'MergeJudge') ||
startsWith(github.event.comment.body, '/mergejudge')
runs-on: ubuntu-latest
steps:
# Only needed for deep mode (step 4). Safe to remove otherwise.
- uses: actions/checkout@v4
if: github.event_name == 'pull_request'
- uses: gauravsharmaGG/mergejudge-runner@v1
env:
AI_API_KEY: ${{ secrets.AI_API_KEY }} # omit for rules-only
with:
provider: anthropic # or openai, zai, openai-compatible, none
model: your-model-name # check your provider's docs for current names
api_key_env: AI_API_KEYThe Action picks what to do from the event (mode: auto):
| Event | Mode | What happens |
|---|---|---|
pull_request | triage | Review the PR, post the comment, the check and line comments |
issue_comment | feedback | Record a lesson from ticked boxes or /mergejudge learn … |
schedule, workflow_dispatch | propose | Open or update the learning proposal PR |
Inputs: github_token, app_id / app_private_key (optional GitHub App credentials), mode, config_path (default .mergejudge.yml), provider, base_url, model, api_key_env. Outputs: lane, proposal_pr.
Without a .mergejudge.yml, built-in defaults apply. The config is always read from the PR's base branch, so a PR can't change the rules that review it.
Fork pull requests
For PRs from forks, GitHub gives the workflow a read-only token and no secrets. There's no key, so the review is rules-only, and posting the comment fails. To avoid failed runs, limit the review to same-repository branches by adding this condition to the job:
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository(Combine it with the issue_comment filter above using && if you keep both.)
Don't switch to pull_request_target with a checkout of the PR head. That runs untrusted code with your secrets.
4. Deep mode: give the model the rest of the repo
In the default diff mode, the model sees the changed hunks, your policy files and rubrics. Deep mode adds the code the change touches. Set it on the base branch:
# .mergejudge.yml
review:
mode: deepand keep the actions/checkout step. The Action then:
- indexes the checked-out files in memory, for this run only;
- finds importers, imports, callers, files that mention changed names, strings and env var names (up to two hops out);
- sends those snippets to your AI provider next to the diff, in a single pass.
Limits: tracked files only. .env* files, .pem and .key files, common lockfiles, node_modules, build output folders, binaries and files over 100 KB are not indexed, and symlinks are never followed. At most 5,000 files, 50 MB or 2 minutes are indexed, and a partial index is reported. Without a usable checkout, the review falls back to context mode (files read through the GitHub API) and says so.
5. Learning: feedback → weekly proposal PR
- Feedback. The MergeJudge comment ends with checkboxes (Correct / Too lenient / Too strict / Wrong reason / Missed something, plus
wrongandrightboxes for each failed or unverified rubric item). When someone with write access ticks one, or comments/mergejudge learn <note>, theissue_commentrun records a lesson inlessons/lessons.jsonlon themergejudge-learningbranch. Nothing is written to the reviewed PR. In the Action, merges and reverts alone don't create lessons. Only explicit feedback does. - Scheduled proposal. In the Action, the scheduled run reads the lessons. Once there are at least
learning.propose_after(default 10), it opens or updates a PR frommergejudge/proposal-learning. It may suggest morelanes.protectedpaths or new rubric notes in.mergejudge.yml, with the evidence listed. - You decide. The proposal PR is labelled
do-not-mergeandneeds-humanand is never approved or merged by MergeJudge. A guard rejects any edit that would loosen the rules.
More: Learning and AGENTS.md and policy files.
Where your data goes
With the Action, there are only two parties: GitHub and the AI provider you configure.
| Data | GitHub | Your AI provider | MergeJudge servers |
|---|---|---|---|
PR diff (minus diff_exclude, e.g. lockfiles, build output, images) | yes (it's your repo) | yes, when a provider is configured | no |
| PR title and body | yes | yes | no |
Policy files (AGENTS.md, REVIEW_POLICY.md, …) | yes | yes | no |
| Related code snippets (context and deep modes) | yes | yes | no |
Lessons (lessons.jsonl) | yes, on the mergejudge-learning branch | no | no |
| Your API key | stored as a GitHub secret | sent to the provider to authenticate | no |
So your code does leave your runner. It goes to the AI provider you chose, under your account and that provider's data terms. Pick a provider and plan whose data handling you're comfortable with, or point openai-compatible at an endpoint you run yourself. With provider: none (or no key), there is no AI step and the diff goes nowhere except GitHub.
The MergeJudge hosted service is never called by the Action.
FAQ
Can I self-host AI code review without a vendor account?
Yes. The MergeJudge GitHub Action runs the full review engine in your own GitHub Actions runner. It talks to the GitHub API and, when you set one, the AI provider you configure. It needs no MergeJudge account and does not call MergeJudge's servers.
How do I use my own OpenAI API key in GitHub Actions?
Store the key as a repository secret named OPENAI_API_KEY and set the Action inputs provider: openai, model, and api_key_env: OPENAI_API_KEY. The Action calls https://api.openai.com/v1/chat/completions with that key. MergeJudge does not issue keys. With no key the review is rules-only.
Can I use a local model such as Ollama?
Yes, on the GitHub Action, when the endpoint is a Chat Completions API that job can reach. Set provider: openai-compatible, base_url to that server's /v1 URL (for a local Ollama server, http://127.0.0.1:11434/v1), and a non-empty api_key_env. The Action always sends response_format json_object. A local Ollama server accepts that. Ollama's hosted cloud API does not support structured outputs, so do not point base_url there. ubuntu-latest cannot reach Ollama on your laptop; use a self-hosted runner where Ollama is listening. The hosted GitHub App cannot use a laptop address; its panel only saves an https URL. If the call fails, the review falls back to rules-only and says so.
What do MergeJudge's servers see?
MergeJudge's servers read the pull request diff from GitHub to run the rules. The GitHub Action does not call those servers. When an AI provider is configured, the diff is sent to that provider. MergeJudge does not use your code to train models.
Does my code leave my runner?
Yes, when an AI provider is configured: the diff, pull request title and body, policy files and, in context or deep mode, related code snippets go to the provider you chose, under your account. Point openai-compatible at an endpoint you run yourself if you want that call to stay on infrastructure you operate. With provider: none there is no AI step.
Which AI providers can I use with my own key?
anthropic, openai, zai, openai-compatible (any Chat Completions endpoint; set base_url or the request goes to api.openai.com) or none for rules-only. workers-ai is a self-hosted Worker binding and is not available in the Action.
Can I self-host the MergeJudge hosted service itself?
Not yet. Self-hosting the MergeJudge Worker isn't public. Use the GitHub Action for a fully self-run setup.
Related
- Open-source AI pull request reviewer
- LLM providers
- Sort pull requests by risk
- How to stop AI coding agents from merging their own pull requests
- What is MergeJudge?
Versions
Pin @v1 to get compatible updates, or pin a full commit SHA if your policy requires immutable references. The Action runs a committed bundle (action/index.cjs) on Node 24.
Other ways to run MergeJudge
- Hosted GitHub App: no workflow file. Reviews run on the MergeJudge service with your provider key.
- Run on your own machine: the hosted service plus the open-source runner doing the AI step with your own login.
- Self-hosting the MergeJudge Worker itself isn't public yet.