diff --git a/scripts/github-test-utils.mjs b/scripts/github-test-utils.mjs index 9ecc24927846..bed83e1d3925 100644 --- a/scripts/github-test-utils.mjs +++ b/scripts/github-test-utils.mjs @@ -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) : [])), @@ -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() }, }, }; diff --git a/scripts/junior-requesters.mjs b/scripts/junior-requesters.mjs index 4af68f64a14b..f8d189bd7e26 100644 --- a/scripts/junior-requesters.mjs +++ b/scripts/junior-requesters.mjs @@ -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) { @@ -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) { diff --git a/scripts/team-review-gate.test.mjs b/scripts/team-review-gate.test.mjs index dc9763e1645f..d618255ccbff 100644 --- a/scripts/team-review-gate.test.mjs +++ b/scripts/team-review-gate.test.mjs @@ -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();