From 648adac316cadf1ab5f2287f8904ba486b38aa0f Mon Sep 17 00:00:00 2001 From: Auguste Rame <19855629+SuperAuguste@users.noreply.github.com> Date: Fri, 4 Aug 2023 15:42:57 +0200 Subject: [PATCH] Fix git SSH URL parsing (#567) Closes #566. ## Test plan CI passes. --- vscode/src/chat/utils.test.ts | 6 ++++++ vscode/src/chat/utils.ts | 7 ++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/vscode/src/chat/utils.test.ts b/vscode/src/chat/utils.test.ts index 28a89ec2d978..53e3de5754f2 100644 --- a/vscode/src/chat/utils.test.ts +++ b/vscode/src/chat/utils.test.ts @@ -16,6 +16,12 @@ describe('convertGitCloneURLToCodebaseName', () => { ) }) + test('converts SSH URL with custom user@', () => { + expect(convertGitCloneURLToCodebaseName('wq4235-wewrwweq_3efrge@github.com:sourcegraph/sourcegraph')).toEqual( + 'github.com/sourcegraph/sourcegraph' + ) + }) + test('converts GitHub HTTPS URL', () => { expect(convertGitCloneURLToCodebaseName('https://github.com/sourcegraph/sourcegraph')).toEqual( 'github.com/sourcegraph/sourcegraph' diff --git a/vscode/src/chat/utils.ts b/vscode/src/chat/utils.ts index 00784836b547..eb9ae45c3226 100644 --- a/vscode/src/chat/utils.ts +++ b/vscode/src/chat/utils.ts @@ -11,15 +11,16 @@ export function convertGitCloneURLToCodebaseName(cloneURL: string): string | nul return null } try { - const uri = new URL(cloneURL.replace('git@', '')) // Handle common Git SSH URL format - const match = cloneURL.match(/git@([^:]+):([\w-]+)\/([\w-]+)(\.git)?/) - if (cloneURL.startsWith('git@') && match) { + const match = cloneURL.match(/^[\w-]+@([^:]+):([\w-]+)\/([\w-]+)(\.git)?$/) + if (match) { const host = match[1] const owner = match[2] const repo = match[3] return `${host}/${owner}/${repo}` } + + const uri = new URL(cloneURL) // Handle GitHub URLs if (uri.protocol.startsWith('github') || uri.href.startsWith('github')) { return `github.com/${uri.pathname.replace('.git', '')}`