Skip to content

Commit

Permalink
chore: add gf-site contributor into contributors (#128)
Browse files Browse the repository at this point in the history
  • Loading branch information
oldme-git authored Dec 18, 2024
1 parent 28ea5b0 commit 2c4f9b3
Showing 1 changed file with 31 additions and 16 deletions.
47 changes: 31 additions & 16 deletions .github/workflows/generate-contributors.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
}

Expand Down

0 comments on commit 2c4f9b3

Please sign in to comment.