PR #9656 review: PR detail without protection-rule access
Summary
Mobile reads a PR with the person's GitHub App user token. That token cannot read branchProtectionRule, mergeQueueEntry or isMergeQueueEnabled, and GitHub refuses the whole detail query, so mobile shows "You don't have access to this pull request" (SUPER-3438). The PR moves the four permission-sensitive fields into a second query that runs in parallel. When GitHub refuses only that query with FORBIDDEN errors, the read keeps the core data and uses "none" defaults for the gated fields.
Verdict
looks good The split is the correct fix for a non-null field that GitHub nulls up to pullRequest. I reproduced the failure on base and saw it fixed at head through the real Octokit error path. The findings below are small, non-blocking improvements.
Findings
packages/shared/src/pull-request-detail/pull-request-detail.ts:189The gated query is all-or-nothing.
isMergeQueueEnabled is non-null, so a refusal on that one field nulls the whole pullRequest. Then viewerCanMergeAsAdmin and branchProtectionRule also fall back, even if the token can read them. The author's caveat says the refused fields are inferred, which makes this more likely.Fix: in the same single request, alias
pullRequest once per group, for example queue: pullRequest(number:$number){ isMergeQueueEnabled mergeQueueEntry{…} }, protection: pullRequest(…){ baseRef{ branchProtectionRule{…} } }, admin: pullRequest(…){ viewerCanMergeAsAdmin }. Each refusal then nulls only its own alias. It is still one round trip.packages/shared/src/pull-request-detail/pull-request-detail.ts:356The FORBIDDEN fallback is silent. The PR says the logs hide the error paths, and after this change a refusal is not logged at all, so the inference cannot be confirmed from production.
Fix: take an
onRefused callback, like threads(onError) at packages/shared/src/pull-request-github/pull-request-github.ts:95. Log error.errors.map(e => e.path) from the API procedure once.packages/shared/src/pull-request-detail/pull-request-detail.ts:729When the read is refused,
queue is always null. On mobile a queued PR then is not "queued" (apps/mobile/…/pullRequestState/pullRequestState.ts:37). The PR shows Merge where Dequeue belongs, and capabilities.dequeue is false. This is better than the current error screen, but it stays wrong until the App gets Merge queues: read.Fix: none needed in this PR. Track granting the permission as a follow-up, or add a "queue unknown" state later in a compatible way.
Evidence
Surface: API / shared read (readPullRequestDetail), CLI-style run. No UI changes in this PR. I ran the shared code through @octokit/core, the same client the API's asViewer builds, against this PR on github.com.
- Real token (gh OAuth), head
c7500c60: both queries succeed, the output shape is unchanged. probe-output.txt, first block. - Simulated App user token, head: a fetch shim answers the gated query with HTTP 200 plus 3
FORBIDDEN"Resource not accessible by integration" errors andpullRequest: null, the shape the PR describes from prod logs. The read succeeds withrequiredApprovals: 0,queue: null,queueEnabled: false,merge: true. The same file, second block. - Same refusal on base
9b7f8b9: the read throwsGraphqlResponseError, andgithubErrorCodemaps it toFORBIDDEN. That is the bug. base-output.txt.
BASE (main@9b7f8b9) with refused gated fields: GraphqlResponseError -> FORBIDDEN
SIMULATED APP TOKEN: {
"title": "fix(api): read a pull request when the GitHub App can't see its protection rules",
"mergeability": {
"mergeable": "MERGEABLE",
"mergeStateStatus": "BLOCKED",
"approvals": 0,
"requiredApprovals": 0,
"reviewDecision": "REVIEW_REQUIRED",
"unresolvedThreads": 0,
"requiresThreadResolution": false,
"queue": null,
"queueEnabled": false,
"allowedMergeMethods": [
"squash",
"merge",
"rebase"
],
"defaultMergeMethod": "squash"
},
"capabilities": {
"update": true,
"merge": true,
"markReady": false,
"updateBranch": false,
"reopen": false,
"dequeue": false
}
}
Not run: a real superset-app user-to-server token (I could not mint one here, the same limit the author had). Also not run: the mobile app on device or simulator. The PR changes no mobile code; the refused-token path is shown only by the simulation above.
Questions for the author
- Is it acceptable that every detail read, including desktop
ghreads that are never refused, now makes two GraphQL requests? The aliased single query in finding 1 keeps this at one. - Is there a ticket to grant Administration: read and Merge queues: read on the App, so mobile gets accurate queue and protection data?
- Does an older GHES schema without
isMergeQueueEnabledmatter? Its schema error is not FORBIDDEN, so it still fails the read, as on base.
Test / CI notes
- All at
c7500c60:bun test src/pull-request-detail src/pull-request-githubin packages/shared: 10 pass, 0 fail.bun test src/router/integration/githubin packages/trpc: 6 pass.tsc --noEmitin packages/shared: clean. - CI: Lint, Typecheck, Test, Sherif, Version Sync, Build CLI and all deploys pass. The Mobile build/preview (EAS) and CodeRabbit checks were still pending when I wrote this. E2E Mobile was skipped.