Skip to content

Commit

Permalink
Siliu/feature 346 (#377)
Browse files Browse the repository at this point in the history
Merging into a non-master branch, so omitting most of the PR template. #374 has the relevant context.

This PR fixes a bad import and fixes some logic in the isMemberOf matcher.

Also adds 404s as an accepted response.
  • Loading branch information
cyamonide committed Feb 19, 2021
1 parent 1c2ec1f commit e0f20b9
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 29 deletions.
54 changes: 28 additions & 26 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions src/isMemberOf.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import github from '@actions/github';
import { context } from '@actions/github';
import PQueue from 'p-queue';
import { catchHandler } from './util/catchHandler';
import { OctokitClient } from './util/constants';
Expand All @@ -13,7 +13,7 @@ export const handleMembership = async (
isMemberOf: string[] = [],
requestConcurrency = 2
): Promise<boolean> => {
const { repo, actor } = github.context;
const { repo, actor } = context;

const queue = new PQueue({ concurrency: requestConcurrency });

Expand All @@ -32,5 +32,7 @@ export const handleMembership = async (
membershipChecks.map((membership) => queue.add(() => client.teams.getMembershipForUserInOrg(membership)))
).catch(catchHandler(debug));

return (results as Record<string, unknown>[]).some((data: Record<string, unknown>) => data?.status === ACTIVE_STATE);
const isMember = results instanceof Array && (results).some(result => result.data.state === ACTIVE_STATE);

return isMember;
};
1 change: 1 addition & 0 deletions src/util/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export type RuleFile = Partial<OctokitFile> & Required<Pick<OctokitFile, 'filena

export enum AllowedHttpErrors {
UNPROCESSABLE_ENTITY = 422,
NOT_FOUND = 404
}
export enum HttpErrors {
RESOURCE_NOT_ACCESSIBLE = 403,
Expand Down

0 comments on commit e0f20b9

Please sign in to comment.