Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions src/git.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,35 @@ describe("parseRepoUrl", () => {
});
});

describe("GitHub Enterprise Cloud (*.ghe.com)", () => {
it("should detect github provider for a *.ghe.com host", () => {
const result = parseRepoUrl("https://acme.ghe.com/engineering/platform.git");
expect(result).toEqual({
owner: "engineering",
name: "platform",
provider: "github",
url: "https://acme.ghe.com/engineering/platform",
});
});

it("should detect github provider for multi-part subdomains under .ghe.com", () => {
const result = parseRepoUrl("https://tenant-name.ghe.com/owner/repo.git");
expect(result?.provider).toBe("github");
});

it("should not match the bare ghe.com host (no subdomain)", () => {
const result = parseRepoUrl("https://ghe.com/owner/repo.git");
expect(result?.provider).toBeNull();
});

it("should not match hosts that merely contain .ghe.com as a substring", () => {
// Suffix match guards against attacker-controlled hosts that happen
// to include "ghe.com" somewhere in the middle of the hostname.
const result = parseRepoUrl("https://evil-ghe.com.attacker.com/owner/repo.git");
expect(result?.provider).toBeNull();
});
});

describe("unknown providers", () => {
it("should return null provider for unknown hosts", () => {
const result = parseRepoUrl("https://example.com/myorg/myrepo.git");
Expand Down
2 changes: 1 addition & 1 deletion src/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ function hostToProvider(host: string): string | null {
if (host === "gitlab.com" || host.includes("gitlab")) {
return "gitlab";
}
if (host === "github.com" || host.includes("github")) {
if (host === "github.com" || host.endsWith(".ghe.com") || host.includes("github")) {
return "github";
}
return null;
Expand Down
Loading