Skip to content

Commit

Permalink
Bots can not be members, only check membership if not bot (#176)
Browse files Browse the repository at this point in the history
  • Loading branch information
ludeeus authored Mar 8, 2023
1 parent 4c981b7 commit 15d9770
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions services/bots/src/github-webhook/handlers/review_drafter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 15d9770

Please sign in to comment.