MCPcopy Create free account
hub / github.com/angular/dev-infra / syncUsers

Function syncUsers

apps/functions/code-of-conduct/syncUsers.ts:29–70  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

27);
28
29async 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}

Callers 1

syncUsers.tsFile · 0.85

Calls 4

commitMethod · 0.80
getMethod · 0.45
createMethod · 0.45

Tested by

no test coverage detected