forked from ajv-validator/ajv
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathget-contributors.js
58 lines (43 loc) · 1.7 KB
/
get-contributors.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// Credit for the script goes to svelte:
// https://github.com/sveltejs/svelte/blob/ce3a5791258ec6ecf8c1ea022cb871afe805a45c/site/scripts/get-contributors.js
const fs = require("fs")
const Jimp = require("jimp")
process.chdir(__dirname)
const base = `https://api.github.com/repos/ajv-validator/ajv/contributors`
const {GH_TOKEN_PUBLIC} = process.env
const SIZE = 64
main()
async function main() {
const fetch = (await import("node-fetch")).default
const contributors = []
let page = 1
// eslint-disable-next-line no-constant-condition
while (true) {
const res = await fetch(`${base}?per_page=100&page=${page++}`, {
headers: {Authorization: `token ${GH_TOKEN_PUBLIC}`},
})
const list = await res.json()
if (list.length === 0) break
contributors.push(...list)
}
const bots = ["dependabot-preview[bot]", "greenkeeper[bot]", "greenkeeperio-bot"]
const authors = contributors
.filter((a) => !bots.includes(a.login))
.sort((a, b) => b.contributions - a.contributions)
const sprite = new Jimp(SIZE * authors.length, SIZE)
for (let i = 0; i < authors.length; i += 1) {
const author = authors[i]
console.log(`${i + 1} / ${authors.length}: ${author.login}`)
const image_data = await fetch(author.avatar_url)
const buffer = await image_data.arrayBuffer()
const image = await Jimp.read(buffer)
image.resize(SIZE, SIZE)
sprite.composite(image, i * SIZE, 0)
}
await sprite.quality(80).write(`../docs/.vuepress/components/Contributors/contributors.jpg`)
const str = `[\n ${authors.map((a) => `"${a.login}"`).join(",\n ")},\n]\n`
fs.writeFileSync(
`../docs/.vuepress/components/Contributors/_contributors.js`,
`module.exports = ${str}`
)
}