Skip to content

Commit 2cbad69

Browse files
committed
fix(SA-675): exit 0 when membership changes are successfully applied
Previously, any mismatch would trigger non-zero exit even when ADD_USERS and REMOVE_USERS were enabled and changes were made. Now only exits non-zero when mismatch exists AND changes were not configured to be applied (dry-run mode).
1 parent 3195866 commit 2cbad69

2 files changed

Lines changed: 30 additions & 4 deletions

File tree

index.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,27 @@ export async function run(): Promise<void> {
1212
const usersNotInGithub = new Set(Array.from(googleUsers).filter((x) => !gitHubUsers.has(x)))
1313

1414
const usersNotInGoogle = new Set(Array.from(gitHubUsers).filter((x) => !googleUsers.has(x)))
15+
let unfixedMismatch = false
16+
1517
if (usersNotInGithub.size > 0) {
1618
console.log(`Users not in github: ${Array.from(usersNotInGithub).join(', ')}`)
17-
if (config.addUsers) await addUsersToGitHubOrg(usersNotInGithub)
19+
if (config.addUsers) {
20+
await addUsersToGitHubOrg(usersNotInGithub)
21+
} else {
22+
unfixedMismatch = true
23+
}
1824
}
1925

2026
if (usersNotInGoogle.size > 0) {
2127
console.log(`Users not in google: ${Array.from(usersNotInGoogle).join(', ')}`)
22-
if (config.removeUsers) await removeUsersFromGitHubOrg(usersNotInGoogle)
28+
if (config.removeUsers) {
29+
await removeUsersFromGitHubOrg(usersNotInGoogle)
30+
} else {
31+
unfixedMismatch = true
32+
}
2333
}
2434

25-
const exitCode = usersNotInGoogle.size > 0 || usersNotInGithub.size > 0 ? config.exitCodeOnMissmatch : 0
35+
const exitCode = unfixedMismatch ? config.exitCodeOnMissmatch : 0
2636

2737
process.exit(exitCode)
2838
}

tests/index.spec.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,24 @@ describe('missmatch', () => {
3030
await mod.run()
3131
return expect(processExitSpy).toBeCalledWith(0)
3232
})
33-
it('should exit with 122 if defined when there is a missmatch', async () => {
33+
it('should exit with 122 if defined when there is an unfixed missmatch', async () => {
3434
process.env.EXIT_CODE_ON_MISMATCH = '122'
35+
delete process.env.ADD_USERS
36+
delete process.env.REMOVE_USERS
37+
await mod.run()
38+
return expect(processExitSpy).toBeCalledWith(122)
39+
})
40+
it('should exit with 0 when mismatch is fixed by adding users', async () => {
41+
process.env.EXIT_CODE_ON_MISMATCH = '122'
42+
process.env.ADD_USERS = 'true'
43+
process.env.REMOVE_USERS = 'true'
44+
await mod.run()
45+
return expect(processExitSpy).toBeCalledWith(0)
46+
})
47+
it('should exit with 122 when only add is enabled but remove mismatch exists', async () => {
48+
process.env.EXIT_CODE_ON_MISMATCH = '122'
49+
process.env.ADD_USERS = 'true'
50+
delete process.env.REMOVE_USERS
3551
await mod.run()
3652
return expect(processExitSpy).toBeCalledWith(122)
3753
})

0 commit comments

Comments
 (0)