fix(server): repository identity honors the gh default remote #21574
Mergedjuliusmarmingemerged 16 commits into
main fromrefs/pull/21574/headmerged by juliusmarminge View on GitHubjuliusmarminge changed the title
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
juliusmarminge added labelsmacroscope-review
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:M
- apps/server/src/project/RepositoryIdentityResolver.ts line 103OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -77,3 +83,21 @@83+ }84+ if (remoteUrl.includes("://")) {85+ try {86+ const url = new URL(remoteUrl);87+ if (!url.hostname) return null;88+ const suffix = /\.git\/?$/i.test(url.pathname) ? ".git" : "";89+ url.pathname = `/${repository}${suffix}`;90+ return url.toString();91+ } catch {92+ return null;93+ }94+ }95+ const prefix = /^([^/:\s]+:)/u.exec(remoteUrl)?.[1];96+ return prefix ? `${prefix}${repository}${/\.git\/?$/i.test(remoteUrl) ? ".git" : ""}` : null;97+}98+7799 function pickPrimaryRemote(78100 remotes: ReadonlyMap<string, string>,101+ resolved: string,79102 ): { readonly remoteName: string; readonly remoteUrl: string } | null {103+ // gh stores `base` for the marked remote, or OWNER/REPO for a parent with no remote.
- packages/shared/src/changeRequestUrl.ts lines 62 to 62OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -46,16 +46,17 @@4646 if (isHostOf(host, "bitbucket.org", "bitbucket")) {4747 const match = /^\/([^/]+\/[^/]+)\/pull-requests\/(\d+)(?:\/|$)/u.exec(url.pathname);48- return claim(host, match);48+ return claim(url, match);4949 }5050 if (isHostOf(host, "dev.azure.com") || host.endsWith(".visualstudio.com")) {5151 const match = /^\/((?:[^/]+\/)*_git\/[^/]+)\/pullrequest\/(\d+)(?:\/|$)/u.exec(url.pathname);52- return claim(host, match);52+ return claim(url, match);5353 }5454 return null;5555 }565657-function claim(host: string, match: RegExpExecArray | null): ChangeRequestLink | null {57+function claim(url: URL, match: RegExpExecArray | null): ChangeRequestLink | null {5858 const repository = match?.[1];5959 const number = Number(match?.[2]);6060 return repository && Number.isSafeInteger(number) && number > 061- ? { host, repository: repository.toLowerCase(), number }61+ ? {62+ host: url.host.toLowerCase(),
- @@ -78,3 +96,21 @@96+ const prefix = /^([^/:\s]+:)/u.exec(remoteUrl)?.[1];97+ return prefix ? `${prefix}${repository}${/\.git\/?$/i.test(remoteUrl) ? ".git" : ""}` : null;98+}99+78100 function pickPrimaryRemote(79101 remotes: ReadonlyMap<string, string>,102+ resolved: string,80103 ): { readonly remoteName: string; readonly remoteUrl: string } | null {104+ // gh stores `base` for the marked remote, or OWNER/REPO for a parent with no remote.105+ let markedRemote: { readonly remoteName: string; readonly remoteUrl: string } | null = null;106+ let validMarkCount = 0;107+ for (const line of resolved.split("\n")) {108+ const match = /^remote\.(.+)\.gh-resolved\s+(\S+)$/u.exec(line.trim());109+ const remoteName = match?.[1];110+ const repository = match?.[2];111+ const markedUrl = remoteName ? remotes.get(remoteName) : undefined;112+ if (!remoteName || !repository || !markedUrl) continue;113+ const remoteUrl = repository === "base" ? markedUrl : withRepositoryPath(markedUrl, repository);114+ if (remoteUrl) {115+ markedRemote = { remoteName, remoteUrl };116+ validMarkCount++;@@ -53,9 +53,17 @@53- const link = claim(host, azure);54- return link === null || url.port === "" ? link : { ...link, authority: url.host.toLowerCase() };53+ const link = claim(url, azure);54+ return link === null || url.port === ""55+ ? link56+ : { ...link, host, authority: url.host.toLowerCase() };5557 }565857-function claim(host: string, match: RegExpExecArray | null): ChangeRequestLink | null {59+function claim(url: URL, match: RegExpExecArray | null): ChangeRequestLink | null {5860 const repository = match?.[1];5961 const number = Number(match?.[2]);6062 return repository && Number.isSafeInteger(number) && number > 061- ? { host, repository: repository.toLowerCase(), number }63+ ? {64+ host: url.host.toLowerCase(),65+ repository: repository.toLowerCase(),66+ number,67+ // Older stored link keys need the URL's authority to recover their web port.68+ ...(url.port ? { authority: url.host.toLowerCase() } : {}),69+ }
juliusmarminge added labelsbugfix
juliusmarminge added labelspr:gate-failed
tanstack-source added labelsbug
juliusmarminge added labelstakeover:in-progress
juliusmarminge added labelstakeover:ready
juliusmarminge removed labelstakeover:in-progress
juliusmarminge merged this56e58a9
juliusmarminge closed this
juliusmarminge removed labelstakeover:ready
Sign in to join this conversation.



macroscopeapp[bot](GitHub profile, opens in a new tab) reviewed