get-contributors.js 1.7 KB

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