diff --git a/plugins/catalog-backend-module-github/src/lib/github.ts b/plugins/catalog-backend-module-github/src/lib/github.ts index 8d8410b182..bd77df4da7 100644 --- a/plugins/catalog-backend-module-github/src/lib/github.ts +++ b/plugins/catalog-backend-module-github/src/lib/github.ts @@ -214,19 +214,19 @@ export async function getOrganizationUsers( // There is no user -> teams edge, so we leave the memberships empty for // now and let the team iteration handle it instead - const users = await queryWithPaging( + const users = await queryWithPaging({ client, query, org, - r => r.organization?.membersWithRole, - userTransformer, - { + connection: r => r.organization?.membersWithRole, + transformer: userTransformer, + variables: { org, email: tokenType === 'token', organizationMembersPageSize: pageSizes.organizationMembers, }, - u => (excludeSuspendedUsers ? !u.suspendedAt : true), - ); + filter: u => (excludeSuspendedUsers ? !u.suspendedAt : true), + }); return { users }; } @@ -311,18 +311,18 @@ export async function getOrganizationTeams( return await teamTransformer(team, ctx); }; - const teams = await queryWithPaging( + const teams = await queryWithPaging({ client, query, org, - r => r.organization?.teams, - materialisedTeams, - { + connection: r => r.organization?.teams, + transformer: materialisedTeams, + variables: { org, teamsPageSize: pageSizes.teams, membersPageSize: pageSizes.teamMembers, }, - ); + }); return { teams }; } @@ -405,19 +405,19 @@ export async function getOrganizationTeamsFromUsers( return await teamTransformer(team, ctx); }; - const teams = await queryWithPaging( + const teams = await queryWithPaging({ client, query, org, - r => r.organization?.teams, - materialisedTeams, - { + connection: r => r.organization?.teams, + transformer: materialisedTeams, + variables: { org, userLogins, teamsPageSize: pageSizes.teams, membersPageSize: pageSizes.teamMembers, }, - ); + }); return { teams }; } @@ -464,14 +464,14 @@ export async function getOrganizationTeamsForUser( return await teamTransformer(team, ctx); }; - const teams = await queryWithPaging( + const teams = await queryWithPaging({ client, query, org, - r => r.organization?.teams, - materialisedTeams, - { org, userLogins: [userLogin], teamsPageSize: pageSizes.teams }, - ); + connection: r => r.organization?.teams, + transformer: materialisedTeams, + variables: { org, userLogins: [userLogin], teamsPageSize: pageSizes.teams }, + }); return { teams }; } @@ -492,14 +492,14 @@ export async function getOrganizationsFromUser( } }`; - const orgs = await queryWithPaging( + const orgs = await queryWithPaging({ client, query, - '', - r => r.user?.organizations, - async o => o.login, - { user }, - ); + org: '', + connection: r => r.user?.organizations, + transformer: async o => o.login, + variables: { user }, + }); return { orgs }; } @@ -638,14 +638,18 @@ export async function getOrganizationRepositories( } }`; - const repositories = await queryWithPaging( + const repositories = await queryWithPaging({ client, query, org, - r => r.repositoryOwner?.repositories, - async x => x, - { org, catalogPathRef, repositoriesPageSize: pageSizes.repositories }, - ); + connection: r => r.repositoryOwner?.repositories, + transformer: async x => x, + variables: { + org, + catalogPathRef, + repositoriesPageSize: pageSizes.repositories, + }, + }); return { repositories }; } @@ -733,14 +737,14 @@ export async function getTeamMembers( } }`; - const members = await queryWithPaging( + const members = await queryWithPaging({ client, query, org, - r => r.organization?.team?.members, - async user => user, - { org, teamSlug, membersPageSize: pageSizes.teamMembers }, - ); + connection: r => r.organization?.team?.members, + transformer: async user => user, + variables: { org, teamSlug, membersPageSize: pageSizes.teamMembers }, + }); return { members }; } @@ -754,33 +758,36 @@ export async function getTeamMembers( * * Requires that the query accepts a $cursor variable. * - * @param client - The octokit client - * @param query - The query to execute - * @param org - The slug of the org to read - * @param connection - A function that, given the response, picks out the actual + * @param params - Object containing all parameters + * @param params.client - The octokit client + * @param params.query - The query to execute + * @param params.org - The slug of the org to read + * @param params.connection - A function that, given the response, picks out the actual * Connection object that's being iterated - * @param transformer - A function that, given one of the nodes in the Connection, + * @param params.transformer - A function that, given one of the nodes in the Connection, * returns the model mapped form of it - * @param variables - The variable values that the query needs, minus the cursor - * @param filter - An optional filter function to filter the nodes before transforming them + * @param params.variables - The variable values that the query needs, minus the cursor + * @param params.filter - An optional filter function to filter the nodes before transforming them */ export async function queryWithPaging< GraphqlType, OutputType, Variables extends {}, Response = QueryResponse, ->( - client: typeof graphql, - query: string, - org: string, - connection: (response: Response) => Connection | undefined, +>(params: { + client: typeof graphql; + query: string; + org: string; + connection: (response: Response) => Connection | undefined; transformer: ( item: GraphqlType, ctx: TransformerContext, - ) => Promise, - variables: Variables, - filter?: (item: GraphqlType) => boolean, -): Promise { + ) => Promise; + variables: Variables; + filter?: (item: GraphqlType) => boolean; +}): Promise { + const { client, query, org, connection, transformer, variables, filter } = + params; const result: OutputType[] = []; const sleep = (ms: number) => new Promise(r => setTimeout(r, ms));