From 2b2cf276a801d11562e3d8e46b2eb48545a8ec6c Mon Sep 17 00:00:00 2001 From: Gustav Utterheim Date: Fri, 17 Oct 2025 17:54:26 +0200 Subject: [PATCH] Fix ghe.com implementation --- src/git/repository.ts | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/git/repository.ts b/src/git/repository.ts index e62253c..91a4426 100644 --- a/src/git/repository.ts +++ b/src/git/repository.ts @@ -16,6 +16,24 @@ interface GitHubUrls { protocol: Protocol; } +const gitRemotePattern = + /^(?:(?:(?:git|ssh|rsync|https?):\/\/)?(?:(?:git|\w+)@)?(?[\w.]+))(?:[\w.@:/\-~]+)(?:\.git)\/?$/; + +function isGithubEnterpriseCloudWithDataResidencyRemote(pushUrl?: string): boolean { + if (!pushUrl) { + return false; + } + + try { + const url = new URL(pushUrl); + return url.host.endsWith(".ghe.com"); + } catch (_error) { + const match = gitRemotePattern.exec(pushUrl); + + return Boolean(match?.groups?.host?.endsWith(".ghe.com")); + } +} + async function getGitExtension(): Promise { const gitExtension = vscode.extensions.getExtension("vscode.git"); if (gitExtension) { @@ -77,8 +95,9 @@ export async function getGitHubUrls(): Promise { if ( remote.length > 0 && (remote[0].pushUrl?.indexOf("github.com") !== -1 || - (useEnterprise() && remote[0].pushUrl?.indexOf(new URL(getGitHubApiUri()).host) !== -1) || - (remote[0].pushUrl ? new URL(remote[0].pushUrl).host.endsWith(".ghe.com") : false)) + (useEnterprise() && + (remote[0].pushUrl?.indexOf(new URL(getGitHubApiUri()).host) !== -1 || + isGithubEnterpriseCloudWithDataResidencyRemote(remote[0].pushUrl)))) ) { const url = remote[0].pushUrl;