fix(shared): match source-control providers by DNS label (#6175)
This commit is contained in:
1 parent
ddee418a8d
commit
178da6bc32
2 files changed
+36
-3
No files matched your search
@@ -91,4 +91,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");
|
||||
});
|
||||
});
|
||||
@@ -167,12 +167,16 @@ 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 {
|
||||
@@ -188,7 +192,7 @@ function isAzureDevOpsHost(host: string): boolean {
|
||||
}
|
||||
|
||||
function isBitbucketHost(host: string): boolean {
|
||||
return host === "bitbucket.org" || host.includes("bitbucket");
|
||||
return host === "bitbucket.org" || hasDnsLabel(host, "bitbucket");
|
||||
}
|
||||
|
||||
export function detectSourceControlProviderFromRemoteUrl(
|
||||
|
||||
Reference in new issue
Block a user