Skip to content

Instantly share code, notes, and snippets.

@kierandrewett
Last active September 6, 2022 21:30
Show Gist options
  • Save kierandrewett/396867bd2d815cc88b8f3dc90fc61324 to your computer and use it in GitHub Desktop.
Save kierandrewett/396867bd2d815cc88b8f3dc90fc61324 to your computer and use it in GitHub Desktop.
import axios from "axios";
import { writeFileSync } from "fs";
import { resolve } from "path";
const config = {
headers: {
authorization: process.env.ROBOT_TOKEN
? `token ${process.env.ROBOT_TOKEN}`
: ``,
},
};
const run = async () => {
const repos = [
"dothq/browser",
"dothq/browser-desktop",
"dothq/browser-android",
];
const users = new Set();
for await (const repo of repos) {
const { data } = await axios.get(
`https://api.github.com/repos/${repo}/contributors?per_page=100`,
config
);
data.forEach((u) => users.add(u.login));
}
const contributors = [];
for await (const user of Array.from(users)) {
const d = { username: user, name: user };
const {
data: { name, id },
} = await axios.get(
`https://api.github.com/users/${user}`,
config
);
if (name && name.length) {
d.name = name;
}
contributors.push(d);
}
const file = ["# Contributors"];
for (const { username, name } of contributors
.filter(
(c) =>
!(
c.name.includes("[bot]") ||
c.username.includes("[bot]")
)
)
.sort((a, b) => a.name.localeCompare(b.name))) {
file.push(
`* ${name} ([@${username}](https://github.com/${username}))`
);
}
writeFileSync(
resolve(process.cwd(), "CONTRIBUTORS.md"),
file.join("\n")
);
};
run();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment