fix(api): read a pull request when the GitHub App can't see its protection rules

Merged
HA
15d ago
+347-51

Fixes the mobile "You don't have access to this pull request on GitHub, or it no longer exists." error you get after connecting GitHub (SUPER-3438).

Root cause

integration.github.getPullRequestDetail reads a PR as the person's GitHub App user-to-server token (viewer-octokit.ts, since #8765 / #8799 / #8991). That token can only do what the App can do, and superset-app has actions, checks, contents, issues, members, metadata, pull_requests, workflows. It has no Administration, Merge queues or Commit statuses permission.

The detail query reads fields that need those permissions. GitHub refuses them with Resource not accessible by integration, @octokit/graphql throws on any GraphQL error, the API returns FORBIDDEN, and the app shows "no access".

This hits mobile, and also desktop users with no local GitHub login: the desktop falls back to the same API path (pullRequestClient.ts githubFor).

It isn't caused by the merge-queue PR (#9554). The first failures (Sazabi alert, #sazabi-alerts, Nov 10 00:57 UTC) came before #9554 merged on Nov 11 at 01:19 UTC.

Evidence from production api logs: all 392 getPullRequestDetail log lines in 23h are FORBIDDEN ← GraphqlResponseError with 3 × "Resource not accessible by integration", from the prod App's client id. An older failure in another org had 16 errors. A count that varies by PR points to per-check refusals (commit statuses).

Change

All in readPullRequestDetail (packages/shared):

  1. App-gated fields read separately. viewerCanMergeAsAdmin, mergeQueueEntry, isMergeQueueEnabled and branchProtectionRule move into a second query, sent in parallel, with one alias per field. Two of them are non-null, so a refusal on one blanks only its own alias. Refused fields fall back to none, false or 0.
  2. Refused status checks are dropped. In the main query and the check-pages query, if every error is a FORBIDDEN under statusCheckRollup, the read uses GitHub's partial data. Refused check entries come back null and are skipped.
  3. Anything else still fails the read: a refusal elsewhere, or a FORBIDDEN mixed with another error such as RATE_LIMITED.
  4. Refusals are logged. The API logs them once per path shape, with the repo: [github.getPullRequestDetail] GitHub refused … on owner/repo. Production will then show exactly what GitHub refuses.

The desktop with its local gh login still gets every field and every check.

Known limits

  • Under the fallback, a refused value looks real rather than "unknown". A queued PR reads as not queued, so the UI offers Merge instead of Dequeue. Branch-rule counts read 0, and refused status checks are absent from the list. GitHub still enforces all of these at merge time, so nothing unsafe can merge.
  • The real fix for that data is the App permissions: Commit statuses: read and Merge queues: read are low-risk. Administration is too broad for what it gets us.

Caveat

The logs hide the GraphQL error paths, and I couldn't mint a superset-app user token, so which fields GitHub refuses is inferred from the App's permissions and the error counts. The new log line confirms it after deploy.

Validation

  • bun test: packages/shared pull-request-detail (8 tests) and pull-request-github, desktop pull-request and viewer-github (109), trpc integration/github, host-service github. All pass.
  • New tests cover: one refused gated field keeps the others; refused status checks are dropped and the PR still loads; a refusal outside the checks, or next to another error, still fails.
  • tsc --noEmit passes for shared, trpc and host-service.
  • Independent review (two separate agents plus superset-home): no serious findings.
  • Not verified with a real App token or on device.

Summary by CodeRabbit

  • Bug Fixes
    • Pull-request details remain available when access to administrative, merge-queue, or branch-protection information is restricted. Unavailable information uses safe defaults, while other pull-request details, including mergeability, remain accessible.
    • Restricted status-check information no longer prevents details from loading when the response contains only access-denied errors for checks. Other errors continue to be reported, and missing pull requests are still identified as not found.