Skip to content
This repository has been archived by the owner on Sep 19, 2024. It is now read-only.

fix: crash on missing membership #928

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
22 changes: 13 additions & 9 deletions src/helpers/issue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,15 +163,19 @@ export async function isUserAdminOrBillingManager(

async function checkIfIsBillingManager() {
if (!payload.organization) throw context.logger.fatal(`No organization found in payload!`);
const { data: membership } = await context.octokit.rest.orgs.getMembershipForUser({
org: payload.organization.login,
username: payload.repository.owner.login,
});

console.trace(membership);
if (membership.role === "billing_manager") {
return true;
} else {
try {
const { data: membership } = await context.octokit.rest.orgs.getMembershipForUser({
org: payload.organization.login,
username: payload.repository.owner.login,
});

console.trace(membership);
return membership.role === "billing_manager";
} catch (e) {
context.logger.error(
`Could not get the Billing Manager status for ${payload.repository.owner.login} within ${payload.organization.login}`,
e
);
return false;
}
}
Expand Down
Loading