forked from catppuccin/userstyles
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.ts
More file actions
executable file
路70 lines (60 loc) 路 2.04 KB
/
Copy pathmain.ts
File metadata and controls
executable file
路70 lines (60 loc) 路 2.04 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
65
66
67
68
69
70
#!/usr/bin/env -S deno run -A
import * as assert from "std/assert/mod.ts";
import { Octokit } from "@octokit/rest";
import type { UserStylesSchema } from "@/types/mod.ts";
import { getUserstylesData } from "@/utils.ts";
const octokit = new Octokit({ auth: Deno.env.get("GITHUB_TOKEN") });
const team = { org: "catppuccin", team_slug: "userstyles-maintainers" };
const { userstyles } = getUserstylesData();
// Lowercase usernames of all the "current-maintainers" in the file.
const maintainers = [
...new Set(
Object.values(userstyles).flatMap((
style: UserStylesSchema.Userstyle,
) =>
style.readme["current-maintainers"].map((m) => {
const username = m.url.split("github.com/")?.pop();
// Check that they follow github.com/username pattern.
assert.assertExists(username);
return username.toLowerCase();
})
),
),
];
// Lowercase usernames of all maintainers in the current GitHub team.
const teamMembers = await octokit.teams
.listMembersInOrg({
...team,
per_page: 100,
})
.then((res) => res.data.map((m) => m.login.toLowerCase()));
const syncMaintainers = async () => {
if (!maintainers) return;
if (assert.equal(maintainers, teamMembers)) {
console.log("Maintainers are in sync");
return;
}
const toAdd = maintainers.filter((m) => !teamMembers.includes(m));
const toRemove = teamMembers.filter((m) => !maintainers.includes(m));
for (const m of toAdd) {
await octokit.teams.addOrUpdateMembershipForUserInOrg({
...team,
username: m,
});
console.log(`Added ${m} to the ${team.org}/${team.team_slug} team.`);
}
console.log(
`${toAdd.length} users added to the ${team.org}/${team.team_slug} team.`,
);
for (const m of toRemove) {
await octokit.teams.removeMembershipForUserInOrg({
...team,
username: m,
});
console.log(`Removed ${m} from the ${team.org}/${team.team_slug} team.`);
}
console.log(
`${toRemove.length} users removed from the ${team.org}/${team.team_slug} team.`,
);
};
await syncMaintainers();