diff --git a/src/git/git_remote_parser.test.ts b/src/git/git_remote_parser.test.ts index 33cba5a3530e32209b4cbe09937b347569cf5928..722eaa6e730e40e2692cc3ba80f53a69b98718bb 100644 --- a/src/git/git_remote_parser.test.ts +++ b/src/git/git_remote_parser.test.ts @@ -81,4 +81,17 @@ describe('git_remote_parser', () => { project: 'gitlab-vscode-extension', }); }); + // For more details see: https://gitlab.com/gitlab-org/gitlab-vscode-extension/-/issues/103 + it('should parse remote URLs without custom path even if the instance has custom path', () => { + expect( + parseGitRemote( + 'git@example.com:fatihacet/gitlab-vscode-extension.git', + 'https://example.com/gitlab', + ), + ).toEqual({ + host: 'example.com', + namespace: 'fatihacet', + project: 'gitlab-vscode-extension', + }); + }); }); diff --git a/src/git/git_remote_parser.ts b/src/git/git_remote_parser.ts index 2503dfa0fc6bb45c3d0bf28bff7285039825d0be..d92403b05a1be31ef7dda8d52f47cb9cd81ec90a 100644 --- a/src/git/git_remote_parser.ts +++ b/src/git/git_remote_parser.ts @@ -25,9 +25,13 @@ export function parseGitRemote(remote: string, instanceUrl?: string): GitRemote if (!host || !pathname) { return undefined; } - + // The instance url might have a custom route, i.e. www.company.com/gitlab. This route is + // optional in the remote url. This regex extracts namespace and project from the remote + // url while ignoring any custom route, if present. For more information see: + // - https://gitlab.com/gitlab-org/gitlab-vscode-extension/-/merge_requests/11 + // - https://gitlab.com/gitlab-org/gitlab-vscode-extension/-/issues/103 const pathRegExp = instanceUrl ? escapeForRegExp(getInstancePath(instanceUrl)) : ''; - const match = pathname.match(`${pathRegExp}/:?(.+)/([^/]+?)(?:.git)?/?$`); + const match = pathname.match(`(?:${pathRegExp})?/:?(.+)/([^/]+?)(?:.git)?/?$`); if (!match) { return undefined; }