History

Only claim unambiguous git URLs in connect-dialog detection

Rhys Sullivan committed 4 months ago

Commit 91fae1d1 parent 0aa658d1 file · +12 −0Browse files

Unified · Split

packages/react/src/pages/integrations.tsx+12−0
@@ -67,6 +67,13 @@ const bestDetection = ( · 66 unmodified lines
6767 ): IntegrationDetectionResult | undefined =>
6868 [...results].sort((a, b) => detectionRank[b.confidence] - detectionRank[a.confidence])[0];
6969
70+// Hosts where a two-segment path (owner/repo) is unambiguously a git remote.
71+const GIT_REPO_HOSTS = new Set(["github.com", "gitlab.com", "bitbucket.org", "codeberg.org"]);
72+
73+// Deliberately conservative: only claim URLs that are unambiguously git
74+// remotes (a `.git` suffix, or owner/repo on a known git host). Anything else
75+// falls through to the server-side detection so OpenAPI/MCP/GraphQL URLs keep
76+// their existing flows.
7077 const detectGitRepository = (
7178 raw: string,
7279 ): { readonly endpoint: string; readonly slug: string } | null => {
@@ -76,6 +83,11 @@ const detectGitRepository = ( · 3 unmodified lines
7683 if (parsed.protocol !== "https:" && parsed.protocol !== "http:") return null;
7784 if (parsed.username || parsed.password) return null;
7885 const segments = parsed.pathname.split("/").filter(Boolean);
86+ const knownGitHost =
87+ GIT_REPO_HOSTS.has(parsed.hostname.toLowerCase()) &&
88+ segments.length === 2 &&
89+ parsed.search === "";
90+ if (!parsed.pathname.endsWith(".git") && !knownGitHost) return null;
7991 const name = segments.at(-1)?.replace(/\.git$/, "") ?? "";
8092 if (!name) return null;
8193 parsed.hash = "";