Skip to content

Commit 38ab7bc

Browse files
vn7n24fzkqclaude
andauthored
fix: fetch star totals via stargazerCount, not the stargazers connection (#313)
Between July 22 and 23 GitHub's GraphQL API stopped serving the `stargazers` connection to integration tokens (the built-in Actions GITHUB_TOKEN), answering "Resource not accessible by integration" with the rest of the document intact. assertNoGraphQLErrors treats any errors array as fatal, so exactly the two cards whose queries touch that field — ProfileDetailsCard and StatsCard — failed outright for every Action user on the default token setup, while PAT-backed runs (and the hosted service) kept working. Nothing changed on our side: the same release build was clean on the 22nd and failing on the 23rd (#311). The queries only ever read `stargazers { totalCount }`. `stargazerCount` returns the same number, is cheaper, and is verified to work with integration tokens — swap it in across the profile-details documents (combined, split core, star pagination) and the organization query. This also unblocks the planned move of the hosted service onto a GitHub App installation token, which would have hit the same restriction. Fixes #311. Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
1 parent a9a21d5 commit 38ab7bc

4 files changed

Lines changed: 12 additions & 23 deletions

File tree

src/github-api/organization-details.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,7 @@ const fetcher = (token: string, variables: any) => {
6161
nodes {
6262
createdAt
6363
forkCount
64-
stargazers {
65-
totalCount
66-
}
64+
stargazerCount
6765
issues(states: OPEN) {
6866
totalCount
6967
}
@@ -144,7 +142,7 @@ export async function getOrganizationDetails(login: string, token: string): Prom
144142
organizationDetails.totalPublicRepos = org.totalPublicRepos;
145143

146144
for (const node of nodes) {
147-
organizationDetails.totalStars += node.stargazers.totalCount;
145+
organizationDetails.totalStars += node.stargazerCount;
148146
organizationDetails.totalForks += node.forkCount;
149147
organizationDetails.totalOpenIssues += node.issues.totalCount;
150148
organizationDetails.repoCreatedAt.push(new Date(node.createdAt));

src/github-api/profile-details.ts

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,7 @@ const fetcher = (token: string, variables: any) => {
5757
repositories(first: 100,privacy:PUBLIC, isFork: false, ownerAffiliations: OWNER) {
5858
totalCount
5959
nodes {
60-
stargazers {
61-
totalCount
62-
}
60+
stargazerCount
6361
}
6462
pageInfo {
6563
endCursor
@@ -122,9 +120,7 @@ const coreFetcher = (token: string, variables: any) => {
122120
repositories(first: 100,privacy:PUBLIC, isFork: false, ownerAffiliations: OWNER) {
123121
totalCount
124122
nodes {
125-
stargazers {
126-
totalCount
127-
}
123+
stargazerCount
128124
}
129125
pageInfo {
130126
endCursor
@@ -311,9 +307,7 @@ const starsFetcher = (token: string, variables: any) => {
311307
user(login: $login) {
312308
repositories(first: 100, after: $endCursor, privacy:PUBLIC, isFork: false, ownerAffiliations: OWNER) {
313309
nodes {
314-
stargazers {
315-
totalCount
316-
}
310+
stargazerCount
317311
}
318312
pageInfo {
319313
endCursor
@@ -423,7 +417,7 @@ function splitFlagKey(username: string): string {
423417
// the profile fetch's start, not the pagination's, so the phases can't stack.
424418
async function paginateStars(firstPage: any, username: string, token: string, startedAt: number): Promise<number> {
425419
let stars: number = firstPage.nodes.reduce(
426-
(acc: number, curr: {stargazers: {totalCount: number}}) => acc + curr.stargazers.totalCount,
420+
(acc: number, curr: {stargazerCount: number}) => acc + curr.stargazerCount,
427421
0
428422
);
429423
let starsCursor: string | null = firstPage.pageInfo?.endCursor ?? null;
@@ -439,10 +433,7 @@ async function paginateStars(firstPage: any, username: string, token: string, st
439433
const starsRes: any = await starsFetcher(token, {login: username, endCursor: starsCursor});
440434
assertNoGraphQLErrors(starsRes, 'GetProfileDetails failed');
441435
const repos = starsRes.data.data.user.repositories;
442-
stars += repos.nodes.reduce(
443-
(acc: number, curr: {stargazers: {totalCount: number}}) => acc + curr.stargazers.totalCount,
444-
0
445-
);
436+
stars += repos.nodes.reduce((acc: number, curr: {stargazerCount: number}) => acc + curr.stargazerCount, 0);
446437
starsCursor = repos.pageInfo?.endCursor ?? null;
447438
starsPages += 1;
448439
starsHasNextPage = shouldFetchNextPage(

tests/github-api/organization-details.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,19 @@ const firstPage = {
2323
{
2424
createdAt: '2020-01-01T00:00:00Z',
2525
forkCount: 5,
26-
stargazers: {totalCount: 100},
26+
stargazerCount: 100,
2727
issues: {totalCount: 3}
2828
},
2929
{
3030
createdAt: '2021-03-15T00:00:00Z',
3131
forkCount: 2,
32-
stargazers: {totalCount: 50},
32+
stargazerCount: 50,
3333
issues: {totalCount: 1}
3434
},
3535
{
3636
createdAt: '2022-06-30T00:00:00Z',
3737
forkCount: 1,
38-
stargazers: {totalCount: 25},
38+
stargazerCount: 25,
3939
issues: {totalCount: 0}
4040
}
4141
]

tests/github-api/profile-details.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const data = {
1616
websiteUrl: null,
1717
repositories: {
1818
totalCount: 30,
19-
nodes: [{stargazers: {totalCount: 110}}, {stargazers: {totalCount: 20}}]
19+
nodes: [{stargazerCount: 110}, {stargazerCount: 20}]
2020
},
2121
issues: {totalCount: 10},
2222
repositoriesContributedTo: {totalCount: 30},
@@ -342,7 +342,7 @@ describe('github api for profile details', () => {
342342
data: {
343343
user: {
344344
repositories: {
345-
nodes: [{stargazers: {totalCount: 7}}, {stargazers: {totalCount: 3}}],
345+
nodes: [{stargazerCount: 7}, {stargazerCount: 3}],
346346
pageInfo: {endCursor: null, hasNextPage: false}
347347
}
348348
}

0 commit comments

Comments
 (0)