Skip to content

Commit e16daf3

Browse files
matejclaude
andauthored
Add require-label option for on-demand reviews (#13)
## Summary Adds ability to only run code reviews when a specific label is present on the PR. The review can be triggered by adding the label, even without pushing new commits. ## New Input `require-label` (default: empty) - Set to a label name (e.g., `needs-review`) to only run when that label is present - Leave empty to review all PRs (current behavior) ## Workflow Configuration To trigger on label addition, include `labeled` in your workflow: ```yaml on: pull_request: types: [opened, synchronize, reopened, labeled] jobs: review: steps: - uses: PSPDFKit-labs/claude-code-review@main with: claude-api-key: ${{ secrets.ANTHROPIC_API_KEY }} require-label: 'needs-review' ``` ## Behavior | Label present | Action | |---------------|--------| | Yes | Run review | | No | Skip with message "required label 'X' not found" | ## Test plan - [ ] Test PR without label → should skip - [ ] Add label → should trigger review - [ ] Test PR with label from start → should run 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 6689c08 commit e16daf3

2 files changed

Lines changed: 21 additions & 3 deletions

File tree

.github/workflows/code-review.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ name: Code Review
22

33
on:
44
pull_request:
5+
types: [opened, synchronize, reopened, labeled]
56
workflow_dispatch:
67

78
jobs:

action.yml

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ inputs:
6363
required: false
6464
default: 'true'
6565

66+
require-label:
67+
description: 'Only run review if this label is present on the PR. Leave empty to review all PRs. To trigger on label addition, add "labeled" to your workflow pull_request types.'
68+
required: false
69+
default: ''
70+
6671
outputs:
6772
findings-count:
6873
description: 'Number of code review findings'
@@ -106,6 +111,8 @@ runs:
106111
RUN_EVERY_COMMIT: ${{ inputs.run-every-commit }}
107112
SKIP_DRAFT_PRS: ${{ inputs.skip-draft-prs }}
108113
IS_DRAFT: ${{ github.event.pull_request.draft }}
114+
REQUIRE_LABEL: ${{ inputs.require-label }}
115+
PR_LABELS: ${{ toJSON(github.event.pull_request.labels.*.name) }}
109116
run: |
110117
# Check if ClaudeCode should be enabled
111118
ENABLE_CLAUDECODE="true"
@@ -116,16 +123,26 @@ runs:
116123
PR_NUMBER="$PR_NUMBER"
117124
CACHE_HIT="${{ steps.claudecode-history.outputs.cache-hit }}"
118125
126+
# Check if required label is present
127+
if [ -n "$REQUIRE_LABEL" ]; then
128+
if echo "$PR_LABELS" | jq -e --arg label "$REQUIRE_LABEL" 'index($label) != null' > /dev/null 2>&1; then
129+
echo "Required label '$REQUIRE_LABEL' found on PR #$PR_NUMBER"
130+
else
131+
echo "Skipping code review: required label '$REQUIRE_LABEL' not found on PR #$PR_NUMBER"
132+
ENABLE_CLAUDECODE="false"
133+
fi
134+
fi
135+
119136
# Skip draft PRs if configured
120-
if [ "$SKIP_DRAFT_PRS" == "true" ] && [ "$IS_DRAFT" == "true" ]; then
137+
if [ "$ENABLE_CLAUDECODE" == "true" ] && [ "$SKIP_DRAFT_PRS" == "true" ] && [ "$IS_DRAFT" == "true" ]; then
121138
echo "Skipping code review for draft PR #$PR_NUMBER"
122139
ENABLE_CLAUDECODE="false"
123140
# Now check cache - if ClaudeCode has already run, disable unless run-every-commit is true
124141
# Check if marker file exists (cache may have been restored from a different SHA)
125-
elif [ "$RUN_EVERY_COMMIT" != "true" ] && [ -f ".claudecode-marker/marker.json" ]; then
142+
elif [ "$ENABLE_CLAUDECODE" == "true" ] && [ "$RUN_EVERY_COMMIT" != "true" ] && [ -f ".claudecode-marker/marker.json" ]; then
126143
echo "ClaudeCode has already run on PR #$PR_NUMBER (found marker file), forcing disable to avoid false positives"
127144
ENABLE_CLAUDECODE="false"
128-
elif [ "$RUN_EVERY_COMMIT" == "true" ] && [ -f ".claudecode-marker/marker.json" ]; then
145+
elif [ "$ENABLE_CLAUDECODE" == "true" ] && [ "$RUN_EVERY_COMMIT" == "true" ] && [ -f ".claudecode-marker/marker.json" ]; then
129146
echo "ClaudeCode has already run on PR #$PR_NUMBER but run-every-commit is enabled, running again"
130147
elif [ "$ENABLE_CLAUDECODE" == "true" ]; then
131148
echo "ClaudeCode will run for PR #$PR_NUMBER (first run)"

0 commit comments

Comments
 (0)