in src/desktop/remotefs/gitlab_remote_file_system.ts [71:111]
static parseUri(uri: vscode.Uri): GitLabRemotePath {
if (uri.scheme !== REMOTE_URI_SCHEME) {
throw new HelpError(
`URI is not a GitLab remote. It begins with ${uri.scheme} but it should begin with ${REMOTE_URI_SCHEME}`,
{ section: README_SECTIONS.REMOTEFS },
);
}
const query = new URLSearchParams(uri.query);
const project = query.get('project');
if (!project)
throw new HelpError(
'URI is not a GitLab remote. The URI must contain a project= query parameter',
{ section: README_SECTIONS.REMOTEFS },
);
const ref = query.get('ref');
if (!ref)
throw new HelpError(
'URI is not a GitLab remote. The URI must contain a ref= query parameter',
{ section: README_SECTIONS.REMOTEFS },
);
// Find the instance with a matching authority and a subpath that is a
// prefix of the URI's path.
const instance = accountService
.getInstanceUrls()
.map(x => vscode.Uri.parse(x))
.find(x => uri.authority === x.authority && uri.path.startsWith(x.path));
if (!instance)
throw new HelpError(
`Cannot open ${uri}: missing token for GitLab instance ${uri.authority}`,
{ section: README_SECTIONS.SETUP },
);
// To get the file path, we first remove the instance subpath, then the
// project label.
const pathWithoutInstanceSubpath = uri.path.substring(instance.path.length).replace(/^\//, '');
const pathWithoutFirstSegment = pathWithoutInstanceSubpath.replace(/^[^/]+(\/|$)/, '');
return { instance, project, ref, path: pathWithoutFirstSegment };
}