дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-03 16:51:16 +02:00
fix(github): read a choice saved without a host as github.com's (#6753)
Follow-up to #6746. A repository choice saved as owner/name comes from a release that knew only github.com, so it now means github.com's repository of that name, and the Enterprise one only when github.com has none; #6746 had read it as the origin remote's, which reconnected some projects to the Enterprise server. The probe that picks where to ask gh follows the same rule and finds an Enterprise repository by its remote's path. Co-authored-by: wildcatDownstairs <[email protected]>
Цей коміт міститься в:
1 джерело
633bef2e69
коміт
3bc75e1de0
3 files changed
+69
-20
No files matched your search
@@ -167,18 +167,52 @@ describe("GitHub Enterprise Server hosts beside github.com", () => {
|
||||
expect(ghApi).toHaveBeenLastCalledWith("/w/app", expect.objectContaining({ host: "ghe.example.com" }));
|
||||
});
|
||||
|
||||
it("reads a choice saved without a host as the origin remote's repository", async () => {
|
||||
layout = {
|
||||
"/w/app": [
|
||||
{ name: "public", url: "https://github.com/acme/app.git" },
|
||||
{ name: "origin", url: "[email protected]:acme/app.git" },
|
||||
],
|
||||
};
|
||||
// A choice saved without a host comes from a release that knew only github.com.
|
||||
const legacy = async (remotes: Array<{ name: string; url: string }>) => {
|
||||
layout = { "/w/app": remotes };
|
||||
useProject.setState({ project: { root: "/w" } as never });
|
||||
localStorage.setItem("openidea.github.repository.v1:/w", "acme/app");
|
||||
ghAvailability.mockReturnValue(ready("https://ghe.example.com/acme/app"));
|
||||
ghApi.mockImplementation(answer);
|
||||
await refreshConnection();
|
||||
return useGhRepository.getState().connection?.coordinates;
|
||||
};
|
||||
|
||||
it("reads a choice saved without a host as github.com's repository", async () => {
|
||||
const connected = await legacy([
|
||||
{ name: "origin", url: "[email protected]:acme/app.git" },
|
||||
{ name: "public", url: "https://github.com/acme/app.git" },
|
||||
]);
|
||||
expect(connected).toMatchObject({ owner: "acme", name: "app", host: "github.com" });
|
||||
});
|
||||
|
||||
it("reads a choice saved without a host as the Enterprise repository when github.com has none", async () => {
|
||||
const connected = await legacy([
|
||||
{ name: "origin", url: "[email protected]:acme/app.git" },
|
||||
{ name: "public", url: "https://github.com/acme/tools.git" },
|
||||
]);
|
||||
expect(connected).toMatchObject({ owner: "acme", name: "app", host: "ghe.example.com" });
|
||||
});
|
||||
|
||||
it("asks gh in the repository holding the Enterprise choice when github.com's remotes don't have it", async () => {
|
||||
layout = {
|
||||
"/w/tools": [{ name: "origin", url: "https://github.com/acme/tools.git" }],
|
||||
"/w/app": [{ name: "origin", url: "[email protected]:acme/app.git" }],
|
||||
};
|
||||
useProject.setState({ project: { root: "/w" } as never });
|
||||
localStorage.setItem("openidea.github.repository.v1:/w", "acme/app");
|
||||
ghAvailability.mockImplementation((root: string | null) =>
|
||||
root === "/w/app"
|
||||
? ready("https://ghe.example.com/acme/app")
|
||||
: ok({
|
||||
kind: "ready",
|
||||
repo: { nameWithOwner: "acme/tools", url: "https://github.com/acme/tools" },
|
||||
login: "al",
|
||||
}),
|
||||
);
|
||||
ghApi.mockImplementation(answer);
|
||||
await refreshConnection();
|
||||
expect(ghAvailability).toHaveBeenCalledWith("/w/app");
|
||||
expect(useGhRepository.getState().connection?.coordinates).toMatchObject({ host: "ghe.example.com" });
|
||||
});
|
||||
|
||||
|
||||
@@ -194,14 +194,23 @@ export async function refreshConnection(): Promise<void> {
|
||||
const found = await projectGitHubRemotes();
|
||||
if (seq !== checkSeq) return;
|
||||
const current = useGhRepository.getState().connection?.coordinates ?? null;
|
||||
const saved = parseNameWithOwner(loadSelection(projectRoot()));
|
||||
// gh resolves its repository in a local one; ask in the one likely to be connected.
|
||||
const probe =
|
||||
(
|
||||
found.remotes.find((r) => sameRepository(r, current)) ??
|
||||
found.remotes.find((r) => sameRepository(r, saved)) ??
|
||||
found.remotes[0]
|
||||
)?.root ?? null;
|
||||
const stored = parseNameWithOwner(loadSelection(projectRoot()));
|
||||
// A choice saved without its host comes from a release that knew only github.com: that one first,
|
||||
// else the repository of that name on the Enterprise host.
|
||||
const legacy = stored && !stored.host ? { ...stored, host: "github.com" } : null;
|
||||
const savedIn = (list: readonly GHRemote[]) =>
|
||||
legacy && !list.some((r) => sameRepository(r, legacy)) ? stored : (legacy ?? stored);
|
||||
// gh resolves its repository in a local one; ask in the one likely to be connected. Before gh
|
||||
// names the Enterprise host only github.com remotes are known: find an Enterprise repository by
|
||||
// its remote's path, as `remoteOfRepository` does for SSH host aliases.
|
||||
const rootWith = (repo: GHRepositoryCoordinates | null) =>
|
||||
repo ? [...found.all].find(([, list]) => remoteOfRepository(list, repo))?.[0] : undefined;
|
||||
const known =
|
||||
found.remotes.find((r) => sameRepository(r, current)) ??
|
||||
found.remotes.find((r) => sameRepository(r, savedIn(found.remotes)));
|
||||
const probe = known
|
||||
? (known.root ?? null)
|
||||
: (rootWith(current) ?? rootWith(stored) ?? found.remotes[0]?.root ?? null);
|
||||
try {
|
||||
availability = await call(commands.ghAvailability(probe));
|
||||
} catch (e) {
|
||||
@@ -233,14 +242,12 @@ export async function refreshConnection(): Promise<void> {
|
||||
disconnect({ forget: false });
|
||||
return;
|
||||
}
|
||||
// A choice saved without its host (before hosts were recorded): the origin remote's, when it is one of them.
|
||||
const chosen = saved?.host
|
||||
? saved
|
||||
: (remotes.find((r) => r.remote === "origin" && sameRepository(r, saved)) ?? saved);
|
||||
const target =
|
||||
remotes.length === 1
|
||||
? remotes[0]!
|
||||
: (remotes.find((r) => sameRepository(r, current)) ?? remotes.find((r) => sameRepository(r, chosen)) ?? null);
|
||||
: (remotes.find((r) => sameRepository(r, current)) ??
|
||||
remotes.find((r) => sameRepository(r, savedIn(localRemotes))) ??
|
||||
null);
|
||||
// Only a choice among several repositories is remembered.
|
||||
if (target) await connect(target, { remember: remotes.length > 1 });
|
||||
else disconnect({ forget: false });
|
||||
|
||||
Reference in new issue
Заблокувати користувача