Skip to content

Commit a24eb2c

Browse files
authored
Fix duplicate review updates caused by self-triggering loop (#30)
## Summary - Remove "Request bot as reviewer" step that could trigger a second workflow run (via `review_requested` event), which bypasses SHA dedup and overwrites the just-posted review with lesser content - Add defensive guard in comment script: skip updating an existing review in-place if the new body is missing the PR summary that the existing review already has
1 parent ab64a14 commit a24eb2c

File tree

2 files changed

+16
-31
lines changed

2 files changed

+16
-31
lines changed

action.yml

Lines changed: 9 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ inputs:
77
description: 'Whether to comment on PRs with findings'
88
required: false
99
default: 'true'
10-
10+
1111
upload-results:
1212
description: 'Whether to upload results as artifacts'
1313
required: false
1414
default: 'true'
15-
15+
1616
exclude-directories:
1717
description: 'Comma-separated list of directories to exclude from scanning'
1818
required: false
@@ -22,7 +22,7 @@ inputs:
2222
description: 'Timeout for ClaudeCode analysis in minutes'
2323
required: false
2424
default: '20'
25-
25+
2626
claude-api-key:
2727
description: 'Anthropic Claude API key for code review analysis'
2828
required: true
@@ -123,7 +123,7 @@ outputs:
123123
findings-count:
124124
description: 'Number of code review findings'
125125
value: ${{ steps.claudecode-scan.outputs.findings_count }}
126-
126+
127127
results-file:
128128
description: 'Path to the results JSON file'
129129
value: ${{ steps.claudecode-scan.outputs.results_file }}
@@ -287,7 +287,7 @@ runs:
287287
# This script encapsulates the complex logic for deciding when to run code reviews
288288
# See scripts/determine-claudecode-enablement.sh for implementation details
289289
"${{ github.action_path }}/scripts/determine-claudecode-enablement.sh"
290-
290+
291291
- name: Reserve ClaudeCode slot to prevent race conditions
292292
if: steps.claudecode-check.outputs.enable_claudecode == 'true'
293293
shell: bash
@@ -344,7 +344,7 @@ runs:
344344
uses: actions/setup-node@v4
345345
with:
346346
node-version: '18'
347-
347+
348348
- name: Setup git for diffing
349349
if: steps.claudecode-check.outputs.enable_claudecode == 'true'
350350
shell: bash
@@ -386,7 +386,7 @@ runs:
386386
npm install -g @anthropic-ai/claude-code
387387
sudo apt-get update && sudo apt-get install -y jq
388388
echo "::endgroup::"
389-
389+
390390
- name: Run ClaudeCode scan
391391
id: claudecode-scan
392392
if: steps.claudecode-check.outputs.enable_claudecode == 'true'
@@ -530,7 +530,7 @@ runs:
530530
531531
echo "::endgroup::"
532532
533-
533+
534534
- name: Upload scan results
535535
if: always() && inputs.upload-results == 'true'
536536
uses: actions/upload-artifact@v4
@@ -542,7 +542,7 @@ runs:
542542
claudecode-error.log
543543
retention-days: 7
544544
if-no-files-found: ignore
545-
545+
546546
- name: Comment PR with findings
547547
if: (github.event_name == 'pull_request' || github.event_name == 'issue_comment') && inputs.comment-pr == 'true' && steps.claudecode-check.outputs.enable_claudecode == 'true'
548548
shell: bash
@@ -555,27 +555,6 @@ runs:
555555
run: |
556556
node "$ACTION_PATH/scripts/comment-pr-findings.js"
557557
558-
- name: Request bot as reviewer
559-
if: steps.claudecode-check.outputs.enable_claudecode == 'true'
560-
shell: bash
561-
env:
562-
GH_TOKEN: ${{ env.GITHUB_TOKEN || github.token }}
563-
GITHUB_REPOSITORY: ${{ github.repository }}
564-
PR_NUMBER: ${{ github.event.pull_request.number || steps.pr-info.outputs.pr_number }}
565-
BOT_LOGIN: ${{ inputs.app-slug }}[bot]
566-
run: |
567-
# Request the bot as a reviewer to make it appear in the PR's reviewer list
568-
# This is optional and will fail silently if the bot is already a reviewer or doesn't have permissions
569-
echo "Requesting $BOT_LOGIN as reviewer for PR #$PR_NUMBER..."
570-
571-
if gh api "repos/$GITHUB_REPOSITORY/pulls/$PR_NUMBER/requested_reviewers" \
572-
-X POST \
573-
-f "reviewers[]=$BOT_LOGIN" 2>/dev/null; then
574-
echo "Successfully requested $BOT_LOGIN as reviewer"
575-
else
576-
echo "Note: Could not request bot as reviewer (this is normal if bot is already a reviewer or is the PR author)"
577-
fi
578-
579558
branding:
580559
icon: 'shield'
581560
color: 'red'

scripts/comment-pr-findings.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,13 @@ async function run() {
386386
const existingState = existingReview.state;
387387

388388
if (existingState === newState && reviewComments.length === 0) {
389-
// Same state and no new inline comments - update body in place
389+
// Same state and no new inline comments - check if update would be a downgrade
390+
const existingHasSummary = existingReview.body && existingReview.body.includes(PR_SUMMARY_MARKER);
391+
const newHasSummary = reviewBody.includes(PR_SUMMARY_MARKER);
392+
if (existingHasSummary && !newHasSummary) {
393+
console.log(`Skipping update: existing review already has PR summary, new body does not`);
394+
return;
395+
}
390396
const updated = updateReviewBody(existingReview.id, reviewBody);
391397
if (updated) {
392398
console.log(`Updated existing review in place (state: ${newState})`);

0 commit comments

Comments
 (0)