Skip to content

Commit 024f71a

Browse files
authored
[github] throw up error message from GH (#19993)
1 parent ebe64b5 commit 024f71a

File tree

8 files changed

+121
-37
lines changed

8 files changed

+121
-37
lines changed

components/dashboard/src/workspaces/CreateWorkspacePage.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -738,18 +738,21 @@ export const RepositoryNotFound: FC<{ error: StartWorkspaceError }> = ({ error }
738738
})
739739
.toString();
740740

741+
const errorMessage = error.data?.errorMessage || error.message;
742+
741743
if (!userScopes.includes(missingScope)) {
742744
return (
743745
<RepositoryInputError
744746
title="The repository may be private. Please authorize Gitpod to access private repositories."
747+
message={errorMessage}
745748
linkText="Grant access"
746749
linkHref={authorizeURL}
747750
/>
748751
);
749752
}
750753

751754
if (userIsOwner) {
752-
return <RepositoryInputError title="The repository was not found in your account." />;
755+
return <RepositoryInputError title="The repository was not found in your account." message={errorMessage} />;
753756
}
754757

755758
let updatedRecently = false;
@@ -766,6 +769,7 @@ export const RepositoryNotFound: FC<{ error: StartWorkspaceError }> = ({ error }
766769
return (
767770
<RepositoryInputError
768771
title={`Permission to access private repositories has been granted. If you are a member of '${owner}', please try to request access for Gitpod.`}
772+
message={errorMessage}
769773
linkText="Request access"
770774
linkHref={authorizeURL}
771775
/>
@@ -775,6 +779,7 @@ export const RepositoryNotFound: FC<{ error: StartWorkspaceError }> = ({ error }
775779
return (
776780
<RepositoryInputError
777781
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/.`}
782+
message={errorMessage}
778783
linkText="Check Organization Permissions"
779784
linkHref={"https://github.com/settings/connections/applications/484069277e293e6d2a2a"}
780785
/>
@@ -784,6 +789,7 @@ export const RepositoryNotFound: FC<{ error: StartWorkspaceError }> = ({ error }
784789
return (
785790
<RepositoryInputError
786791
title={`Your access token was updated recently. Please try again if the repository exists and Gitpod was approved for '${owner}'.`}
792+
message={errorMessage}
787793
linkText="Authorize again"
788794
linkHref={authorizeURL}
789795
/>

components/public-api/gitpod/v1/error.proto

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ message RepositoryNotFoundError {
4949
bool user_is_owner = 3;
5050
repeated string user_scopes = 4;
5151
string last_update = 5;
52+
string repo_name = 6;
53+
string error_message = 7;
5254
}
5355

5456
message RepositoryUnauthorizedError {

components/public-api/go/v1/error.pb.go

Lines changed: 51 additions & 31 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

components/public-api/typescript-common/src/public-api-converter.spec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,8 @@ describe("PublicAPIConverter", () => {
351351
lastUpdate: "2021-06-28T10:48:28Z",
352352
owner: "akosyakov",
353353
userIsOwner: true,
354+
repoName: "gitpod",
355+
errorMessage: "Repository not found.",
354356
userScopes: ["repo"],
355357
}),
356358
);

components/public-api/typescript/src/gitpod/v1/error_pb.ts

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

components/server/src/errors/index.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,26 @@ import {
1212
import { RepositoryUnauthorizedError } from "@gitpod/public-api/lib/gitpod/v1/error_pb";
1313

1414
export namespace NotFoundError {
15-
export async function create(token: Token | undefined, user: User, host: string, owner: string, repoName: string) {
15+
export async function create(
16+
token: Token | undefined,
17+
user: User,
18+
host: string,
19+
owner: string,
20+
repoName: string,
21+
errorMessage: string = "Repository not found.",
22+
) {
1623
const lastUpdate = (token && token.updateDate) || "";
1724
const userScopes = token ? [...token.scopes] : [];
1825

1926
const userIsOwner = owner == user.name; // TODO: shouldn't this be a comparison with `identity.authName`?
2027
return new RepositoryNotFoundError({
2128
host,
2229
owner,
30+
repoName,
2331
userIsOwner,
2432
userScopes,
2533
lastUpdate,
34+
errorMessage,
2635
});
2736
}
2837
export function is(error: any): error is RepositoryNotFoundError {

components/server/src/github/github-context-parser.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ export class GithubContextParser extends AbstractContextParser implements IConte
145145
this.config.host,
146146
owner,
147147
repoName,
148+
result.errors && result.errors.map((e: any) => e.message).join(", "),
148149
);
149150
}
150151
const defaultBranch = result.data.repository.defaultBranchRef;
@@ -231,6 +232,7 @@ export class GithubContextParser extends AbstractContextParser implements IConte
231232
this.config.host,
232233
owner,
233234
repoName,
235+
result.errors && result.errors.map((e: any) => e.message).join(", "),
234236
);
235237
}
236238

@@ -334,6 +336,7 @@ export class GithubContextParser extends AbstractContextParser implements IConte
334336
this.config.host,
335337
owner,
336338
repoName,
339+
result.errors && result.errors.map((e: any) => e.message).join(", "),
337340
);
338341
}
339342

@@ -427,6 +430,7 @@ export class GithubContextParser extends AbstractContextParser implements IConte
427430
this.config.host,
428431
owner,
429432
repoName,
433+
result.errors && result.errors.map((e: any) => e.message).join(", "),
430434
);
431435
}
432436
const pr = result.data.repository.pullRequest;
@@ -510,6 +514,7 @@ export class GithubContextParser extends AbstractContextParser implements IConte
510514
this.config.host,
511515
owner,
512516
repoName,
517+
result.errors && result.errors.map((e: any) => e.message).join(", "),
513518
);
514519
}
515520
const issue = result.data.repository.issue;

components/server/src/gitlab/gitlab-context-parser.ts

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,14 @@ export class GitlabContextParser extends AbstractContextParser implements IConte
190190
throw error;
191191
}
192192
// log.error({ userId: user.id }, error);
193-
throw await NotFoundError.create(await this.tokenHelper.getCurrentToken(user), user, host, owner, repoName);
193+
throw await NotFoundError.create(
194+
await this.tokenHelper.getCurrentToken(user),
195+
user,
196+
host,
197+
owner,
198+
repoName,
199+
error.message,
200+
);
194201
}
195202
}
196203

@@ -340,7 +347,14 @@ export class GitlabContextParser extends AbstractContextParser implements IConte
340347
return g.MergeRequests.show(`${owner}/${repoName}`, nr);
341348
});
342349
if (GitLab.ApiError.is(result)) {
343-
throw await NotFoundError.create(await this.tokenHelper.getCurrentToken(user), user, host, owner, repoName);
350+
throw await NotFoundError.create(
351+
await this.tokenHelper.getCurrentToken(user),
352+
user,
353+
host,
354+
owner,
355+
repoName,
356+
result.message,
357+
);
344358
}
345359
const sourceProjectId = result.source_project_id;
346360
const targetProjectId = result.target_project_id;
@@ -428,7 +442,14 @@ export class GitlabContextParser extends AbstractContextParser implements IConte
428442
return g.Issues.show(nr, { projectId: `${owner}/${repoName}` });
429443
});
430444
if (GitLab.ApiError.is(result)) {
431-
throw await NotFoundError.create(await this.tokenHelper.getCurrentToken(user), user, host, owner, repoName);
445+
throw await NotFoundError.create(
446+
await this.tokenHelper.getCurrentToken(user),
447+
user,
448+
host,
449+
owner,
450+
repoName,
451+
result.message,
452+
);
432453
}
433454
const context = await ctxPromise;
434455
return <IssueContext>{
@@ -450,7 +471,14 @@ export class GitlabContextParser extends AbstractContextParser implements IConte
450471
): Promise<NavigatorContext> {
451472
const repository = await this.fetchRepo(user, `${owner}/${repoName}`);
452473
if (GitLab.ApiError.is(repository)) {
453-
throw await NotFoundError.create(await this.tokenHelper.getCurrentToken(user), user, host, owner, repoName);
474+
throw await NotFoundError.create(
475+
await this.tokenHelper.getCurrentToken(user),
476+
user,
477+
host,
478+
owner,
479+
repoName,
480+
repository.message,
481+
);
454482
}
455483
const commit = await this.fetchCommit(user, `${owner}/${repoName}`, sha);
456484
if (GitLab.ApiError.is(commit)) {

0 commit comments

Comments
 (0)