Skip to content

Open-source Grok Bot alternative for named AI teammates. Local-first desktop, web, and mobile clients with per-bot tools, instructions, and memory. Independent fork of T3 Code.

fix(shared): match source-control providers by DNS label (#6175)

Guilherme Barros178da6bc3210
diff --git a/packages/shared/src/sourceControl.test.ts b/packages/shared/src/sourceControl.test.ts
index bfee883dd..3842fa84b 100644
--- a/packages/shared/src/sourceControl.test.ts
+++ b/packages/shared/src/sourceControl.test.ts
@@ -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");
+ });
});
diff --git a/packages/shared/src/sourceControl.ts b/packages/shared/src/sourceControl.ts
index a29fe968e..ad6fa890b 100644
--- a/packages/shared/src/sourceControl.ts
+++ b/packages/shared/src/sourceControl.ts
@@ -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(