Skip to content

Instantly share code, notes, and snippets.

@0xBigBoss
Last active October 25, 2023 18:07
Show Gist options
  • Save 0xBigBoss/0cf35bd2ad612aff77dd2840230ac997 to your computer and use it in GitHub Desktop.
Save 0xBigBoss/0cf35bd2ad612aff77dd2840230ac997 to your computer and use it in GitHub Desktop.
ZX script to fetch all contributors to an organization public repos.
#!/usr/bin/env zx
// -*- mode: js -*-
const orgName = process.argv[3];
if (!orgName) {
console.log(`Usage: gh-org-contribs ${chalk.bold("<org-name>")}`);
process.exit(1);
}
console.log(chalk.blue(`Fetching contributors for ${orgName}`));
$.verbose = false;
async function ensureDependencies() {
if (!(await which("gh"))) {
console.log(chalk.red("GitHub CLI is not installed. brew install gh"));
process.exit(1);
}
}
async function getRepos(org) {
let output = await $`gh api orgs/${org}/repos --paginate`;
let data = JSON.parse(output.stdout);
const repos = [...data.map((r) => r.name)];
return repos;
}
async function getContributors(org, repo) {
let output = await $`gh api repos/${org}/${repo}/contributors --paginate`;
let data = JSON.parse(output.stdout);
return data.map((contributor) => contributor.login);
}
(async function main() {
await ensureDependencies();
const repos = await getRepos(orgName);
let allContributors = new Set();
for (let repo of repos) {
console.log(chalk.dim(`Fetching contributors for ${repo}`));
const contributors = await getContributors(orgName, repo);
contributors.forEach((c) => allContributors.add(c));
}
// add a link to each contributor's profile
allContributors = [...allContributors].map((c) => {
return {
name: c,
link: `https://github.com/${c}`,
};
});
console.table(allContributors);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment