Skip to content
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -736,18 +736,21 @@ export const RepositoryNotFound: FC<{ error: StartWorkspaceError }> = ({ error }
})
.toString();

const errorMessage = error.data?.errorMessage || error.message;

if (!userScopes.includes(missingScope)) {
return (
<RepositoryInputError
title="The repository may be private. Please authorize Gitpod to access private repositories."
message={errorMessage}
linkText="Grant access"
linkHref={authorizeURL}
/>
);
}

if (userIsOwner) {
return <RepositoryInputError title="The repository was not found in your account." />;
return <RepositoryInputError title="The repository was not found in your account." message={errorMessage} />;
}

let updatedRecently = false;
Expand All @@ -764,6 +767,7 @@ export const RepositoryNotFound: FC<{ error: StartWorkspaceError }> = ({ error }
return (
<RepositoryInputError
title={`Permission to access private repositories has been granted. If you are a member of '${owner}', please try to request access for Gitpod.`}
message={errorMessage}
linkText="Request access"
linkHref={authorizeURL}
/>
Expand All @@ -773,6 +777,7 @@ export const RepositoryNotFound: FC<{ error: StartWorkspaceError }> = ({ error }
return (
<RepositoryInputError
title={`Although you appear to have the correct authorization credentials, the '${owner}' organization has enabled OAuth App access restrictions, meaning that data access to third-parties is limited. For more information on these restrictions, including how to enable this app, visit https://docs.github.com/articles/restricting-access-to-your-organization-s-data/.`}
message={errorMessage}
linkText="Check Organization Permissions"
linkHref={"https://github.com/settings/connections/applications/484069277e293e6d2a2a"}
/>
Expand All @@ -782,6 +787,7 @@ export const RepositoryNotFound: FC<{ error: StartWorkspaceError }> = ({ error }
return (
<RepositoryInputError
title={`Your access token was updated recently. Please try again if the repository exists and Gitpod was approved for '${owner}'.`}
message={errorMessage}
linkText="Authorize again"
linkHref={authorizeURL}
/>
Expand Down
2 changes: 2 additions & 0 deletions components/public-api/gitpod/v1/error.proto
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ message RepositoryNotFoundError {
bool user_is_owner = 3;
repeated string user_scopes = 4;
string last_update = 5;
string repo_name = 6;
string error_message = 7;
}

message RepositoryUnauthorizedError {
Expand Down
82 changes: 51 additions & 31 deletions components/public-api/go/v1/error.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,8 @@ describe("PublicAPIConverter", () => {
lastUpdate: "2021-06-28T10:48:28Z",
owner: "akosyakov",
userIsOwner: true,
repoName: "gitpod",
errorMessage: "Repository not found.",
userScopes: ["repo"],
}),
);
Expand Down
12 changes: 12 additions & 0 deletions components/public-api/typescript/src/gitpod/v1/error_pb.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 10 additions & 1 deletion components/server/src/errors/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,26 @@ import {
import { RepositoryUnauthorizedError } from "@gitpod/public-api/lib/gitpod/v1/error_pb";

export namespace NotFoundError {
export async function create(token: Token | undefined, user: User, host: string, owner: string, repoName: string) {
export async function create(
token: Token | undefined,
user: User,
host: string,
owner: string,
repoName: string,
errorMessage: string = "Repository not found.",
) {
const lastUpdate = (token && token.updateDate) || "";
const userScopes = token ? [...token.scopes] : [];

const userIsOwner = owner == user.name; // TODO: shouldn't this be a comparison with `identity.authName`?
return new RepositoryNotFoundError({
host,
owner,
repoName,
userIsOwner,
userScopes,
lastUpdate,
errorMessage,
});
}
export function is(error: any): error is RepositoryNotFoundError {
Expand Down
5 changes: 5 additions & 0 deletions components/server/src/github/github-context-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ export class GithubContextParser extends AbstractContextParser implements IConte
this.config.host,
owner,
repoName,
result.errors && result.errors.map((e: any) => e.message).join(", "),
);
}
const defaultBranch = result.data.repository.defaultBranchRef;
Expand Down Expand Up @@ -231,6 +232,7 @@ export class GithubContextParser extends AbstractContextParser implements IConte
this.config.host,
owner,
repoName,
result.errors && result.errors.map((e: any) => e.message).join(", "),
);
}

Expand Down Expand Up @@ -334,6 +336,7 @@ export class GithubContextParser extends AbstractContextParser implements IConte
this.config.host,
owner,
repoName,
result.errors && result.errors.map((e: any) => e.message).join(", "),
);
}

Expand Down Expand Up @@ -427,6 +430,7 @@ export class GithubContextParser extends AbstractContextParser implements IConte
this.config.host,
owner,
repoName,
result.errors && result.errors.map((e: any) => e.message).join(", "),
);
}
const pr = result.data.repository.pullRequest;
Expand Down Expand Up @@ -510,6 +514,7 @@ export class GithubContextParser extends AbstractContextParser implements IConte
this.config.host,
owner,
repoName,
result.errors && result.errors.map((e: any) => e.message).join(", "),
);
}
const issue = result.data.repository.issue;
Expand Down
36 changes: 32 additions & 4 deletions components/server/src/gitlab/gitlab-context-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,14 @@ export class GitlabContextParser extends AbstractContextParser implements IConte
throw error;
}
// log.error({ userId: user.id }, error);
throw await NotFoundError.create(await this.tokenHelper.getCurrentToken(user), user, host, owner, repoName);
throw await NotFoundError.create(
await this.tokenHelper.getCurrentToken(user),
user,
host,
owner,
repoName,
error.message,
);
}
}

Expand Down Expand Up @@ -340,7 +347,14 @@ export class GitlabContextParser extends AbstractContextParser implements IConte
return g.MergeRequests.show(`${owner}/${repoName}`, nr);
});
if (GitLab.ApiError.is(result)) {
throw await NotFoundError.create(await this.tokenHelper.getCurrentToken(user), user, host, owner, repoName);
throw await NotFoundError.create(
await this.tokenHelper.getCurrentToken(user),
user,
host,
owner,
repoName,
result.message,
);
}
const sourceProjectId = result.source_project_id;
const targetProjectId = result.target_project_id;
Expand Down Expand Up @@ -428,7 +442,14 @@ export class GitlabContextParser extends AbstractContextParser implements IConte
return g.Issues.show(nr, { projectId: `${owner}/${repoName}` });
});
if (GitLab.ApiError.is(result)) {
throw await NotFoundError.create(await this.tokenHelper.getCurrentToken(user), user, host, owner, repoName);
throw await NotFoundError.create(
await this.tokenHelper.getCurrentToken(user),
user,
host,
owner,
repoName,
result.message,
);
}
const context = await ctxPromise;
return <IssueContext>{
Expand All @@ -450,7 +471,14 @@ export class GitlabContextParser extends AbstractContextParser implements IConte
): Promise<NavigatorContext> {
const repository = await this.fetchRepo(user, `${owner}/${repoName}`);
if (GitLab.ApiError.is(repository)) {
throw await NotFoundError.create(await this.tokenHelper.getCurrentToken(user), user, host, owner, repoName);
throw await NotFoundError.create(
await this.tokenHelper.getCurrentToken(user),
user,
host,
owner,
repoName,
repository.message,
);
}
const commit = await this.fetchCommit(user, `${owner}/${repoName}`, sha);
if (GitLab.ApiError.is(commit)) {
Expand Down