From edf3f7bed058ab7ad516a1616c19e94d8158df5a Mon Sep 17 00:00:00 2001 From: oldme Date: Wed, 18 Dec 2024 11:00:10 +0800 Subject: [PATCH] chore: add gf-site contributor into contributors --- .github/workflows/generate-contributors.js | 47 ++++++++++++++-------- 1 file changed, 31 insertions(+), 16 deletions(-) diff --git a/.github/workflows/generate-contributors.js b/.github/workflows/generate-contributors.js index daaf3203564..3115d09ab30 100644 --- a/.github/workflows/generate-contributors.js +++ b/.github/workflows/generate-contributors.js @@ -2,7 +2,10 @@ const fs = require("fs") const sharp = require('sharp') // github api url -const githubUrl = `https://api.github.com/repos/gogf/gf/contributors` +const githubUrl = [ + "https://api.github.com/repos/gogf/gf/contributors", + "https://api.github.com/repos/gogf/gf-site/contributors", +] // 生成 svg 的位置 const svgPath = "../../static/img/contributors.svg" @@ -28,28 +31,40 @@ getContributors().then(contributors => { // getContributors 获取所有的贡献者 async function getContributors() { - const contributors = [] - let page = 1 - let per_page = 100 - let hasMore = true + let contributors = [] - while (hasMore) { - const response = await fetch(`${githubUrl}?page=${page}&per_page=${per_page}`) - const data = await response.json() + let f = async function (url) { + let page = 1 + let per_page = 100 + let hasMore = true - if (response.status !== 200) { - throw new Error(`Failed to fetch contributors: ${response.statusText}`) - } + while (hasMore) { + const response = await fetch(`${url}?page=${page}&per_page=${per_page}`) + const data = await response.json() + + if (response.status !== 200) { + throw new Error(`Failed to fetch contributors: ${response.statusText}`) + } - contributors.push(...data) + contributors.push(...data) - if (data.length < per_page) { - hasMore = false - } else { - page++ + if (data.length < per_page) { + hasMore = false + } else { + page++ + } } } + for (const url of githubUrl) { + await f(url) + } + + // 根据id去重 + contributors = contributors.filter((value, index, self) => { + return self.findIndex(v => v.id === value.id) === index + }) + return contributors }