Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GitLab] Fix opening empty GitLab repo #4521

Merged
merged 1 commit into from
Jun 16, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 35 additions & 2 deletions components/server/src/gitlab/gitlab-context-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,40 @@ export class GitlabContextParser extends AbstractContextParser implements IConte
protected async handleDefaultContext(user: User, host: string, owner: string, repoName: string): Promise<NavigatorContext> {
try {
const repository = await this.fetchRepo(user, `${owner}/${repoName}`);
return this.handleTreeContext(user, host, owner, repoName, repository.defaultBranch ? [ repository.defaultBranch ] : []);
if (!repository.defaultBranch) {
return <NavigatorContext>{
isFile: false,
path: '',
title: `${owner}/${repoName}`,
repository
}
}

try {
const branchOrTag = await this.getBranchOrTag(user, owner, repoName, [repository.defaultBranch!]);
return <NavigatorContext>{
isFile: false,
path: '',
title: `${owner}/${repoName} - ${branchOrTag.name}`,
ref: branchOrTag.name,
revision: branchOrTag.revision,
refType: branchOrTag.type,
repository
};
} catch (error) {
if (error && error.message && (error.message as string).startsWith("Cannot find tag/branch for context")) {
// the repo is empty (has no branches)
return <NavigatorContext>{
isFile: false,
path: '',
title: `${owner}/${repoName} - ${repository.defaultBranch}`,
revision: '',
repository
}
} else {
throw error;
}
}
} catch (error) {
if (UnauthorizedError.is(error)) {
throw error;
Expand All @@ -148,7 +181,7 @@ export class GitlabContextParser extends AbstractContextParser implements IConte
revision: branchOrTag && branchOrTag.revision,
refType: branchOrTag && branchOrTag.type,
repository
}
};
if (!branchOrTag) {
return context;
}
Expand Down