diff --git a/src/google.ts b/src/google.ts index e7b5c91c7..a8b8d897a 100644 --- a/src/google.ts +++ b/src/google.ts @@ -26,24 +26,31 @@ export async function getAdminService() { export async function getGithubUsersFromGoogle(): Promise> { const service = await mod.getAdminService() + let githubAccounts = new Set() + let pageToken = null - const userList = await service.users.list({ - customer: 'my_customer', - maxResults: 250, - projection: 'custom', - fields: 'users(customSchemas/Accounts/github(value))', - customFieldMask: 'Accounts', - }) - - const githubAccounts = mod.formatUserList(userList.data.users) + do { + const userList = await service.users.list({ + customer: 'my_customer', + maxResults: 250, + projection: 'custom', + fields: 'users(customSchemas/Accounts/github(value)),nextPageToken', + customFieldMask: 'Accounts', + pageToken: pageToken, + }) + pageToken = userList.data.nextPageToken + githubAccounts = new Set([...githubAccounts, ...formatUserList(userList.data.users)]) + } while (pageToken != null) return githubAccounts } // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types -export function formatUserList(users): Set { +export function formatUserList(users: any[]): Set { return new Set( users - .map((user) => user.customSchemas?.Accounts?.github?.map((account) => account.value?.toLowerCase())) + .map((user) => + user.customSchemas?.Accounts?.github?.map((account: { value: string }) => account.value?.toLowerCase()), + ) .flat() .filter(Boolean), )