Skip to content

Talk to GitHub through its API instead of the gh CLI (account per host, saved token, GHE) #1528

Closed

Description

@currentbits

Every PR operation shells out to gh (electron/worktrees-pr.js:36, prWorkspace.js gh pr view, the refresher). The costs: one process per poll per thread, gh must be installed and logged in, the wrong account gets picked on multi-account machines, and GHE is unsupported (see the polling-hygiene issue).

Proposal (M):

  1. A small GitHub REST/GraphQL transport. It gets its token from gh auth token --hostname <host> when available (so nothing changes for existing users), or from a token saved in the OS keychain via Settings.
  2. Choose the account per host in Settings › Source control.
  3. Batch the refresher: one GraphQL query for all open PRs in a repo instead of gh pr view per thread.
  4. Keep gh as the fallback during migration. Route the outbound secret scan over the new path too.

This is also the abstraction GitLab (#193) should plug into later.

Activity

  1. added and removed on Oct 9, 2026
  2. currentbits commented on Oct 9, 2026

    @currentbits
    OwnerAuthor

    Part 1 is on branch coder/talk-to-github-through-its-api-instead-o-04dd2a (d1ecfc69).

    • New electron/github.js. It gets a token from gh auth token --hostname <host> (cached per host, cleared on a 401 and on Settings › Rescan), sends GraphQL over fetch, and supports GHE via https://<host>/api/graphql.
    • The refresher now sends one GraphQL query per repo, up to 50 PRs per request, instead of one gh pr view per thread. If there's no token or the API fails, it falls back to the old per-thread gh call. CODER_GITHUB_API=0 forces gh.
    • Live check against this repo: 3 PRs in one request, 508 ms. A nonexistent PR number is skipped and doesn't fail the batch.

    Split out: #1533 (account per host and a saved token; the keychain is blocked by the safeStorage ACL problem described in secrets.js) and #1534 (moving the interactive PR and issue operations onto the transport, with the outbound secret scan on that path).

  3. currentbits commented on Oct 9, 2026

    @currentbits
    OwnerAuthor

    All four parts are on branch coder/talk-to-github-through-its-api-instead-o-04dd2a, which isn't pushed or open as a PR yet:

    1. Transport (electron/github.js), with tokens from gh, the chosen account, or a saved token — d1ecfc69 / bcab6b1c
    2. Account per host and a saved token in Settings › Source control (GitHub account per host + saved token in Settings › Source control (#1528 follow-up) #1533) — bcab6b1c
    3. Batched refresher: one GraphQL query per repo instead of one gh pr view per thread — d1ecfc69
    4. Interactive PR and issue actions over the API, with gh as the fallback (Move interactive PR/issue ops from gh CLI onto electron/github.js (#1528 follow-up) #1534) — merged in 253964ff. The PR create/edit/comment secret scan still runs before the request. gh pr checkout deliberately stays on gh.

    A join test (26eac0bc) confirms that a token saved in Settings authenticates interactive PR actions.

    Merged tree: typecheck clean; renderer tests 2693/0; electron tests 4136/0 with a CI-style env.

    Separate pre-existing gap, not part of this work: issue comments and creates have never been secret-scanned. Filed as a suggested follow-up.

  4. currentbits commented on Oct 9, 2026

    @currentbits
    OwnerAuthor

    PR #1550 is open. It's rebased onto current main as one commit (87b4f31) and closes #1528, #1533 and #1534 when merged. Ported onto main's split modules: worktrees-pr.js, ipc-app.js, the store-* modules and settings/GitPane.tsx. The batched refresher now sits alongside PR watch-and-wake (#1493). Tests: renderer 2916/0, electron 4407/0, vite build succeeds.

  5. currentbits commented on Oct 9, 2026

    @currentbits
    OwnerAuthor

    PR #1550 is open. It's rebased onto current main as one commit (87b4f31) and closes #1528, #1533 and #1534 when merged. Ported onto main's split modules: worktrees-pr.js, ipc-app.js, the store-* modules and settings/GitPane.tsx. The batched refresher now sits alongside PR watch-and-wake (#1493). Tests: renderer 2916/0, electron 4407/0, vite build succeeds.

  6. added and removed on Oct 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions