A reusable GitHub Action that automatically reviews Pull Requests using AI models via OpenRouter. Model-agnostic - use Claude, GPT-4, Gemini, Llama, or any model available on OpenRouter.
- Model Agnostic: Use any AI model available on OpenRouter
- Reusable: Host once, use across all your repositories
- Customizable: Configure system prompts, review focus areas, and more
- Automatic Reviews: Triggers on PR open, sync, and reopen
Create .github/workflows/ai-review.yml in your repository:
name: AI Code Review
on:
pull_request:
types: [opened, synchronize, reopened]
permissions:
contents: read
pull-requests: write
jobs:
review:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: AI Code Review
uses: YOUR_USERNAME/ai-code-reviewer@v1
with:
openrouter_api_key: ${{ secrets.OPENROUTER_API_KEY }}
github_token: ${{ secrets.GITHUB_TOKEN }}Replace YOUR_USERNAME/ai-code-reviewer with your published action's path.
- Go to OpenRouter
- Sign up or log in
- Navigate to API Keys
- Create a new API key
- Go to your GitHub repository → Settings → Secrets and variables → Actions
- Add a new repository secret:
- Name:
OPENROUTER_API_KEY - Value: Your OpenRouter API key
- Name:
| Input | Required | Default | Description |
|---|---|---|---|
openrouter_api_key |
Yes | - | Your OpenRouter API key |
github_token |
Yes | - | GitHub token for posting comments |
model |
No | anthropic/claude-3.5-sonnet |
AI model to use |
system_prompt |
No | - | Override the entire system prompt |
custom_prompt |
No | - | Additional instructions appended to the prompt |
review_focus |
No | - | Comma-separated focus areas |
temperature |
No | 0.3 |
Model temperature (0-1) |
max_diff_size |
No | 100000 |
Max diff size in characters |
post_comment |
No | true |
Whether to post review as PR comment |
| Output | Description |
|---|---|
review |
The generated review content |
model_used |
The AI model that was used |
- uses: YOUR_USERNAME/ai-code-reviewer@v1
with:
openrouter_api_key: ${{ secrets.OPENROUTER_API_KEY }}
github_token: ${{ secrets.GITHUB_TOKEN }}- uses: YOUR_USERNAME/ai-code-reviewer@v1
with:
openrouter_api_key: ${{ secrets.OPENROUTER_API_KEY }}
github_token: ${{ secrets.GITHUB_TOKEN }}
model: 'openai/gpt-4-turbo'- uses: YOUR_USERNAME/ai-code-reviewer@v1
with:
openrouter_api_key: ${{ secrets.OPENROUTER_API_KEY }}
github_token: ${{ secrets.GITHUB_TOKEN }}
system_prompt: |
You are a senior security engineer reviewing code for vulnerabilities.
Focus exclusively on security issues and rate their severity.
Ignore style and formatting issues.- uses: YOUR_USERNAME/ai-code-reviewer@v1
with:
openrouter_api_key: ${{ secrets.OPENROUTER_API_KEY }}
github_token: ${{ secrets.GITHUB_TOKEN }}
review_focus: 'security,performance,bugs'Available focus areas:
security- Security vulnerabilities and unsafe practicesperformance- Performance bottlenecks and inefficienciesbugs- Logic errors, edge cases, runtime issuesquality- Code smells and anti-patternsreadability- Code clarity and maintainabilitytesting- Test coverage and qualitydocumentation- Missing or outdated docsarchitecture- Design patterns and modularityaccessibility- UI accessibility issueserror-handling- Error handling and logging
- uses: YOUR_USERNAME/ai-code-reviewer@v1
with:
openrouter_api_key: ${{ secrets.OPENROUTER_API_KEY }}
github_token: ${{ secrets.GITHUB_TOKEN }}
custom_prompt: |
Pay special attention to:
- SQL injection vulnerabilities
- Proper input validation
- Error messages that might leak sensitive info- name: AI Code Review
id: review
uses: YOUR_USERNAME/ai-code-reviewer@v1
with:
openrouter_api_key: ${{ secrets.OPENROUTER_API_KEY }}
github_token: ${{ secrets.GITHUB_TOKEN }}
post_comment: 'false'
- name: Use Review Output
run: |
echo "Model used: ${{ steps.review.outputs.model_used }}"
echo "Review: ${{ steps.review.outputs.review }}"Popular models on OpenRouter:
| Provider | Model ID | Notes |
|---|---|---|
| Anthropic | anthropic/claude-3.5-sonnet |
Default, excellent for code |
| Anthropic | anthropic/claude-3-opus |
Most capable |
| OpenAI | openai/gpt-4-turbo |
Fast and capable |
| OpenAI | openai/gpt-4o |
Latest GPT-4 |
google/gemini-pro-1.5 |
Good balance | |
| Meta | meta-llama/llama-3.1-70b-instruct |
Open source |
| Mistral | mistralai/mistral-large |
European option |
| DeepSeek | deepseek/deepseek-coder |
Code specialist |
See the full list at OpenRouter Models.
To host and reuse this action across your projects:
-
Create a new GitHub repository named
ai-code-reviewer(or your preferred name) -
Push this code to the repository:
git init git add . git commit -m "Initial commit: AI Code Reviewer action" git remote add origin https://github.com/YOUR_USERNAME/ai-code-reviewer.git git push -u origin main
-
Create a release:
git tag -a v1 -m "Release v1" git push origin v1 -
Use in any repository:
uses: YOUR_USERNAME/ai-code-reviewer@v1
-
Follow Option 1 steps first
-
Go to your repository → Releases → Draft a new release
-
Check "Publish this Action to the GitHub Marketplace"
-
Fill in the marketplace listing details
-
Publish the release
After publishing to the Marketplace, users can find and use your action more easily.
For private/internal use:
-
Create a private repository with the action code
-
Reference it using the full path:
uses: YOUR_ORG/ai-code-reviewer@v1
-
Ensure the workflow has access to the private repository
ai-code-reviewer/
├── action.yml # Action definition
├── scripts/
│ └── review.js # Main review script
├── .github/
│ └── workflows/
│ └── pr-code-review.yml # Example workflow
└── README.md
- Check that
OPENROUTER_API_KEYis set correctly - Verify the workflow has
pull-requests: writepermission - Check the Actions log for error messages
- Verify your API key is valid
- Check your OpenRouter account has credits
- Ensure the model ID is correct (check OpenRouter Models)
The script truncates diffs larger than 100KB by default. You can adjust this with max_diff_size.
MIT