feat(github): support GitHub Enterprise Server hosts in pull requests (#6729)

gh api does not take the host from the remote as gh pr does, so requests for an Enterprise repository went to github.com. GhApiRequest now carries an optional host passed as gh api --hostname (validated as host[:port]); the GitHub tool window sends the connected repository's host, availability reads the login on that host, and remotes on the host gh resolved count as GitHub remotes. Commit checks in the Git log keep github.com.

Fixes #6717

Co-authored-by: wildcatDownstairs <[email protected]>
Цей коміт міститься в:
LU XIANGRUIтаwildcatDownstairs authored and GitHub committed 2026-11-28 21:00:14 +08:00
1 джерело 16e5cb5763
коміт 2ea7d6c41b
13 files changed
+223 -40

No files matched your search

+45 -10
Переглянути файл
@@ -3,6 +3,12 @@ import { afterEach, describe, expect, it, vi } from "vitest";
const ghApi = vi.fn();
const ghAvailability = vi.fn();
const ok = (data: unknown) => Promise.resolve({ status: "ok", data });
const FOLDER: Record<string, Array<{ name: string; url: string }>> = {
"/w/android": [{ name: "origin", url: "[email protected]:org/android.git" }],
"/w/ios": [{ name: "origin", url: "https://github.com/org/ios.git" }],
"/w/tools": [{ name: "origin", url: "https://gitlab.com/org/tools.git" }],
};
let layout = FOLDER;
vi.mock("@/platform/ipc", () => ({
isTauri: () => true,
@@ -12,17 +18,10 @@ vi.mock("@/platform/ipc", () => ({
return r.data;
},
commands: {
vcsRoots: () => ok([{ root: "/w/android" }, { root: "/w/ios" }, { root: "/w/tools" }]),
vcsRemotes: (root: string | null) =>
ok(
root === "/w/android"
? [{ name: "origin", url: "[email protected]:org/android.git" }]
: root === "/w/ios"
? [{ name: "origin", url: "https://github.com/org/ios.git" }]
: [{ name: "origin", url: "https://gitlab.com/org/tools.git" }],
),
vcsRoots: () => ok(Object.keys(layout).map((root) => ({ root }))),
vcsRemotes: (root: string | null) => ok(layout[root ?? ""] ?? []),
ghAvailability: (repo: string | null) => ghAvailability(repo),
ghApi: (repo: string | null, req: { endpoint: string }) => ghApi(repo, req),
ghApi: (repo: string | null, req: { endpoint: string; host: string | null }) => ghApi(repo, req),
},
}));
@@ -33,6 +32,7 @@ afterEach(() => {
ghApi.mockReset();
ghAvailability.mockReset();
localStorage.clear();
layout = FOLDER;
});
describe("a folder holding several git repositories", () => {
@@ -65,3 +65,38 @@ describe("a folder holding several git repositories", () => {
expect(ghApi).toHaveBeenLastCalledWith("/w/ios", expect.objectContaining({ endpoint: "user" }));
});
});
describe("a GitHub Enterprise Server repository", () => {
it("recognises the host gh resolved and sends every API call there", async () => {
layout = {
"/w/app": [
{ name: "origin", url: "[email protected]:acme/app.git" },
{ name: "mirror", url: "https://github.com/acme/app-mirror.git" },
],
};
ghAvailability.mockReturnValue(
ok({ kind: "ready", repo: { nameWithOwner: "acme/app", url: "https://ghe.example.com/acme/app" }, login: "al" }),
);
ghApi.mockImplementation((_repo: string | null, req: { endpoint: string }) =>
ok(
req.endpoint === "user"
? JSON.stringify({ id: 1, node_id: "U1", login: "al", avatar_url: "", html_url: "" })
: JSON.stringify({ data: { repository: { id: "R1", owner: { login: "acme" }, name: "app" } } }),
),
);
await refreshConnection();
const s = useGhRepository.getState();
expect(s.remotes.map((r) => `${r.host}/${r.owner}/${r.name}`)).toEqual([
"ghe.example.com/acme/app",
"github.com/acme/app-mirror",
]);
expect(await connect(s.remotes[0]!)).toBe(true);
expect(ghApi.mock.calls.map(([, req]) => [req.endpoint, req.host])).toEqual([
["graphql", "ghe.example.com"],
["user", "ghe.example.com"],
]);
// The github.com mirror goes back to gh's default host.
expect(await connect(s.remotes[1]!)).toBe(true);
expect(ghApi).toHaveBeenLastCalledWith("/w/app", expect.objectContaining({ host: null }));
});
});