Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

required-review: Don't fail on case mismatch for @singleuser pseudo-teams #29322

Merged
merged 3 commits into from
Mar 10, 2023
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fixed

Don't fail on case mismatch for `@singleuser` pseudo-teams.
44 changes: 30 additions & 14 deletions projects/github-actions/required-review/src/team-members.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@ const cache = {};
* @returns {string[]} Team members.
*/
async function fetchTeamMembers( team ) {
// Handle @singleuser virtual teams.
if ( team.startsWith( '@' ) ) {
return [ team.slice( 1 ) ];
}

if ( cache[ team ] ) {
return cache[ team ];
}
Expand All @@ -25,16 +20,37 @@ async function fetchTeamMembers( team ) {
const org = github.context.payload.repository.owner.login;

let members = [];
try {
for await ( const res of octokit.paginate.iterator( octokit.rest.teams.listMembersInOrg, {
org: org,
team_slug: team,
per_page: 100,
} ) ) {
members = members.concat( res.data.map( v => v.login ) );
if ( team.startsWith( '@' ) ) {
// Handle @singleuser virtual teams. Fetch the correct username case from GitHub
// to avoid having to worry about edge cases and Unicode versions and such.
try {
const res = await octokit.rest.users.getByUsername( { username: team.slice( 1 ) } );
members.push( res.data.login );
} catch ( error ) {
throw new WError(
// prettier-ignore
`Failed to query user ${ team } from GitHub: ${ error.response?.data?.message || error.message }`,
error,
{}
);
}
} else {
try {
for await ( const res of octokit.paginate.iterator( octokit.rest.teams.listMembersInOrg, {
org: org,
team_slug: team,
per_page: 100,
} ) ) {
members = members.concat( res.data.map( v => v.login ) );
}
} catch ( error ) {
throw new WError(
// prettier-ignore
`Failed to query ${ org } team ${ team } from GitHub: ${ error.response?.data?.message || error.message }`,
error,
{}
);
}
} catch ( error ) {
throw new WError( `Failed to query ${ org } team ${ team } from GitHub`, error, {} );
}

cache[ team ] = members;
Expand Down