ghbot
GitHub App bot that reviews pull requests with an AI reviewer, leaves inline review comments for problems, approves clean PRs, and can merge them when repository checks are green.
Behavior
- Listens for
pull_requestevents:opened,synchronize,reopened,ready_for_review. - Fetches changed files and patches from the pull request.
- Asks the reviewer for a structured decision:
safeToMerge=trueonly when there are no blocking findings.blockingfindings become request-changes reviews.suggestionfindings are included as non-blocking suggestions.
- Posts inline comments only on valid added diff lines.
- Approves clean pull requests.
- If
AUTO_MERGE=true, merges only after:- the AI reviewer says the PR is safe,
- GitHub reports the PR as mergeable,
- checks/statuses are green when
REQUIRE_CHECKS=true.
GitHub App setup
Create a GitHub App with these repository permissions:
- Contents:
Read & write - Pull requests:
Read & write - Checks:
Read-only - Commit statuses:
Read-only - Metadata:
Read-only
Subscribe to this webhook event:
- Pull request
Set the webhook URL to:
https://your-domain.example/webhooks/github
Generate a private key for the app, install the app on the target repositories, and copy .env.example to .env.
Configuration
cp .env.example .env
Required variables:
WEBHOOK_SECRET: the GitHub App webhook secret.GITHUB_APP_ID: GitHub App ID.GITHUB_PRIVATE_KEY: GitHub App private key. Use escaped\nline breaks in a single-line env var.OPENAI_API_KEY: API key for the reviewer model.
Important optional variables:
OPENAI_MODEL: defaults togpt-4.1.AUTO_MERGE: defaults tofalse. Set totrueonly after testing on a non-critical repo.MERGE_METHOD:merge,squash, orrebase. Defaults tosquash.REQUIRE_CHECKS: defaults totrue.MAX_PATCH_CHARS: maximum patch payload sent to the reviewer. Defaults to120000.
Local development
npm install
npm run dev
Expose the local server with a tunnel and point the GitHub App webhook to:
https://your-tunnel.example/webhooks/github
Health check:
curl http://localhost:3000/healthz
Deploy to Vercel
This project includes a Vercel Function at api/github/webhooks.ts and a rewrite from /webhooks/github to /api/github/webhooks.
- Import this repository into Vercel.
- Add the required environment variables in Vercel Project Settings.
- Deploy.
- Set the GitHub App webhook URL to:
https://your-project.vercel.app/webhooks/github
For local Vercel testing:
npm run dev:vercel
Vercel serverless functions have execution time limits. For large PRs, keep MAX_PATCH_CHARS conservative or upgrade the function duration in vercel.json.
Self-hosted production
npm install
npm run build
npm start
Run it behind HTTPS. GitHub webhooks must reach /webhooks/github, and the app must keep the private key and webhook secret out of source control.
Safety notes
Start with AUTO_MERGE=false. Let the bot comment and approve first, then enable auto-merge after you trust the behavior on your repositories.
This bot does not execute untrusted PR code. It reviews diffs and checks GitHub check/status results. Keep repository branch protection enabled so required CI and human override rules still apply.
Open source release checklist
- Replace the copyright holder in
LICENSEif needed. - Create a GitHub repository.
- Push this code.
- Configure repository secrets only in GitHub/Vercel, never in source control.
- Keep branch protection enabled on
main.