Merge pull request #10 from pacnpal/claude/auto-pr-review-01RhWKxVsrwj27rznVTBz9mC

Set up automatic pull request review
This commit is contained in:
pacnpal
2025-11-14 10:16:59 -05:00
committed by GitHub
5 changed files with 49 additions and 3 deletions

View File

@@ -87,6 +87,32 @@ For existing pull requests, you can manually trigger the review:
3. Fill in the branch and pull request number
4. Click "Run Workflow"
### Disabling Auto-Review
You can disable automatic reviews and only use manual triggers by setting `auto-review: false`:
```yaml
- name: Run Claude Review
uses: pacnpal/claude-code-review@main
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
anthropic-key: ${{ secrets.ANTHROPIC_API_KEY }}
pr-number: ${{ github.event.pull_request.number || inputs.pr_number }}
auto-review: false # Disables automatic reviews
```
You can also make it conditional based on labels or other criteria:
```yaml
- name: Run Claude Review
uses: pacnpal/claude-code-review@main
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
anthropic-key: ${{ secrets.ANTHROPIC_API_KEY }}
pr-number: ${{ github.event.pull_request.number || inputs.pr_number }}
auto-review: ${{ contains(github.event.pull_request.labels.*.name, 'needs-review') }}
```
## Setup
### Prerequisites
@@ -119,6 +145,7 @@ For existing pull requests, you can manually trigger the review:
| `github-token` | GitHub token for API access | Yes | N/A |
| `anthropic-key` | Anthropic API key for Claude | Yes | N/A |
| `pr-number` | Pull request number to review | Yes | N/A |
| `auto-review` | Enable automatic code reviews (set to `false` to skip) | No | `true` |
## Outputs

View File

@@ -424,6 +424,15 @@ async function run() {
const token = core.getInput('github-token', { required: true });
const anthropicKey = core.getInput('anthropic-key', { required: true });
let prNumber = core.getInput('pr-number');
const autoReview = core.getInput('auto-review', { required: false }) || 'true';
// Check if auto-review is disabled
if (autoReview.toLowerCase() === 'false') {
core.info('⏭️ Auto-review is disabled, skipping code review');
core.setOutput('diff_size', '0');
core.setOutput('review', 'Auto-review disabled');
return;
}
// Get PR number from event if not provided
const context = github.context;

View File

@@ -11,6 +11,10 @@ inputs:
pr-number:
description: 'Pull request number'
required: true
auto-review:
description: 'Enable automatic code reviews (set to false to skip review)'
required: false
default: 'true'
outputs:
diff_size:
description: 'Size of the relevant code changes'

9
dist/index.js vendored
View File

@@ -32260,6 +32260,15 @@ async function run() {
const token = core.getInput('github-token', { required: true });
const anthropicKey = core.getInput('anthropic-key', { required: true });
let prNumber = core.getInput('pr-number');
const autoReview = core.getInput('auto-review', { required: false }) || 'true';
// Check if auto-review is disabled
if (autoReview.toLowerCase() === 'false') {
core.info('⏭️ Auto-review is disabled, skipping code review');
core.setOutput('diff_size', '0');
core.setOutput('review', 'Auto-review disabled');
return;
}
// Get PR number from event if not provided
const context = github.context;

3
package-lock.json generated
View File

@@ -98,7 +98,6 @@
"integrity": "sha512-e7jT4DxYvIDLk1ZHmU/m/mB19rex9sv0c2ftBtjSBv+kVM/902eh0fINUzD7UwLLNR+jU585GxUJ8/EBfAM5fw==",
"dev": true,
"license": "MIT",
"peer": true,
"dependencies": {
"@babel/code-frame": "^7.27.1",
"@babel/generator": "^7.28.5",
@@ -1189,7 +1188,6 @@
"version": "5.2.2",
"resolved": "https://registry.npmjs.org/@octokit/core/-/core-5.2.2.tgz",
"integrity": "sha512-/g2d4sW9nUDJOMz3mabVQvOGhVa4e/BN/Um7yca9Bb2XTzPPnfTWHWQg+IsEYO7M3Vx+EXvaM/I2pJWIMun1bg==",
"peer": true,
"dependencies": {
"@octokit/auth-token": "^4.0.0",
"@octokit/graphql": "^7.1.0",
@@ -2003,7 +2001,6 @@
}
],
"license": "MIT",
"peer": true,
"dependencies": {
"baseline-browser-mapping": "^2.8.25",
"caniuse-lite": "^1.0.30001754",