Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dismiss bot review when marked as ready #209

Merged
merged 3 commits into from
Oct 3, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions services/bots/src/github-webhook/handlers/review_drafter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,14 @@ export class ReviewDrafter extends BaseWebhookHandler {
const { data: reviews } = await context.github.pulls.listReviews(
context.pullRequest({ per_page: 100 }),
);

const requestedChanges = reviews.filter((review) => review.state === 'CHANGES_REQUESTED');
const reviewers = new Set(
reviews
.filter((review) => review.state === 'CHANGES_REQUESTED')
requestedChanges
.filter(
// Sometimes GitHub sends it as "bot" and sometimes as "Bot
(review) => review.user.type.toLowerCase() !== 'bot',
)
.map((review) => review.user.login),
);

Expand All @@ -101,5 +106,17 @@ export class ReviewDrafter extends BaseWebhookHandler {
context.pullRequest({ reviewers: Array.from(reviewers) }),
);
}

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 all bot reviews
await context.github.pulls.dismissReview(
context.pullRequest({ review_id: review.id, message: 'Stale' }),
);
}
}
}