Co-authored-by: lezi-fun <177434121+lezi-fun@users.noreply.github.com>
ghbot
GitHub Actions bot that reviews pull requests by calling Codex CLI, leaves inline review comments for problems, approves clean PRs, and can merge them when repository checks are green.
Behavior
- Triggers on
pull_request_target:opened,synchronize,reopened,ready_for_review. - When a new PR is opened, posts an immediate comment that review has started.
- Fetches changed files and patches from the pull request.
- Asks Codex CLI for a structured decision:
safeToMerge=trueonly when there are no blocking findings.blockingfindings become request-changes reviews.suggestionfindings are included as non-blocking suggestions.
- Supports a lenient pass when a repository administrator comments
/lenient-check. - If no repository administrator has commented or reviewed within the last 24 hours, the lenient trigger automatically broadens to users with
write,maintain, oradminpermission. - In lenient mode, only blocks dangerous changes, runtime-impacting issues, errors, crashes, broken builds, data-loss risks, and security risks.
- A PR that passes lenient mode is not auto-merged until
@lezi-funapproves the current head commit. - If the reviewer detects clearly malicious code, the bot comments with the reason and closes the pull request.
- Posts inline comments only on valid added diff lines.
- Approves clean pull requests.
- Retries transient Codex CLI and GitHub API request failures up to 5 times before giving up.
- 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 Actions setup
Add these repository secrets:
CODEX_API_KEY
Optional repository variables:
CODEX_BASE_URL: defaults tohttps://api.openai.com/v1CODEX_MODEL: defaults togpt-5.4CODEX_REASONING_EFFORT:minimal,low,medium,high, orxhigh, defaults tohighAUTO_MERGE: defaults tofalseMERGE_METHOD:merge,squash, orrebase, defaults tosquashREQUIRE_CHECKS: defaults totrueMAX_PATCH_CHARS: defaults to120000
The workflow uses the repository GITHUB_TOKEN, so you do not need a GitHub App, webhook endpoint, Vercel deployment, or a self-hosted listener.
It installs Codex CLI inside the GitHub Actions runner and uses that CLI for the review itself. The workflow writes an isolated Codex config.toml at runtime so each run gets an explicit model, provider base URL, and reasoning setting.
Required workflow permissions
Repository Actions permissions must allow the workflow token to:
contents: writepull-requests: writechecks: writeissues: writestatuses: read
These permissions are declared in .github/workflows/review.yml.
Lenient check
If a strict review leaves findings that are not practical to change, a repository administrator can comment this on the PR:
/lenient-check
That reruns the AI in lenient mode.
If no administrator has commented or reviewed within the last 24 hours on that PR, the command is also accepted from users with write or maintain permission.
If lenient mode passes, the bot still requires @lezi-fun to approve the current head commit before merge.
Local development
npm install
npm run build
npm run typecheck
To simulate the workflow locally, export the same env vars that the GitHub Action uses and run:
node dist/src/actions/runReview.js
You must also provide:
GITHUB_EVENT_NAMEGITHUB_EVENT_PATHGITHUB_TOKEN
Configuration
See .env.example for local testing values.
Important variables:
GITHUB_TOKEN: GitHub token used by the workflow or local simulationCODEX_API_KEY: API key used by Codex CLICODEX_BASE_URL: optional Codex/OpenAI-compatible base URLCODEX_MODEL: defaults togpt-5.4CODEX_REASONING_EFFORT: optional, one ofminimal,low,medium,high,xhighBOT_NAME: defaults toghbot, but the workflow sets it togithub-actions[bot]LENIENT_APPROVAL_USER: defaults tolezi-funAUTO_MERGE: defaults tofalseMERGE_METHOD: defaults tosquashREQUIRE_CHECKS: defaults totrueMAX_PATCH_CHARS: defaults to120000
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.