TypeScript
fix(shared): detect *.ghe.com remotes as GitHub (#19362)
Torjus Bjåen93d0e1a8e6b7
diff --git a/packages/shared/src/sourceControl.test.ts b/packages/shared/src/sourceControl.test.tsindex 7395c4b6ad2..80f0184da1a 100644--- a/packages/shared/src/sourceControl.test.ts+++ b/packages/shared/src/sourceControl.test.ts@@ -147,6 +147,22 @@ describe("detectSourceControlProviderFromRemoteUrl", () => {).toBe("bitbucket");});+ it("detects GitHub Enterprise Cloud data residency hosts on ghe.com", () => {+ expect(detectSourceControlProviderFromRemoteUrl("https://acme.ghe.com/owner/repo.git")).toEqual(+ {+ kind: "github",+ name: "GitHub Self-Hosted",+ baseUrl: "https://acme.ghe.com",+ },+ );+ expect(detectSourceControlProviderFromRemoteUrl("[email protected]:owner/repo.git")?.kind).toBe(+ "github",+ );+ expect(detectSourceControlProviderFromRemoteUrl("https://ghe.com/owner/repo.git")?.kind).toBe(+ "unknown",+ );+ });+it("does not match provider names embedded in unrelated DNS labels", () => {expect(detectSourceControlProviderFromRemoteUrl("https://notgithub.example.com/owner/repo.git")diff --git a/packages/shared/src/sourceControl.ts b/packages/shared/src/sourceControl.tsindex fcda71b64f8..c9bc11701a3 100644--- a/packages/shared/src/sourceControl.ts+++ b/packages/shared/src/sourceControl.ts@@ -179,8 +179,9 @@ function hasDnsLabel(host: string, label: string): boolean {return host.split(".").includes(label);}+/** `*.ghe.com` is GitHub Enterprise Cloud with data residency, one subdomain per enterprise. */function isGitHubHost(host: string): boolean {- return host === "github.com" || hasDnsLabel(host, "github");+ return host === "github.com" || host.endsWith(".ghe.com") || hasDnsLabel(host, "github");}function isGitLabHost(host: string): boolean {