Skip to content

Commit 5478232

Browse files
committed
Dismiss stale action reviews reliably with review marker
1 parent 1aa392c commit 5478232

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

scripts/comment-pr-findings.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
const fs = require('fs');
88
const { spawnSync } = require('child_process');
9+
const REVIEW_MARKER = '<!-- nutrient-code-review-action -->';
910

1011
// Parse GitHub context from environment
1112
const context = {
@@ -91,6 +92,7 @@ function addReactionsToReview(reviewId) {
9192
// Check if a review was posted by this action
9293
function isOwnReview(review) {
9394
if (!review.body) return false;
95+
if (review.body.includes(REVIEW_MARKER)) return true;
9496

9597
// Check for our review summary patterns
9698
const ownPatterns = [
@@ -124,10 +126,13 @@ function dismissStaleReviews() {
124126
let dismissedCount = 0;
125127
for (const review of reviews) {
126128
const isDismissible = review.state === 'APPROVED' || review.state === 'CHANGES_REQUESTED';
127-
const isBot = review.user && review.user.type === 'Bot';
128129
const isOwn = isOwnReview(review);
130+
const hasMarker = Boolean(review.body && review.body.includes(REVIEW_MARKER));
131+
const isBot = review.user && review.user.type === 'Bot';
132+
const canDismissLegacyReview = isBot && isOwn;
133+
const canDismissMarkedReview = hasMarker;
129134

130-
if (isBot && isDismissible && isOwn) {
135+
if (isDismissible && (canDismissMarkedReview || canDismissLegacyReview)) {
131136
try {
132137
ghApi(
133138
`/repos/${context.repo.owner}/${context.repo.repo}/pulls/${context.issue.number}/reviews/${review.id}/dismissals`,
@@ -231,7 +236,7 @@ async function run() {
231236

232237
const { high: highSeverityCount } = countSeverities(newFindings);
233238
const reviewEvent = highSeverityCount > 0 ? 'REQUEST_CHANGES' : 'APPROVE';
234-
const reviewBody = buildReviewSummary(newFindings);
239+
const reviewBody = `${buildReviewSummary(newFindings)}\n\n${REVIEW_MARKER}`;
235240

236241
// Prepare review comments
237242
const reviewComments = [];

0 commit comments

Comments
 (0)