Skip to content
Merged
Show file tree
Hide file tree
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
9 changes: 8 additions & 1 deletion scripts/github-test-utils.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ const profiles = {
d: { login: 'd', name: 'Dan Example' },
};

const contractorProfiles = {
timfish: { login: 'timfish', name: 'Tim Fish' },
RulaKhaled: { login: 'RulaKhaled', name: 'Rola Abuhasna' },
};

export function setup(run, pr, payload) {
const github = {
paginate: vi.fn(async method => (method === github.rest.teams.listMembersInOrg ? Object.values(profiles) : [])),
Expand All @@ -29,7 +34,9 @@ export function setup(run, pr, payload) {
requestReviewers: vi.fn(),
},
teams: { listMembersInOrg: vi.fn() },
users: { getByUsername: vi.fn(async ({ username }) => ({ data: profiles[username] })) },
users: {
getByUsername: vi.fn(async ({ username }) => ({ data: profiles[username] ?? contractorProfiles[username] })),
},
issues: { addAssignees: vi.fn(), addLabels: vi.fn(), removeLabel: vi.fn() },
},
};
Expand Down
17 changes: 10 additions & 7 deletions scripts/junior-requesters.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export function resolveLoginByName(name, members) {

/**
* Returns the GitHub logins of the people who asked Junior for this PR, or nothing for other PRs. Names are only
* matched against the SDK team, so a Slack name can't resolve to an unrelated GitHub user.
* matched against the SDK team and contractors, so a Slack name can't resolve to an unrelated GitHub user.
*/
export async function getJuniorRequesters({ github, core, pr }) {
if (pr.user.login !== JUNIOR_LOGIN) {
Expand All @@ -86,12 +86,15 @@ export async function getJuniorRequesters({ github, core, pr }) {
continue;
}
members ??= await Promise.all(
(
await github.paginate(github.rest.teams.listMembersInOrg, {
org: pr.base.repo.owner.login,
team_slug: TEAM_SLUG,
})
).map(async ({ login }) => (await github.rest.users.getByUsername({ username: login })).data),
[
...(
await github.paginate(github.rest.teams.listMembersInOrg, {
org: pr.base.repo.owner.login,
team_slug: TEAM_SLUG,
})
).map(({ login }) => login),
...CONTRACTORS,
].map(async username => (await github.rest.users.getByUsername({ username })).data),
);
const login = resolveLoginByName(requester.name, members);
if (login) {
Expand Down
6 changes: 6 additions & 0 deletions scripts/team-review-gate.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ describe('labelJuniorPrForTeamReview', () => {
expect(github.rest.issues.addLabels).not.toHaveBeenCalled();
});

it('does not label a Junior PR requested by a contractor who is named, not linked', async () => {
const { github, run } = setup(labelJuniorPrForTeamReview, { user: junior, body: attribution('**Rola Abuhasna**') });
await run();
expect(github.rest.issues.addLabels).not.toHaveBeenCalled();
});

it('labels a Junior PR when any requester is outside the SDK team', async () => {
const { github, run } = setup(labelJuniorPrForTeamReview, { user: junior, body: attribution('@a, @outsider') });
await run();
Expand Down
Loading