AI code review comments for GitHub pull requests
- Automatically analyze code in pull request diffs
- Generate insightful, context-aware code review comments
- Support for multiple AI models:
- OpenAI (GPT-4, etc.)
- Azure OpenAI
- Anthropic Claude
- Custom/third-party AI models
- Easy integration with GitHub CI workflows
- Customizable configuration
# Install globally
npm install -g ai-approver
# Or install locally
npm install ai-approver --save-dev
# Review a specific pull request
ai-approver review --repo owner/repo --pr 123 --model openai
# Run as part of CI workflow (uses environment variables)
ai-approver ci --model openai
The following environment variables are used:
GITHUB_TOKEN
: GitHub API token with PR read/write accessOPENAI_API_KEY
: OpenAI API keyAZURE_OPENAI_API_KEY
: Azure OpenAI API keyAZURE_OPENAI_ENDPOINT
: Azure OpenAI endpoint URLANTHROPIC_API_KEY
: Anthropic API keyCUSTOM_API_KEY
: Custom API key (optional)CUSTOM_API_ENDPOINT
: Custom API endpoint
You can customize the behavior by creating a custom configuration file:
ai-approver review --repo owner/repo --pr 123 --config ./my-config.js
See config/default.js
for the full configuration options.
You can easily integrate AI-Approver into your GitHub Actions workflow. Here's how:
- Create a
.github/workflows/ai-approver.yml
file in your repository:
name: AI Code Review
on:
pull_request:
types: [opened, synchronize]
jobs:
review:
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '18'
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Run AI Code Review
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
run: node src/index.js
-
Add the required secrets to your GitHub repository:
GITHUB_TOKEN
is automatically provided by GitHub ActionsOPENAI_API_KEY
should be added in your repository settings under Secrets and Variables > Actions
-
Customize the workflow as needed:
- Adjust the Node.js version if required
- Modify the environment variables for different AI models
- Add any additional configuration parameters
The workflow will run automatically whenever a pull request is opened or updated, analyzing the changed files and providing AI-generated code reviews directly as PR comments.
For different environments (development, testing, production), you can customize the configuration using:
// config/custom-environment-variables.js
export default {
github: {
token: "GITHUB_TOKEN"
},
openai: {
apiKey: "OPENAI_API_KEY"
}
};
This allows for flexible deployment across different environments while maintaining security best practices.
# Clone the repository
git clone https://github.com/yourusername/ai-approver.git
cd ai-approver
# Install dependencies
npm install
# Run locally
node src/index.js review --repo owner/repo --pr 123
ISC