Skip to content

Commit 6bb2c7c

Browse files
committed
Ensure function iterates over all results from google
1 parent e23b152 commit 6bb2c7c

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

src/google.ts

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,24 +26,31 @@ export async function getAdminService() {
2626

2727
export async function getGithubUsersFromGoogle(): Promise<Set<string>> {
2828
const service = await mod.getAdminService()
29+
let githubAccounts = new Set<string>()
30+
let pageToken = null
2931

30-
const userList = await service.users.list({
31-
customer: 'my_customer',
32-
maxResults: 250,
33-
projection: 'custom',
34-
fields: 'users(customSchemas/Accounts/github(value))',
35-
customFieldMask: 'Accounts',
36-
})
37-
38-
const githubAccounts = mod.formatUserList(userList.data.users)
32+
do {
33+
const userList = await service.users.list({
34+
customer: 'my_customer',
35+
maxResults: 250,
36+
projection: 'custom',
37+
fields: 'users(customSchemas/Accounts/github(value)),nextPageToken',
38+
customFieldMask: 'Accounts',
39+
pageToken: pageToken,
40+
})
41+
pageToken = userList.data.nextPageToken
42+
githubAccounts = new Set([...githubAccounts, ...formatUserList(userList.data.users)])
43+
} while (pageToken != null)
3944
return githubAccounts
4045
}
4146

4247
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
43-
export function formatUserList(users): Set<string> {
48+
export function formatUserList(users: any[]): Set<string> {
4449
return new Set(
4550
users
46-
.map((user) => user.customSchemas?.Accounts?.github?.map((account) => account.value?.toLowerCase()))
51+
.map((user) =>
52+
user.customSchemas?.Accounts?.github?.map((account: { value: string }) => account.value?.toLowerCase()),
53+
)
4754
.flat()
4855
.filter(Boolean),
4956
)

0 commit comments

Comments
 (0)