Last active
September 6, 2022 21:30
-
-
Save kierandrewett/396867bd2d815cc88b8f3dc90fc61324 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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