From 15d977074fa6684b411328fb7c61b7d50c91d6f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20S=C3=B8rensen?= Date: Wed, 8 Mar 2023 12:06:07 +0100 Subject: [PATCH] Bots can not be members, only check membership if not bot (#176) --- .../github-webhook/handlers/review_drafter.ts | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/services/bots/src/github-webhook/handlers/review_drafter.ts b/services/bots/src/github-webhook/handlers/review_drafter.ts index f3ff626..3ab8d8e 100644 --- a/services/bots/src/github-webhook/handlers/review_drafter.ts +++ b/services/bots/src/github-webhook/handlers/review_drafter.ts @@ -43,19 +43,22 @@ export class ReviewDrafter extends BaseWebhookHandler { return; } - try { - const { data: reviewerMembership } = await context.github.orgs.getMembershipForUser({ - org: context.organization, - username: context.payload.review.user.login, - }); + if (context.payload.sender.type !== 'Bot') { + // Check if the author is a member of the organization + try { + const { data: reviewerMembership } = await context.github.orgs.getMembershipForUser({ + org: context.organization, + username: context.payload.review.user.login, + }); - if (!['admin', 'member'].includes(reviewerMembership.role)) { - // If the author is not admin or member, we don't need to do anything + if (!['admin', 'member'].includes(reviewerMembership.role)) { + // If the author is not admin or member, we don't need to do anything + return; + } + } catch (ev: any) { + // We get an error if the user is not a member of the organization return; } - } catch (ev: any) { - // We get an error if the user is not a member of the organization - return; } // Mark PR as draft, this is not available in the REST API, so we use our helper