Skip to content

Commit 420a05c

Browse files
committed
fix
1 parent ae5f6b4 commit 420a05c

4 files changed

Lines changed: 75 additions & 0 deletions

File tree

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ jobs:
6161
# Optional inputs with defaults
6262
model_id: 'anthropic/claude-2' # Default model
6363
max_tokens: '2048' # Default max tokens
64+
review_label: 'ai-review' # Optional: Only review PRs with this label
6465

6566
# Optional custom prompt
6667
custom_prompt: |
@@ -137,6 +138,7 @@ _Analyzed using anthropic/claude-2_
137138
| `model_id` | Model ID to use | No | `anthropic/claude-2` | See available models below |
138139
| `custom_prompt` | Custom prompt for analysis | No | Default code review prompt | Can be multiline YAML |
139140
| `max_tokens` | Maximum tokens in response | No | `2048` | Adjust based on review complexity |
141+
| `review_label` | Label to trigger review | No | - | If not set, reviews all PRs |
140142

141143
### Minimal Configuration
142144

@@ -194,6 +196,16 @@ jobs:
194196
Rate the overall quality from 1-5 stars and provide final comments.
195197
```
196198
199+
### Label-Based Review Example
200+
201+
```yaml
202+
- uses: jonit-dev/openrouter-github-action@main
203+
with:
204+
github_token: ${{ secrets.GITHUB_TOKEN }}
205+
open_router_key: ${{ secrets.OPEN_ROUTER_KEY }}
206+
review_label: 'ai-review' # Only reviews PRs with this label
207+
```
208+
197209
## Available Models
198210
199211
Recommended models:

action.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ inputs:
1212
description: 'The model ID to use for analysis (e.g., anthropic/claude-2, openai/gpt-4)'
1313
required: true
1414
default: 'anthropic/claude-2'
15+
review_label:
16+
description: 'Label that triggers the review. If not set, reviews all PRs.'
17+
required: false
1518
custom_prompt:
1619
description: 'Custom prompt for the AI analysis. If not provided, a default prompt focusing on code review aspects will be used.'
1720
required: false

dist/index.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41642,6 +41642,24 @@ async function getPRDiff(octokit, context) {
4164241642
}
4164341643
}
4164441644

41645+
async function shouldReviewPR(octokit, context, requiredLabel) {
41646+
if (!requiredLabel) {
41647+
return true;
41648+
}
41649+
41650+
try {
41651+
const { data: labels } = await octokit.rest.issues.listLabelsOnIssue({
41652+
owner: context.repo.owner,
41653+
repo: context.repo.repo,
41654+
issue_number: context.payload.pull_request.number,
41655+
});
41656+
41657+
return labels.some((label) => label.name === requiredLabel);
41658+
} catch (error) {
41659+
throw new Error(`Failed to fetch PR labels: ${error.message}`);
41660+
}
41661+
}
41662+
4164541663
async function analyzeDiff(diff, modelId, openRouterKey, customPrompt) {
4164641664
const defaultPrompt = `You are a highly skilled staff software engineer reviewing a pull request.
4164741665

@@ -41740,11 +41758,23 @@ async function run() {
4174041758
const openRouterKey = core.getInput('open_router_key', { required: true });
4174141759
const modelId = core.getInput('model_id', { required: true });
4174241760
const customPrompt = core.getInput('custom_prompt');
41761+
const reviewLabel = core.getInput('review_label');
4174341762

4174441763
// Get GitHub token and create octokit client
4174541764
const token = core.getInput('github_token', { required: true });
4174641765
const octokit = github.getOctokit(token);
4174741766

41767+
// Check if we should review this PR based on label
41768+
const shouldReview = await shouldReviewPR(
41769+
octokit,
41770+
github.context,
41771+
reviewLabel
41772+
);
41773+
if (!shouldReview) {
41774+
core.info('Skipping review - required label not found on PR');
41775+
return;
41776+
}
41777+
4174841778
// Get PR diff
4174941779
const diff = await getPRDiff(octokit, github.context);
4175041780

src/index.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,24 @@ async function getPRDiff(octokit, context) {
1919
}
2020
}
2121

22+
async function shouldReviewPR(octokit, context, requiredLabel) {
23+
if (!requiredLabel) {
24+
return true;
25+
}
26+
27+
try {
28+
const { data: labels } = await octokit.rest.issues.listLabelsOnIssue({
29+
owner: context.repo.owner,
30+
repo: context.repo.repo,
31+
issue_number: context.payload.pull_request.number,
32+
});
33+
34+
return labels.some((label) => label.name === requiredLabel);
35+
} catch (error) {
36+
throw new Error(`Failed to fetch PR labels: ${error.message}`);
37+
}
38+
}
39+
2240
async function analyzeDiff(diff, modelId, openRouterKey, customPrompt) {
2341
const defaultPrompt = `You are a highly skilled staff software engineer reviewing a pull request.
2442
@@ -117,11 +135,23 @@ async function run() {
117135
const openRouterKey = core.getInput('open_router_key', { required: true });
118136
const modelId = core.getInput('model_id', { required: true });
119137
const customPrompt = core.getInput('custom_prompt');
138+
const reviewLabel = core.getInput('review_label');
120139

121140
// Get GitHub token and create octokit client
122141
const token = core.getInput('github_token', { required: true });
123142
const octokit = github.getOctokit(token);
124143

144+
// Check if we should review this PR based on label
145+
const shouldReview = await shouldReviewPR(
146+
octokit,
147+
github.context,
148+
reviewLabel
149+
);
150+
if (!shouldReview) {
151+
core.info('Skipping review - required label not found on PR');
152+
return;
153+
}
154+
125155
// Get PR diff
126156
const diff = await getPRDiff(octokit, github.context);
127157

0 commit comments

Comments
 (0)