Changesets · Branches · Tags · Compare
| Changeset | fe16bbb4f71aed6f3832d1008c1f86334b5ea1dd50cbea5ef4ba1d0a19100b03 |
|---|---|
| Author | WaylandYang <145302500+WaylandYang@users.noreply.github.com> · 2026-09-02 19:38 +08:00 |
| Committer | GitHub <noreply@github.com> · 2026-09-02 19:38 +08:00 |
| Parents | 5458acc09ac1 |
1 file changed
modified scripts/star-history.mjs +24 −2
| @@ -29,9 +29,15 @@ | ||
| 29 | 29 | * GraphQL 的 `stargazers` 连接认这个 token——CI 上验过。 |
| 30 | 30 | * 改这里,好过为了一个接口去放宽凭据。 */ |
| 31 | 31 | async function stargazerDates() { |
| 32 | + /* `viewerPermission` 与 `totalCount` 不是装饰。**受限数据 GitHub 回的是 | |
| 33 | + 空集合,不是报错**——只看 `edges` 的话,「没权限」和「真的零颗星」 | |
| 34 | + 长得一模一样。把这两个一起取回来,失败时说得出是哪一种 */ | |
| 32 | 35 | const query = `query($owner:String!,$name:String!,$cursor:String){ |
| 33 | 36 | repository(owner:$owner,name:$name){ |
| 37 | + stargazerCount | |
| 38 | + viewerPermission | |
| 34 | 39 | stargazers(first:100,after:$cursor,orderBy:{field:STARRED_AT,direction:ASC}){ |
| 40 | + totalCount | |
| 35 | 41 | pageInfo{hasNextPage endCursor} |
| 36 | 42 | edges{starredAt} |
| 37 | 43 | } |
| @@ -58,8 +64,15 @@ | ||
| 58 | 64 | if (body.errors) { |
| 59 | 65 | throw new Error(`graphql page ${page}: ${JSON.stringify(body.errors)}`); |
| 60 | 66 | } |
| 61 | - const conn = body.data?.repository?.stargazers; | |
| 67 | + const node = body.data?.repository; | |
| 68 | + const conn = node?.stargazers; | |
| 62 | 69 | if (!conn) throw new Error(`graphql page ${page}: no stargazers in response`); |
| 70 | + if (page === 1) { | |
| 71 | + console.log( | |
| 72 | + `repo sees ${node.stargazerCount} stars; connection reports ` + | |
| 73 | + `${conn.totalCount}; token permission = ${node.viewerPermission}`, | |
| 74 | + ); | |
| 75 | + } | |
| 63 | 76 | for (const e of conn.edges) if (e.starredAt) dates.push(new Date(e.starredAt)); |
| 64 | 77 | if (!conn.pageInfo.hasNextPage) return dates; |
| 65 | 78 | cursor = conn.pageInfo.endCursor; |
| @@ -68,7 +81,16 @@ | ||
| 68 | 81 | } |
| 69 | 82 | |
| 70 | 83 | const dates = (await stargazerDates()).sort((a, b) => a - b); |
| 71 | -if (dates.length === 0) throw new Error("no stargazer timestamps came back"); | |
| 84 | +if (dates.length === 0) { | |
| 85 | + // 上面那行日志已经说了 repo 报多少颗星、连接报多少、token 是什么权限。 | |
| 86 | + // **不要在这里静默出一张空图**——一张画着零的曲线比没有图更糟 | |
| 87 | + throw new Error( | |
| 88 | + "no stargazer timestamps came back — see the line above for what the API " + | |
| 89 | + "reported. An empty connection with a non-zero star count means the token " + | |
| 90 | + "cannot read the stargazer timeline (restricted to admins and collaborators " + | |
| 91 | + "since 2026-06-30).", | |
| 92 | + ); | |
| 93 | +} | |
| 72 | 94 | |
| 73 | 95 | /* 按天聚合成累计值。**每一天都要有点**,哪怕当天没有新增—— |
| 74 | 96 | 缺口跳过去的话,横轴的间距就不再代表时间,曲线的斜率也就骗人了 */ |