Skip to content

ref(github): Share one GitHub API helper across tools - #2692

Merged
BYK merged 2 commits into
mainfrom
ref/github-api-helper
Nov 5, 2026
Merged

BYK merged 2 commits into
mainfrom
ref/github-api-helper

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Every GitHub tool built its own Request with the same headers. Each one also had its own copy of readJson, githubError/githubApiErrorMessage, and parseRepo. This PR moves that code into src/tool-support/github-api.ts:

  • githubApi(egress, { operation, path, method?, body?, apiVersion?, signal? }) sends the request through host egress and returns { ok, status, body }. The body is parsed as JSON, or kept as text when it is not JSON.
  • githubErrorMessage(body) reads REST errors as message: resource=… field=… code=… and GraphQL errors as the joined errors[].message.
  • parseRepo and repoPath replace the per-file copies.

All tools, the conversation-title lookup in plugin.ts, and the Stacks client now use it.

Lint rule: the new oxlint rule junior/use-github-api (in tools/oxlint/junior) flags egress.fetch calls in junior-github/src. It is off only in tool-support/github-api.ts. The existing githubRequest and fetch restriction messages now name githubApi.

What stays the same

  • Egress is still the only way out, and the operation names are unchanged.
  • Each tool still maps statuses to errors itself (PluginToolInputError vs. Error), because the status that means bad input differs per route.
  • The tool-error baseline entries are renamed only. No new plain Error throws.

What changes

  • Every tool now includes REST validation details and GraphQL messages in its error text. Before, only create-PR and the draft update did. This gives the model more to work with when it fixes bad input.
  • GraphQL and reaction requests now also send Accept and X-GitHub-Api-Version.

Not in scope: the webhook paths in webhooks/check-suite.ts and webhooks/installation-requests.ts call githubRequest in credential-support.ts with an App installation token, not egress. That is a different auth path, so it stays as it is.

Follow-up to the Octokit discussion: we did not add octokit, because egress owns credentials and operation selects the grant.

--

View Session in Sentry

Every GitHub tool built its own Request with the same headers, then
parsed the body and formatted errors with its own copy of readJson,
githubError, and parseRepo. Move that into githubApi, githubErrorMessage,
parseRepo, and repoPath in tool-support/github-api.ts.

Requests still go only through host egress with the same operation
names, and each tool keeps its own status-to-error mapping. Error text
now includes REST validation details and GraphQL messages for every
tool, not only the ones that had that parsing.

Co-Authored-By: BYK <[email protected]>
@vercel

vercel Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
junior-docs Ready Ready Preview Nov 4, 2026 10:23pm UTC

Request Review

@github-actions github-actions Bot added the risk: high PR risk score: high label Nov 4, 2026

@BYK BYK left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also enforce using this through a lint rule (prefer oxlint over ast-grep)

Add the junior/use-github-api oxlint rule. It flags egress.fetch calls in
junior-github src, except in tool-support/github-api.ts, so new tools use
the shared helper.
@github-actions

github-actions Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

1 screenshot change — 1 changed · 0 added · 0 removed

Review screenshots in Frameshift

Settings Mcp · Desktop
Settings Mcp · Desktop
Changed

@BYK
BYK merged commit a8f2a42 into main Nov 5, 2026
45 checks passed
@BYK
BYK deleted the ref/github-api-helper branch November 5, 2026 10:01
BYK pushed a commit that referenced this pull request Nov 5, 2026
…2693)

Follow-up to #2690, from [Bugbot's review
comment](#2690 (comment)).

`POST /pulls/{n}/comments/{id}/replies` accepts only the first comment
of a thread. GitHub's docs say: "Replies to replies are not supported."
Events often name a later reply, so `github_commentOnPullRequest` failed
with 404 or 422 in the usual case.

Now, when `in_reply_to` is set, the tool reads the comment
(`github.pull.comment.get`) and replies to its `in_reply_to_id` when it
has one. A missing comment returns a `PluginToolInputError`.

This PR is stacked on #2692, which changes the same file.

<!-- junior-session-footer:start -->
<!-- junior-conversation-id:local%3Aweb%3A3ee1f99a8027cbdb43eb2584 -->

--

[View Session in
Sentry](https://sentry.sentry.io/explore/conversations/local%3Aweb%3A3ee1f99a8027cbdb43eb2584/?project=4510944073809921)

<!-- junior-session-footer:end -->

---------

Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com>

This branch was successfully deployed

1 active deployment
Preview – junior-docs — ac1896df Deployed Nov 4, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk: high PR risk score: high

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant