Skip to content
Open
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
29 changes: 18 additions & 11 deletions src/google.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,31 @@ export async function getAdminService() {

export async function getGithubUsersFromGoogle(): Promise<Set<string>> {
const service = await mod.getAdminService()
let githubAccounts = new Set<string>()
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<string> {
export function formatUserList(users: any[]): Set<string> {
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),
)
Expand Down