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 packages/shared/src/sourceControl.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,33 @@ describe("detectSourceControlProviderFromRemoteUrl", () => {
baseUrl: "https://self-hosted.example.test:8443",
});
});

it("matches self-hosted providers by complete DNS labels", () => {
expect(
detectSourceControlProviderFromRemoteUrl("https://github.example.com/owner/repo.git")?.kind,
).toBe("github");
expect(
detectSourceControlProviderFromRemoteUrl("https://gitlab.example.com/group/repo.git")?.kind,
).toBe("gitlab");
expect(
detectSourceControlProviderFromRemoteUrl("https://bitbucket.example.com/workspace/repo.git")
?.kind,
).toBe("bitbucket");
});

it("does not match provider names embedded in unrelated DNS labels", () => {
expect(
detectSourceControlProviderFromRemoteUrl("https://notgithub.example.com/owner/repo.git")
?.kind,
).toBe("unknown");
expect(
detectSourceControlProviderFromRemoteUrl("https://notgitlab.example.com/group/repo.git")
?.kind,
).toBe("unknown");
expect(
detectSourceControlProviderFromRemoteUrl(
"https://notbitbucket.example.com/workspace/repo.git",
)?.kind,
).toBe("unknown");
});
});
10 changes: 7 additions & 3 deletions packages/shared/src/sourceControl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,20 +167,24 @@ function toBaseUrl(host: string): string {
return `https://${host}`;
}

function hasDnsLabel(host: string, label: string): boolean {
return host.split(".").includes(label);
}

function isGitHubHost(host: string): boolean {
return host === "github.com" || host.includes("github");
return host === "github.com" || hasDnsLabel(host, "github");
}

function isGitLabHost(host: string): boolean {
return host === "gitlab.com" || host.includes("gitlab");
return host === "gitlab.com" || hasDnsLabel(host, "gitlab");
}

function isAzureDevOpsHost(host: string): boolean {
return host === "dev.azure.com" || host.endsWith(".visualstudio.com");
}

function isBitbucketHost(host: string): boolean {
return host === "bitbucket.org" || host.includes("bitbucket");
return host === "bitbucket.org" || hasDnsLabel(host, "bitbucket");
}

export function detectSourceControlProviderFromRemoteUrl(
Expand Down
Loading