Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
rubyowo committed Aug 16, 2023
1 parent 7c58437 commit 47d8d8a
Showing 1 changed file with 43 additions and 24 deletions.
67 changes: 43 additions & 24 deletions src/generate/syncMaintainers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,34 +10,48 @@ type Metadata = {
const ajv = new (Ajv as unknown as (typeof Ajv)["default"])();
const validate = ajv.compile<Metadata>(schema);

const userstylesYaml = Deno.readTextFileSync(
path.join(ROOT, "../userstyles.yml"),
);
const userstylesYaml = Deno.readTextFileSync(path.join(ROOT, "../userstyles.yml"));
const userstylesData = parseYaml(userstylesYaml);
if (!validate(userstylesData)) {
console.error(validate.errors);
Deno.exit(1);
}

const maintainers = [...new Set(Object.values(userstylesData.userstyles).flatMap((style) =>
style.readme["current-maintainers"].map((m) => m.url.split("/").pop().toLowerCase())
))];
const maintainers = [
...new Set(
Object.values(userstylesData.userstyles).flatMap((style) =>
style.readme["current-maintainers"].map((m) =>
m.url.split("/").pop().toLowerCase()
)
)
)
];

const requestGH = async (endpoint: string, method = "GET", returnJson = true, body?: string) => {
const res = await fetch("https://api.github.com/orgs/catppuccin/teams/userstyles-maintainers" + endpoint, {
method,
headers: {
"Authorization": `Bearer ${Deno.args[0]}`
const requestGH = async (
endpoint: string,
method = "GET",
returnJson = true,
body?: string,
) => {
const res = await fetch(
"https://api.github.com/orgs/catppuccin/teams/userstyles-maintainers" +
endpoint,
{
method,
headers: {
"Authorization": `Bearer ${Deno.args[0]}`,
},
body,
},
body,
})
return returnJson ? res.json() : res
}
);
return returnJson ? res.json() : res;
};

const teamMembers = (await requestGH("/members")).map(l => l.login.toLowerCase());
const teamMembers = (await requestGH("/members")).map((l: { login: string; }) => l.login.toLowerCase());

const checkEquality = (a, b) => a.length === b.length && a.every((e: string) => b.includes(e));
const getExtra = (a, b) => a.filter((e: string) => !b.includes(e))
const checkEquality = (a: string[], b: string[]) =>
a.length === b.length && a.every((e) => b.includes(e));
const getExtra = (a: string[], b: string[]) => a.filter((e) => !b.includes(e));

const syncMaintainers = async () => {
if (checkEquality(maintainers, teamMembers)) {
Expand All @@ -46,14 +60,19 @@ const syncMaintainers = async () => {
}
if (maintainers.length > teamMembers.length) {
for (const m of getExtra(maintainers, teamMembers)) {
await requestGH(`/memberships/${m}`, 'PUT', false, JSON.stringify({ role: "member" }))
console.log(`Added ${m} to the team`)
await requestGH(
`/memberships/${m}`,
"PUT",
false,
JSON.stringify({ role: "member" }),
);
console.log(`Added ${m} to the team`);
}
} else {
for (const m of getExtra(teamMembers, maintainers)) {
await requestGH(`/memberships/${m}`, 'DELETE', false)
console.log(`Removed ${m} from the team`)
await requestGH(`/memberships/${m}`, "DELETE", false);
console.log(`Removed ${m} from the team`);
}
}
}
await syncMaintainers()
};
await syncMaintainers();

0 comments on commit 47d8d8a

Please sign in to comment.