| author | |
| committer | |
| log | 178da6bc3210b82c4a83f33c8b149f623a3375e1 |
| tree | 72825d30e530ef7f1d507db74b4aa129a0d66fa0 |
| parent | ddee418a8d6d3e242ca26a8053a886ecc3b56b53 |
| signature | Signed by PGP key B5690EEEBB952194 |
2 files changed, 36 insertions(+), 3 deletions(-)
packages/shared/src/sourceControl.test.ts+29| ... | ... | @@ -91,4 +91,33 @@ describe("detectSourceControlProviderFromRemoteUrl", () => { |
| 91 | 91 | baseUrl: "https://self-hosted.example.test:8443", |
| 92 | 92 | }); |
| 93 | 93 | }); |
| 94 | ||
| 95 | it("matches self-hosted providers by complete DNS labels", () => { | |
| 96 | expect( | |
| 97 | detectSourceControlProviderFromRemoteUrl("https://github.example.com/owner/repo.git")?.kind, | |
| 98 | ).toBe("github"); | |
| 99 | expect( | |
| 100 | detectSourceControlProviderFromRemoteUrl("https://gitlab.example.com/group/repo.git")?.kind, | |
| 101 | ).toBe("gitlab"); | |
| 102 | expect( | |
| 103 | detectSourceControlProviderFromRemoteUrl("https://bitbucket.example.com/workspace/repo.git") | |
| 104 | ?.kind, | |
| 105 | ).toBe("bitbucket"); | |
| 106 | }); | |
| 107 | ||
| 108 | it("does not match provider names embedded in unrelated DNS labels", () => { | |
| 109 | expect( | |
| 110 | detectSourceControlProviderFromRemoteUrl("https://notgithub.example.com/owner/repo.git") | |
| 111 | ?.kind, | |
| 112 | ).toBe("unknown"); | |
| 113 | expect( | |
| 114 | detectSourceControlProviderFromRemoteUrl("https://notgitlab.example.com/group/repo.git") | |
| 115 | ?.kind, | |
| 116 | ).toBe("unknown"); | |
| 117 | expect( | |
| 118 | detectSourceControlProviderFromRemoteUrl( | |
| 119 | "https://notbitbucket.example.com/workspace/repo.git", | |
| 120 | )?.kind, | |
| 121 | ).toBe("unknown"); | |
| 122 | }); | |
| 94 | 123 | }); |
packages/shared/src/sourceControl.ts+7-3| ... | ... | @@ -167,12 +167,16 @@ function toBaseUrl(host: string): string { |
| 167 | 167 | return `https://${host}`; |
| 168 | 168 | } |
| 169 | 169 | |
| 170 | function hasDnsLabel(host: string, label: string): boolean { | |
| 171 | return host.split(".").includes(label); | |
| 172 | } | |
| 173 | ||
| 170 | 174 | function isGitHubHost(host: string): boolean { |
| 171 | return host === "github.com" || host.includes("github"); | |
| 175 | return host === "github.com" || hasDnsLabel(host, "github"); | |
| 172 | 176 | } |
| 173 | 177 | |
| 174 | 178 | function isGitLabHost(host: string): boolean { |
| 175 | return host === "gitlab.com" || host.includes("gitlab"); | |
| 179 | return host === "gitlab.com" || hasDnsLabel(host, "gitlab"); | |
| 176 | 180 | } |
| 177 | 181 | |
| 178 | 182 | function isAzureDevOpsHost(host: string): boolean { |
| ... | ... | @@ -188,7 +192,7 @@ function isAzureDevOpsHost(host: string): boolean { |
| 188 | 192 | } |
| 189 | 193 | |
| 190 | 194 | function isBitbucketHost(host: string): boolean { |
| 191 | return host === "bitbucket.org" || host.includes("bitbucket"); | |
| 195 | return host === "bitbucket.org" || hasDnsLabel(host, "bitbucket"); | |
| 192 | 196 | } |
| 193 | 197 | |
| 194 | 198 | export function detectSourceControlProviderFromRemoteUrl( |