Skip to content

Commit

Permalink
Fix git SSH URL parsing (#567)
Browse files Browse the repository at this point in the history
Closes #566.

## Test plan

CI passes.
  • Loading branch information
SuperAuguste authored Aug 4, 2023
1 parent 91f1df0 commit 648adac
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
6 changes: 6 additions & 0 deletions vscode/src/chat/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ describe('convertGitCloneURLToCodebaseName', () => {
)
})

test('converts SSH URL with custom user@', () => {
expect(convertGitCloneURLToCodebaseName('[email protected]:sourcegraph/sourcegraph')).toEqual(
'github.com/sourcegraph/sourcegraph'
)
})

test('converts GitHub HTTPS URL', () => {
expect(convertGitCloneURLToCodebaseName('https://github.com/sourcegraph/sourcegraph')).toEqual(
'github.com/sourcegraph/sourcegraph'
Expand Down
7 changes: 4 additions & 3 deletions vscode/src/chat/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', '')}`
Expand Down

0 comments on commit 648adac

Please sign in to comment.