fix(github): API requests use the proxy git has for the host #48252
Openrtio(GitHub profile, opens in a new tab)wants to merge 2 commits into
main fromrefs/pull/48252/headopened View on GitHubtanstack-source added labelsbug
rtio(GitHub profile, opens in a new tab) linked this to fix #48251
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
- @@ -4,7 +7,20 @@7+import * as Cache from "effect/Cache";8+import * as Duration from "effect/Duration";49 import * as Effect from "effect/Effect";510 import * as Layer from "effect/Layer";611 import * as Stream from "effect/Stream";7-import { HttpBody, HttpClient, HttpClientRequest } from "effect/http";12+import { FetchHttpClient, HttpBody, HttpClient, HttpClientRequest } from "effect/http";13+import type * as Undici from "undici";814915 import { GH_PROCESS_CONCURRENCY } from "./GitHubCredentials.ts";101617+// undici is external to the CLI bundle; Node single-executables can load it from disk only with require.18+const requireUndici = NodeModule.createRequire(import.meta.url);19+20+/**21+ * git's `http.<url>.proxy` value as the URL undici dials, or null when undici cannot. git reads a22+ * bare `host:port` as HTTP; `socks5h` (DNS at the proxy) is what undici's SOCKS5 agent always does.23+ */24+export function proxyUrl(configured: string): URL | null {25+ try {26+ const url = new URL(configured.includes("://") ? configured : `http://${configured}`);@@ -5,6 +10,20 @@510 import * as Layer from "effect/Layer";611 import * as Stream from "effect/Stream";7-import { HttpBody, HttpClient, HttpClientRequest } from "effect/http";12+import { FetchHttpClient, HttpBody, HttpClient, HttpClientRequest } from "effect/http";13+import type * as Undici from "undici";814915 import { GH_PROCESS_CONCURRENCY } from "./GitHubCredentials.ts";101617+// undici is external to the CLI bundle; Node single-executables can load it from disk only with require.18+const requireUndici = NodeModule.createRequire(import.meta.url);19+20+/**21+ * git's `http.<url>.proxy` value as the URL undici dials, or null when undici cannot. git reads a22+ * bare `host:port` as HTTP; `socks5h` (DNS at the proxy) is what undici's SOCKS5 agent always does.23+ */24+export function proxyUrl(configured: string): URL | null {25+ try {26+ const url = new URL(configured.includes("://") ? configured : `http://${configured}`);27+ if (url.protocol === "socks5h:")28+ return new URL(`socks5:${configured.slice("socks5h:".length)}`);29+ return ["http:", "https:", "socks5:", "socks:"].includes(url.protocol) ? url : null;
Pushed140cb07
Sign in to join this conversation.
No actionable comments were generated in the recent review.
Walkthrough
The GitHub HTTP client now reads Git’s per-origin proxy setting for fallback HTTP requests. It supports HTTP, HTTPS, and SOCKS proxy URLs, and caches lookup results for five minutes. The Unix-socket path remains unchanged.
Changes: GitHub proxy routing
packages/source-control-github/src/server/GitHubHttpClient.ts,packages/source-control-github/package.json,packages/source-control-github/src/server/GitHubHttpClient.test.tspackages/source-control-github/src/server/GitHubHttpClient.ts,packages/source-control-github/src/server/GitHubHttpClient.test.ts,docs/user/source-control.mdEstimated code review effort: 3 (Moderate) | ~20 minutes
Change: Bug fix · Severity of issue fixed: Medium
Sequence Diagram(s)#
Merge Risk:
Low · up to
140cb· assessed changes onlyPath filters excluded changed files. This rating applies only to the assessed changes.
Pre-merge checks:
4
#48251, explains the per-origin git proxy behavior, lists what is o…#48251] Requirement: T3 Code must reach a GitHub Enterprise host through the proxy that git uses for that host, so PR, check, and issue loading works. Evidence: GitHubHttpClient.ts runs `git config -…Full details: Title check
Explanation
The title names the main change: GitHub API requests now use the proxy that git configures for the host. It follows the conventional commit format and matches the changeset, which adds git-config-driven proxy routing to GitHubHttpClient.
Full details: Description check
Explanation
The description follows the template. It has Problem, Change, Scope, and Verification sections with specific content. It cites issue
#48251, explains the per-origin git proxy behavior, lists what is out of scope, and reports concrete test results. It also states that the live run against the company Enterprise Server is not yet verified. The template's HTML comment guidance is not repeated, which is acceptable. The model and harness line is present.Full details: Linked Issues check
Explanation
[
#48251] Requirement: T3 Code must reach a GitHub Enterprise host through the proxy that git uses for that host, so PR, check, and issue loading works. Evidence: GitHubHttpClient.ts runsgit config --get-urlmatch http.proxy <origin>for each request origin. The lookup falls back to plain http.proxy. Valid values route through undici ProxyAgent (http/https) or Socks5ProxyAgent (socks5, with socks5h handled through proxy-side DNS). Origins without a configured proxy stay direct. The lookup result is cached for 5 minutes. The follow-up change since the previous review adjusts parsing only: a portless non-HTTPS proxy value uses port 1080, HTTPS proxies default to 443, explicit :80 is kept, and socks:// is rejected. These adjustments do not remove the proxy routing that the issue requires. The issue's example value (socks5h://localhost:8080) has an explicit port and is unaffected. Tests: GitHubHttpClient.test.ts covers proxy value parsing, a live SOCKS5 tunnel test, and a direct request to an unproxied origin. The tests for the new parser defaults were not read in full. Limits: this assessment relies on the change summary, the PR description, and the test descriptions. The full diff was not read. The live Enterprise Server run is not a coding requirement of the issue.Full details: Out of Scope Changes check
Explanation
All changed files connect to the objective of routing GitHub API requests through the git-configured per-origin proxy. GitHubHttpClient.ts holds the proxy lookup, value parsing (including the new port defaults and socks:// rejection), agent creation, and caching. GitHubHttpClient.test.ts holds tests for that behavior. packages/source-control-github/package.json adds undici, which the proxy agents require. docs/user/source-control.md documents the git proxy setting that users configure. The Unix-socket path is unchanged, and http_unix_socket keeps precedence. The PR excludes media fetches, process-wide HTTPS_PROXY/NO_PROXY handling, and a UI proxy setting, and the change summaries list no changes in those areas. pnpm-lock.yaml is excluded from review, so its content is not assessed. Limits: this assessment relies on the change summaries and did not read the full incremental diff.
Finishing Touches
Generate unit tests (beta)
17839ce2-9ba3-4187-aeeb-e910744272ffReviewing files that changed from the base of the PR and between b8add94e9f38695c6194f5fbdb7eb1bb2b14bbb1 and 140cb076214020b4246f29dfc3d7c49336ee0ab6.
packages/source-control-github/src/server/GitHubHttpClient.test.tspackages/source-control-github/src/server/GitHubHttpClient.tsIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.