fix(leaderboard): 脚本调 GitHub API 带 Authorization(修 name 全是占位符)#280
fix(leaderboard): 脚本调 GitHub API 带 Authorization(修 name 全是占位符)#280longsizhuo merged 2 commits intomainfrom
Conversation
现象:排行榜上所有用户 name 字段都是 "GitHub User <id>" 占位符。 根因:脚本匿名调用 GitHub /user/:id API,限流 60/hour,前排 21 人基本全部 403, 静默 fallback 到占位符;catch 块之前把所有错误吞掉,看不到问题。 修复: - 读取 GITHUB_TOKEN / GH_PAT(workflow 已在 env 注入),带 Bearer 头走认证 - 失败时打印首个响应片段,累计 success / failure 计数便于排查 - 本地用 21 位贡献者验证:21/0 通过,name 字段回到真实 login (longsizhuo / Mira190 / ...) - 顺手重新生成 generated/site-leaderboard.json
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
Pull request overview
This PR fixes the /rank Contributors tab showing placeholder names by authenticating the leaderboard generation script’s GitHub API calls, and refreshes the generated leaderboard snapshot accordingly.
Changes:
- Read
process.env.GITHUB_TOKEN/process.env.GH_PATand sendAuthorization: Bearer ...when callinghttps://api.github.com/user/:id. - Add basic success/failure counters and print a sample failure response once for easier debugging.
- Regenerate
generated/site-leaderboard.jsonso names/URLs reflect the latest successful enrichment output.
Reviewed changes
Copilot reviewed 1 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| scripts/generate-leaderboard.mjs | Adds token-based GitHub API auth plus minimal logging/metrics for enrichment. |
| generated/site-leaderboard.json | Updates snapshot data (real logins instead of placeholders; refreshed URLs/ordering/data). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
scripts/generate-leaderboard.mjs
Outdated
| const ghToken = process.env.GITHUB_TOKEN || process.env.GH_PAT || ""; | ||
| if (!ghToken) { | ||
| console.warn( | ||
| "[generate-leaderboard] 未检测到 GITHUB_TOKEN,名字获取会因限流失败,榜单只会展示 id 占位符", |
There was a problem hiding this comment.
ghToken 同时支持从 GITHUB_TOKEN 和 GH_PAT 读取,但这里的告警文案只提到了 GITHUB_TOKEN,可能会误导排查(例如本地只设置了 GH_PAT 时)。建议把提示改成“未检测到 GITHUB_TOKEN/GH_PAT(或 GitHub token)…”。
| "[generate-leaderboard] 未检测到 GITHUB_TOKEN,名字获取会因限流失败,榜单只会展示 id 占位符", | |
| "[generate-leaderboard] 未检测到 GITHUB_TOKEN/GH_PAT(GitHub token),名字获取会因限流失败,榜单只会展示 id 占位符", |
| } | ||
| } catch (err) { | ||
| // Ignore fetch errors | ||
| failureCount++; |
There was a problem hiding this comment.
catch (err) 分支现在只累计失败次数但不输出任何信息;如果首次失败来自网络/DNS/SSL 等异常(而非非 2xx 响应),日志里会缺少可定位线索。建议至少在首次捕获异常时输出 err.message(或 err)并说明后续将静默计数,保持和非 2xx 分支一致的可追溯性。
| failureCount++; | |
| failureCount++; | |
| if (failureCount === 1) { | |
| console.warn( | |
| "[generate-leaderboard] GitHub API 请求异常,后续失败将静默计数。示例错误:", | |
| err instanceof Error ? err.message : err, | |
| ); | |
| } |
Copilot CR #280: - 告警文案原来只提 GITHUB_TOKEN,可能误导本地只设 GH_PAT 的排查 - catch 分支之前只累加 failureCount,网络/DNS/SSL 异常无任何日志线索;补一次首次异常输出,与非 2xx 分支保持一致
现象
`/rank` 页 Contributors tab 所有用户都显示 "GitHub User ",而不是真实的 GitHub login。
根因
`scripts/generate-leaderboard.mjs` 调 `https://api.github.com/user/:id\` 时没带 Authorization header:
workflow 已经在 env 里注入了 `GITHUB_TOKEN: ${{ secrets.GH_PAT }}`,脚本没读用。
修复
后续
如果线上运行时 `secrets.GH_PAT` 过期/撤销了,这次失败日志会直接显示 401 响应,不再静默。
Test plan