Skip to content

Commit 7dc9453

Browse files
committed
Use review marker only for stale review dismissal
1 parent 5478232 commit 7dc9453

2 files changed

Lines changed: 6 additions & 29 deletions

File tree

scripts/comment-pr-findings.bun.test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -849,7 +849,7 @@ describe('comment-pr-findings.js', () => {
849849
});
850850

851851
describe('Stale Review Handling', () => {
852-
test('should only dismiss own bot reviews when DISMISS_STALE_REVIEWS is true', async () => {
852+
test('should only dismiss marker-tagged reviews when DISMISS_STALE_REVIEWS is true', async () => {
853853
process.env.DISMISS_STALE_REVIEWS = 'true';
854854

855855
const mockFindings = [{
@@ -864,13 +864,13 @@ describe('comment-pr-findings.js', () => {
864864

865865
const mockReviews = [
866866
// Our reviews - should be dismissed
867-
{ id: 101, state: 'CHANGES_REQUESTED', user: { type: 'Bot' }, body: 'Found 3 security issues. Please address the high-severity issues before merging.' },
868-
{ id: 102, state: 'APPROVED', user: { type: 'Bot' }, body: 'No issues found. Changes look good.' },
867+
{ id: 101, state: 'CHANGES_REQUESTED', user: { type: 'Bot' }, body: 'Found 3 security issues. Please address the high-severity issues before merging.\n\n<!-- nutrient-code-review-action -->' },
868+
{ id: 102, state: 'APPROVED', user: { type: 'Bot' }, body: 'No issues found. Changes look good.\n\n<!-- nutrient-code-review-action -->' },
869869
// Other bot reviews - should NOT be dismissed
870870
{ id: 103, state: 'APPROVED', user: { type: 'Bot' }, body: 'Dependabot has approved this PR.' },
871871
{ id: 104, state: 'CHANGES_REQUESTED', user: { type: 'Bot' }, body: 'Renovate: This PR has conflicts.' },
872872
// COMMENTED state - should NOT be dismissed
873-
{ id: 105, state: 'COMMENTED', user: { type: 'Bot' }, body: 'Found 1 security issue.' },
873+
{ id: 105, state: 'COMMENTED', user: { type: 'Bot' }, body: 'Found 1 security issue.\n\n<!-- nutrient-code-review-action -->' },
874874
// User review - should NOT be dismissed
875875
{ id: 106, state: 'CHANGES_REQUESTED', user: { type: 'User' }, body: 'Please fix the typo.' }
876876
];

scripts/comment-pr-findings.js

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -92,26 +92,7 @@ function addReactionsToReview(reviewId) {
9292
// Check if a review was posted by this action
9393
function isOwnReview(review) {
9494
if (!review.body) return false;
95-
if (review.body.includes(REVIEW_MARKER)) return true;
96-
97-
// Check for our review summary patterns
98-
const ownPatterns = [
99-
'No issues found. Changes look good.',
100-
/^Found \d+ .+ issues?\./,
101-
'Please address the high-severity issues before merging.',
102-
'Consider addressing the suggestions in the comments.',
103-
'Minor suggestions noted in comments.'
104-
];
105-
106-
for (const pattern of ownPatterns) {
107-
if (pattern instanceof RegExp) {
108-
if (pattern.test(review.body)) return true;
109-
} else {
110-
if (review.body.includes(pattern)) return true;
111-
}
112-
}
113-
114-
return false;
95+
return review.body.includes(REVIEW_MARKER);
11596
}
11697

11798
// Helper function to dismiss stale bot reviews from this action only
@@ -127,12 +108,8 @@ function dismissStaleReviews() {
127108
for (const review of reviews) {
128109
const isDismissible = review.state === 'APPROVED' || review.state === 'CHANGES_REQUESTED';
129110
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;
134111

135-
if (isDismissible && (canDismissMarkedReview || canDismissLegacyReview)) {
112+
if (isDismissible && isOwn) {
136113
try {
137114
ghApi(
138115
`/repos/${context.repo.owner}/${context.repo.repo}/pulls/${context.issue.number}/reviews/${review.id}/dismissals`,

0 commit comments

Comments
 (0)