Skip to content

Commit

Permalink
fix(manage-merge-queue): paginate all members in org
Browse files Browse the repository at this point in the history
  • Loading branch information
danadajian committed Aug 22, 2024
1 parent 1cb1521 commit fe7646d
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 21 deletions.
18 changes: 13 additions & 5 deletions dist/374.index.js

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

2 changes: 1 addition & 1 deletion dist/374.index.js.map

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

22 changes: 15 additions & 7 deletions dist/676.index.js

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

2 changes: 1 addition & 1 deletion dist/676.index.js.map

Large diffs are not rendered by default.

20 changes: 15 additions & 5 deletions src/helpers/is-user-in-team.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,28 @@ import { HelperInputs } from '../types/generated';
import { context } from '@actions/github';
import { octokit } from '../octokit';
import * as core from '@actions/core';
import { MembersInOrg } from '../types/github';

export class IsUserInTeam extends HelperInputs {
login? = '';
team = '';
}

export const isUserInTeam = async ({ login = context.actor, team }: IsUserInTeam) => {
const members = await paginateAllMembersInOrg(team);
core.info(`Checking if ${login} is in team ${team}`);
core.info(`Team members: ${members.map(({ login }) => login).join(', ')}`);
return members.some(({ login: memberLogin }) => memberLogin === login);
};

async function paginateAllMembersInOrg(team: string, page = 1): Promise<MembersInOrg> {
const response = await octokit.teams.listMembersInOrg({
org: context.repo.owner,
team_slug: team
team_slug: team,
per_page: 100
});
core.info(`Checking if ${login} is in team ${team}`);
core.info(`Team members: ${response.data.map(({ login }) => login).join(', ')}`);
return response.data.some(({ login: memberLogin }) => memberLogin === login);
};
if (!response.data.length) {
return [];
}
return response.data.concat(await paginateAllMembersInOrg(team, page + 1));
}
4 changes: 2 additions & 2 deletions src/helpers/manage-merge-queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@ export const manageMergeQueue = async ({
if (pullRequest.labels.find(label => label.name === JUMP_THE_QUEUE_PR_LABEL)) {
if (allow_only_for_maintainers === 'true') {
core.info(`Checking if user ${login} is a maintainer...`);
const isMaintainer = await isUserInTeam({ team: team });
const isMaintainer = await isUserInTeam({ login: context.actor, team: team });
if (!isMaintainer) {
await removeLabelIfExists(JUMP_THE_QUEUE_PR_LABEL, pullRequest.number);
return await createPrComment({
body: `@${login} Only core maintainers can jump the queue. Please have a core maintainer jump the queue for you.`
body: `@${context.actor} Only core maintainers can jump the queue. Please have a core maintainer jump the queue for you.`
});
}
}
Expand Down
1 change: 1 addition & 0 deletions src/types/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export type ChangedFilesList = RestEndpointMethodTypes['pulls']['listFiles']['re
export type ProjectListResponse = RestEndpointMethodTypes['projects']['listForRepo']['response'];
export type ColumnListResponse = RestEndpointMethodTypes['projects']['listColumns']['response'];
export type ChecksUpdateConclusion = RestEndpointMethodTypes['checks']['update']['parameters']['conclusion'];
export type MembersInOrg = RestEndpointMethodTypes['teams']['listMembersInOrg']['response']['data'];

export type GithubError = {
status: number;
Expand Down

0 comments on commit fe7646d

Please sign in to comment.