feat(scripts): misc (#1542)
This commit is contained in:
1 parent
2c4eefa877
commit
d0c973e9c9
10 files changed
+148
-101
No files matched your search
@@ -2,11 +2,13 @@ import type { Userstyle } from "@/types/userstyles.d.ts";
|
||||
|
||||
import * as assert from "@std/assert";
|
||||
|
||||
import { Octokit } from "@octokit/rest";
|
||||
import { getUserstylesData } from "@/utils.ts";
|
||||
|
||||
const octokit = new Octokit({ auth: Deno.env.get("GITHUB_TOKEN") });
|
||||
const team = { org: "catppuccin", team_slug: "userstyles-maintainers" };
|
||||
import {
|
||||
addUserstylesTeamMember,
|
||||
getAuthenticatedOctokit,
|
||||
getUserstylesData,
|
||||
getUserstylesTeamMembers,
|
||||
removeUserstylesTeamMember,
|
||||
} from "@/utils.ts";
|
||||
|
||||
const { userstyles } = getUserstylesData();
|
||||
|
||||
@@ -26,47 +28,41 @@ const maintainers = [
|
||||
),
|
||||
];
|
||||
|
||||
// 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()));
|
||||
assert.assertExists(maintainers);
|
||||
assert.assert(Array.isArray(maintainers));
|
||||
assert.assertGreater(maintainers.length, 0);
|
||||
|
||||
async function syncMaintainers() {
|
||||
if (!maintainers) return;
|
||||
if (assert.equal(maintainers, teamMembers)) {
|
||||
console.log("Maintainers are in sync");
|
||||
return;
|
||||
}
|
||||
const octokit = getAuthenticatedOctokit();
|
||||
const team = "userstyles-maintainers";
|
||||
const maintainersTeamMembers = await getUserstylesTeamMembers(
|
||||
octokit,
|
||||
team,
|
||||
);
|
||||
|
||||
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.`,
|
||||
);
|
||||
if (assert.equal(maintainers, maintainersTeamMembers)) {
|
||||
console.log("Maintainers are in sync.");
|
||||
Deno.exit(0);
|
||||
}
|
||||
|
||||
await syncMaintainers();
|
||||
const toAdd = maintainers.filter((m) => !maintainersTeamMembers.includes(m));
|
||||
const toRemove = maintainersTeamMembers.filter((m) => !maintainers.includes(m));
|
||||
|
||||
for (const maintainer of toAdd) {
|
||||
await addUserstylesTeamMember(octokit, team, maintainer);
|
||||
console.log(
|
||||
`Added ${maintainer} to the catppuccin/${team} team.`,
|
||||
);
|
||||
}
|
||||
console.log(
|
||||
`${toAdd.length} users added to the catppuccin/${team} team.`,
|
||||
);
|
||||
|
||||
for (const member of toRemove) {
|
||||
await removeUserstylesTeamMember(octokit, team, member);
|
||||
console.log(
|
||||
`Removed ${member} from the catppuccin/${team} team.`,
|
||||
);
|
||||
}
|
||||
console.log(
|
||||
`${toRemove.length} users removed from the catppuccin/${team} team.`,
|
||||
);
|
||||
Reference in new issue
Block a user