Skip to content

Commit

Permalink
[GitLab] Fix opening empty GitLab repo
Browse files Browse the repository at this point in the history
  • Loading branch information
corneliusludmann committed Jun 16, 2021
1 parent a97c197 commit d9aba83
Showing 1 changed file with 35 additions and 2 deletions.
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

0 comments on commit d9aba83

Please sign in to comment.