AI-powered PR review using GitHub Actions and an LLM. This project fetches the PR diff, sends it to the model, and posts the review as a PR comment.
Gemini is used here because it has a free tier, but the same setup can work with other LLMs after updating the API client and secrets.
- A PR (pull request) is opened or updated.
- GitHub Actions runs the workflow.
- The script fetches the diff from GitHub.
- The diff is sent to the model for review.
- The bot formats the result and posts it as a PR comment.
pr-bot/
├── .github/workflows/pr-review.yml
├── scripts/review.py
├── requirements.txt
├── README.md
├── tictactoe.html
└── .gitignore
- GitHub account and repo with Actions enabled
- LLM API key (Gemini for this example)
- Python 3.11+
If you just want to look at the project locally:
git clone git@github.com:KhangHo10/pr-bot.git
cd pr-botIf you want the bot to actually run on a pull request, use your own repository or fork this repo first. Without write access, you cannot push to this repo or open a PR against it.
pip install -r requirements.txtIn the repository where the bot will run, add a secret named GEMINI_API_KEY in GitHub Actions settings.
Create a new branch in that repository, make a change, and open a pull request. The workflow in .github/workflows/pr-review.yml runs automatically when a PR is opened, synchronized, or reopened.
on:
pull_request:
types: [opened, synchronize, reopened]GitHub Actions does not run from your local clone. It runs in the GitHub repository that contains the PR.
You can test the script locally before pushing a PR.
export REPO="owner/repo-name"
export PR_NUMBER="12"
export GITHUB_TOKEN="your_github_token"
export GEMINI_API_KEY="your_gemini_api_key"
python scripts/review.py- copy the workflow from .github/workflows/pr-review.yml
- add your LLM API key as a secret
- update the client code in scripts/review.py if switching providers
- adjust the prompt if needed for your project's standards
- This is a review assistant, not a replacement for human judgment.
- Keep API keys in GitHub Secrets.
- Make sure the repo has permission to comment on pull requests.
This project is provided as a workshop/demo example. You are free to reuse and adapt it for your own repositories.