diff --git a/README.md b/README.md index 37f89d224..3ca9fe0ad 100644 --- a/README.md +++ b/README.md @@ -140,6 +140,7 @@ updates: | `GOOGLE_CREDENTIALS` | Base64'd json as downloaded from the google service account creation step | `Zm9vCg==` | `null` | | `ADD_USERS` | Set to TRUE to add users to the github organisation | `TRUE` | `false` | | `REMOVE_USERS` | Set to TRUE to remove users from the github organisation | `TRUE` | `false` | +| `REMOVE_SUSPENDED_USERS` | Set to TRUE to remove users from the github organisation that are suspended in Google | `TRUE` | `false` | | `EXIT_CODE_ON_MISMATCH` | Exit code to use when there's a mismatch, useful when combined with `ADD_USERS` and `REMOVE_USERS` to be used in a dry-run mode | `1` | `0` | | `GITHUB_ORG` | GitHub Organization | `chrisnstest` | `null` | | `GITHUB_APP_ID` | GitHub App ID | `106341` | `null` | diff --git a/src/config.ts b/src/config.ts index 3b8a8c31b..bb0d00223 100644 --- a/src/config.ts +++ b/src/config.ts @@ -32,6 +32,9 @@ export const config = { get googleEmailAddress(): string { return process.env.GOOGLE_EMAIL_ADDRESS ?? '' }, + get removeSuspendedUsers(): boolean { + return process.env.REMOVE_SUSPENDED_USERS?.toLowerCase() === 'true' + }, } export interface googleCredentials { diff --git a/src/google.ts b/src/google.ts index 5e090534a..aaf8a741d 100644 --- a/src/google.ts +++ b/src/google.ts @@ -37,6 +37,7 @@ export async function getGithubUsersFromGoogle(): Promise> { fields: 'users(customSchemas/Accounts/github(value)),nextPageToken', customFieldMask: 'Accounts', pageToken: pageToken, + query: config.removeSuspendedUsers ? 'isSuspended=false' : '', }) pageToken = userList.data.nextPageToken githubAccounts = new Set([...githubAccounts, ...formatUserList(userList.data.users)]) diff --git a/tests/config.spec.ts b/tests/config.spec.ts index 9dda40e15..158f19ae2 100644 --- a/tests/config.spec.ts +++ b/tests/config.spec.ts @@ -156,3 +156,28 @@ describe('googleEmailAddress', () => { expect(mod.config.googleEmailAddress).toStrictEqual('hello') }) }) + +describe('removeSuspendedUsers', () => { + beforeEach(() => { + delete process.env.REMOVE_SUSPENDED_USERS + }) + it('no value', () => { + expect(mod.config.removeSuspendedUsers).toStrictEqual(false) + }) + it('invalid value', () => { + process.env.REMOVE_SUSPENDED_USERS = 'foobar' + expect(mod.config.removeSuspendedUsers).toStrictEqual(false) + }) + it('false value', () => { + process.env.REMOVE_SUSPENDED_USERS = 'false' + expect(mod.config.removeSuspendedUsers).toStrictEqual(false) + }) + it('true value', () => { + process.env.REMOVE_SUSPENDED_USERS = 'true' + expect(mod.config.removeSuspendedUsers).toStrictEqual(true) + }) + it('true value mixed case', () => { + process.env.REMOVE_SUSPENDED_USERS = 'tRuE' + expect(mod.config.removeSuspendedUsers).toStrictEqual(true) + }) +})