Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add gf-site contributor into contributors #128

Merged
merged 1 commit into from
Dec 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading