refactor(server): GitHub GraphQL batches use variables and share one pager #16960
Mergedjuliusmarmingemerged 3 commits into
t3code/github-api-naming fromrefs/pull/16960/headmerged by juliusmarminge View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
juliusmarminge added labelsmacroscope-review
- apps/server/src/pullRequest/GitHubPullRequestApi.ts lines 1595 to 1616OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -1612,2 +1598,19 @@1612- } while (after !== null && heads.length <= workflowApprovalLimit);1613- return heads;1598+ const countHeads = (pages: ReadonlyArray<{ readonly heads: ReadonlyArray<unknown> }>) =>1599+ pages.reduce((total, page) => total + page.heads.length, 0);1600+ const { pages } = yield* readGraphQlPages(1601+ (after) =>1602+ graphqlRead({1603+ cwd: input.cwd,1604+ host: input.host,1605+ operation: "listWorkflowRunsRequiringApproval",1606+ allowReserve: true,1607+ variables: { owner, name, head: input.headBranch, after },1608+ query: PULL_REQUEST_HEADS_GRAPHQL_QUERY,1609+ decode: decodePullRequestHeadsJson,1610+ }),1611+ {1612+ nextCursor: (page) => page.nextCursor,1613+ until: (pages) => countHeads(pages) > workflowApprovalLimit,1614+ },1615+ );1616+ return pages.flatMap((page) => page.heads);apps/server/src/pullRequest/GitHubPullRequestCli.ts lines 1919 to 1932OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -1919,10 +1922,11 @@1919- const items: GitHubPullRequestListItem[] = [];1920- let rawCount = 0;1921- let after: string | null = null;1922- do {1923- const read: GitHubPullRequestListPage = yield* page(after, rows - rawCount);1924- items.push(...read.items);1925- rawCount += read.rawCount;1926- after = read.endCursor;1927- } while (after !== null && rawCount < rows);1928- return { items, rawCount };1922+ const countRows = (pages: ReadonlyArray<GitHubPullRequestListPage>) =>1923+ pages.reduce((total, read) => total + read.rawCount, 0);1924+ const { pages } = yield* readGraphQlPages(1925+ (after, pages: ReadonlyArray<GitHubPullRequestListPage>) =>1926+ page(after, rows - countRows(pages)),1927+ {1928+ nextCursor: (read) => read.endCursor,1929+ until: (pages) => countRows(pages) >= rows,1930+ },1931+ );1932+ return { items: pages.flatMap((read) => read.items), rawCount: countRows(pages) };
github-actions[bot](GitHub profile, opens in a new tab) removed labelssize:L
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XL
- apps/server/src/pullRequest/GitHubPullRequestApi.ts line 1585OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -1581,18 +1583,3 @@1581- let after: string | null = null;1582- do {1583- const page: {1584- readonly heads: ReadonlyArray<GitHubPullRequestHead>;1585- readonly nextCursor: string | null;1586- } = yield* graphqlRead({1587- cwd: input.cwd,1588- host: input.host,1589- operation: "listWorkflowRunsRequiringApproval",1590- allowReserve: true,1591- variables: { owner, name, head: input.headBranch, after },1592- query: PULL_REQUEST_HEADS_GRAPHQL_QUERY,1593- decode: decodePullRequestHeadsJson,1594- });1595- heads.push(...page.heads);1596- after = page.nextCursor;1597- } while (after !== null && heads.length <= workflowApprovalLimit);1598- return heads;1583+ const countHeads = (pages: ReadonlyArray<{ readonly heads: ReadonlyArray<unknown> }>) =>1584+ pages.reduce((total, page) => total + page.heads.length, 0);1585+ const { pages } = yield* readGraphQlPages(apps/server/src/pullRequest/GitHubPullRequestApi.ts line 1905OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -1897,13 +1900,6 @@18971900 ) => Effect.Effect<GitHubPullRequestListPage, GitHubPullRequestApiError>,18981901 ) =>18991902 Effect.gen(function* () {1900- const items: GitHubPullRequestListItem[] = [];1901- let rawCount = 0;1902- let after: string | null = null;1903- do {1904- const read: GitHubPullRequestListPage = yield* page(after, rows - rawCount);1905- items.push(...read.items);1906- rawCount += read.rawCount;1907- after = read.endCursor;1908- } while (after !== null && rawCount < rows);1909- return { items, rawCount };1903+ const countRows = (pages: ReadonlyArray<GitHubPullRequestListPage>) =>1904+ pages.reduce((total, read) => total + read.rawCount, 0);1905+ const { pages } = yield* readGraphQlPages(
- apps/server/src/pullRequest/GitHubPullRequestApi.ts line 1905OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -1897,13 +1900,6 @@18971900 ) => Effect.Effect<GitHubPullRequestListPage, GitHubPullRequestApiError>,18981901 ) =>18991902 Effect.gen(function* () {1900- const items: GitHubPullRequestListItem[] = [];1901- let rawCount = 0;1902- let after: string | null = null;1903- do {1904- const read: GitHubPullRequestListPage = yield* page(after, rows - rawCount);1905- items.push(...read.items);1906- rawCount += read.rawCount;1907- after = read.endCursor;1908- } while (after !== null && rawCount < rows);1909- return { items, rawCount };1903+ const countRows = (pages: ReadonlyArray<GitHubPullRequestListPage>) =>1904+ pages.reduce((total, read) => total + read.rawCount, 0);1905+ const { pages } = yield* readGraphQlPages(
github-actions[bot](GitHub profile, opens in a new tab) removed labelssize:XL
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
juliusmarminge merged thisa21ac5f
juliusmarminge closed this
Sign in to join this conversation.
Approvability#
Verdict: Not approved
Macroscope's review found this PR not approvable — This refactor replaces several production GitHub GraphQL and pagination implementations with shared infrastructure while changing listing completeness and workflow-approval behavior. The cross-cutting runtime impact warrants human review.
You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).