提交 0b487a62 编写于 作者: M Max Linke 提交者: Tomas Vik

fix: api calls fail when instance is on custom path

上级 3af084dc
......@@ -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',
});
});
});
......@@ -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;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册