From faf46553f5baa76c1c3d11f82e74562c5126f707 Mon Sep 17 00:00:00 2001 From: ludeeus Date: Tue, 3 Oct 2023 17:40:09 +0000 Subject: [PATCH 1/3] Dismiss bot reviews when PR is marked as ready for review --- .../bots/src/github-webhook/handlers/review_drafter.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/services/bots/src/github-webhook/handlers/review_drafter.ts b/services/bots/src/github-webhook/handlers/review_drafter.ts index 3ab8d8e..84d9604 100644 --- a/services/bots/src/github-webhook/handlers/review_drafter.ts +++ b/services/bots/src/github-webhook/handlers/review_drafter.ts @@ -101,5 +101,15 @@ export class ReviewDrafter extends BaseWebhookHandler { context.pullRequest({ reviewers: Array.from(reviewers) }), ); } + + // Sometimes GitHub sends it as "bot" and sometimes as "Bot + const botReviewes = reviews.filter((review) => review.user.type.toLocaleLowerCase() === 'bot'); + + for (const review of botReviewes) { + // Dismiss the bot reviews + await context.github.pulls.dismissReview( + context.pullRequest({ review_id: review.id, message: 'Stale' }), + ); + } } } From c6602df9e3520432a5ce10e7312dd1aab4212742 Mon Sep 17 00:00:00 2001 From: ludeeus Date: Tue, 3 Oct 2023 17:42:33 +0000 Subject: [PATCH 2/3] Only check CHANGES_REQUESTED --- .../src/github-webhook/handlers/review_drafter.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/services/bots/src/github-webhook/handlers/review_drafter.ts b/services/bots/src/github-webhook/handlers/review_drafter.ts index 84d9604..5fc7ab2 100644 --- a/services/bots/src/github-webhook/handlers/review_drafter.ts +++ b/services/bots/src/github-webhook/handlers/review_drafter.ts @@ -89,11 +89,9 @@ export class ReviewDrafter extends BaseWebhookHandler { const { data: reviews } = await context.github.pulls.listReviews( context.pullRequest({ per_page: 100 }), ); - const reviewers = new Set( - reviews - .filter((review) => review.state === 'CHANGES_REQUESTED') - .map((review) => review.user.login), - ); + + const requestedChanges = reviews.filter((review) => review.state === 'CHANGES_REQUESTED'); + const reviewers = new Set(requestedChanges.map((review) => review.user.login)); if (reviewers.size) { // Request review from all reviewers that have requested changes. @@ -103,7 +101,9 @@ export class ReviewDrafter extends BaseWebhookHandler { } // Sometimes GitHub sends it as "bot" and sometimes as "Bot - const botReviewes = reviews.filter((review) => review.user.type.toLocaleLowerCase() === 'bot'); + const botReviewes = requestedChanges.filter( + (review) => review.user.type.toLowerCase() === 'bot', + ); for (const review of botReviewes) { // Dismiss the bot reviews From 695433b82b8c06f1914b43da1a9109543e1fb7ee Mon Sep 17 00:00:00 2001 From: ludeeus Date: Tue, 3 Oct 2023 17:52:40 +0000 Subject: [PATCH 3/3] filter bots out of re-requests --- .../src/github-webhook/handlers/review_drafter.ts | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/services/bots/src/github-webhook/handlers/review_drafter.ts b/services/bots/src/github-webhook/handlers/review_drafter.ts index 5fc7ab2..ef11bbc 100644 --- a/services/bots/src/github-webhook/handlers/review_drafter.ts +++ b/services/bots/src/github-webhook/handlers/review_drafter.ts @@ -91,7 +91,14 @@ export class ReviewDrafter extends BaseWebhookHandler { ); const requestedChanges = reviews.filter((review) => review.state === 'CHANGES_REQUESTED'); - const reviewers = new Set(requestedChanges.map((review) => review.user.login)); + const reviewers = new Set( + requestedChanges + .filter( + // Sometimes GitHub sends it as "bot" and sometimes as "Bot + (review) => review.user.type.toLowerCase() !== 'bot', + ) + .map((review) => review.user.login), + ); if (reviewers.size) { // Request review from all reviewers that have requested changes. @@ -100,13 +107,13 @@ export class ReviewDrafter extends BaseWebhookHandler { ); } - // Sometimes GitHub sends it as "bot" and sometimes as "Bot const botReviewes = requestedChanges.filter( + // Sometimes GitHub sends it as "bot" and sometimes as "Bot (review) => review.user.type.toLowerCase() === 'bot', ); for (const review of botReviewes) { - // Dismiss the bot reviews + // Dismiss all bot reviews await context.github.pulls.dismissReview( context.pullRequest({ review_id: review.id, message: 'Stale' }), );