()
| 27 | ); |
| 28 | |
| 29 | async function syncUsers() { |
| 30 | /** The authenticated Github client for performing actions. */ |
| 31 | const github = await getAuthenticatedGithubClient(); |
| 32 | /** The firestore collection for blocked users */ |
| 33 | const blockedUsersCollection = getBlockedUsersCollection(); |
| 34 | /** A Firestore batch, allowing for atomic updating of the blocked users. */ |
| 35 | const writeBatch = blockedUsersCollection.firestore.batch(); |
| 36 | |
| 37 | /** |
| 38 | * A Date object one year from today, the default block length applied for users discovered |
| 39 | * from Githubs listing. |
| 40 | */ |
| 41 | const oneYearFromToday = (() => { |
| 42 | const date = new Date(); |
| 43 | date.setFullYear(date.getFullYear() + 1); |
| 44 | return date; |
| 45 | })(); |
| 46 | |
| 47 | /** All of the currently blocked users for the Angular organization. */ |
| 48 | const blockedUsers = await github.paginate(github.orgs.listBlockedUsers, { |
| 49 | org: 'angular', |
| 50 | per_page: 100, |
| 51 | }); |
| 52 | |
| 53 | for (let blockedUser of blockedUsers) { |
| 54 | const firebaseUser = await blockedUsersCollection.doc(blockedUser.login).get(); |
| 55 | // For users we already know about from Github, we skip their records. |
| 56 | if (firebaseUser.exists) { |
| 57 | continue; |
| 58 | } |
| 59 | |
| 60 | writeBatch.create(firebaseUser.ref, { |
| 61 | blockedBy: 'Imported From Github', |
| 62 | blockedOn: new Date(), |
| 63 | blockUntil: oneYearFromToday, |
| 64 | comments: 'This record was automatically imported from Github', |
| 65 | context: 'Unknown', |
| 66 | username: blockedUser.login, |
| 67 | }); |
| 68 | } |
| 69 | await writeBatch.commit(); |
| 70 | } |
no test coverage detected