-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathindex.ts
More file actions
64 lines (53 loc) · 2.18 KB
/
index.ts
File metadata and controls
64 lines (53 loc) · 2.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import { getGithubUsersFromGoogle } from './src/google'
import { getGithubUsersFromGithub, addUsersToGitHubOrg, removeUsersFromGitHubOrg, OperationError } from './src/github'
import { config } from './src/config'
import { notifySlack } from './src/slack'
export async function run(): Promise<void> {
const googleUsers = await getGithubUsersFromGoogle()
console.log(`Users from google: ${Array.from(googleUsers).join(', ')}`)
const gitHubUsers = await getGithubUsersFromGithub()
console.log(`Users from github: ${Array.from(gitHubUsers).join(', ')}`)
const usersNotInGithub = new Set(Array.from(googleUsers).filter((x) => !gitHubUsers.has(x)))
const usersNotInGoogle = new Set(Array.from(gitHubUsers).filter((x) => !googleUsers.has(x)))
let unfixedMismatch = false
const allErrors: OperationError[] = []
const addedUsers: string[] = []
const removedUsers: string[] = []
if (usersNotInGithub.size > 0) {
console.log(`Users not in github: ${Array.from(usersNotInGithub).join(', ')}`)
if (config.addUsers) {
const result = await addUsersToGitHubOrg(usersNotInGithub)
addedUsers.push(...result.success)
if (result.errors.length > 0) {
allErrors.push(...result.errors)
}
} else {
unfixedMismatch = true
}
}
if (usersNotInGoogle.size > 0) {
console.log(`Users not in google: ${Array.from(usersNotInGoogle).join(', ')}`)
if (config.removeUsers) {
const result = await removeUsersFromGitHubOrg(usersNotInGoogle)
removedUsers.push(...result.success)
if (result.errors.length > 0) {
allErrors.push(...result.errors)
}
} else {
unfixedMismatch = true
}
}
if (allErrors.length > 0) {
console.error(`\n--- ERRORS SUMMARY ---`)
for (const err of allErrors) {
console.error(`[${err.operation.toUpperCase()}] ${err.user}: ${err.message}`)
}
console.error(`Total errors: ${allErrors.length}`)
}
await notifySlack(addedUsers, removedUsers, allErrors, config.githubOrg)
const hasErrors = allErrors.length > 0
const exitCode = unfixedMismatch || hasErrors ? config.exitCodeOnMissmatch : 0
process.exit(exitCode)
}
// istanbul ignore next
if (require.main === module) run()