From 75580b869682da4aaff0b58240d6e9d967880b5c Mon Sep 17 00:00:00 2001 From: Espen Carlsen Date: Tue, 10 Oct 2023 09:28:08 +0000 Subject: [PATCH 1/2] fix: delete suspended accounts --- src/config.ts | 3 +++ src/google.ts | 1 + tests/config.spec.ts | 25 +++++++++++++++++++++++++ 3 files changed, 29 insertions(+) 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) + }) +}) From d36d8093188b81f78e259247180eac6094d5ece3 Mon Sep 17 00:00:00 2001 From: Espen Carlsen Date: Mon, 16 Oct 2023 06:51:57 +0000 Subject: [PATCH 2/2] doc: updated documentation to include REMOVE_SUSPENDED_USERS --- README.md | 1 + 1 file changed, 1 insertion(+) 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` |