From 2e57922dead255a7f6d90d6d47c5fb642ad836d1 Mon Sep 17 00:00:00 2001 From: Johan Haals Date: Tue, 9 Mar 2021 14:58:14 +0100 Subject: [PATCH 1/3] scaffolder: Improve GitHub publishers permission update error message Signed-off-by: Johan Haals --- .changeset/wet-hounds-vanish.md | 5 +++ .../src/scaffolder/stages/publish/github.ts | 40 ++++++++++--------- 2 files changed, 27 insertions(+), 18 deletions(-) create mode 100644 .changeset/wet-hounds-vanish.md diff --git a/.changeset/wet-hounds-vanish.md b/.changeset/wet-hounds-vanish.md new file mode 100644 index 0000000000..1a74bfb08d --- /dev/null +++ b/.changeset/wet-hounds-vanish.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-scaffolder-backend': patch +--- + +Update GitHub publisher to display a more helpful error message when repository access update fails. diff --git a/plugins/scaffolder-backend/src/scaffolder/stages/publish/github.ts b/plugins/scaffolder-backend/src/scaffolder/stages/publish/github.ts index a449eddd5d..22233ee5dc 100644 --- a/plugins/scaffolder-backend/src/scaffolder/stages/publish/github.ts +++ b/plugins/scaffolder-backend/src/scaffolder/stages/publish/github.ts @@ -131,25 +131,29 @@ export class GithubPublisher implements PublisherBase { const { data } = await repoCreationPromise; - if (access?.startsWith(`${owner}/`)) { - const [, team] = access.split('/'); - await client.teams.addOrUpdateRepoPermissionsInOrg({ - org: owner, - team_slug: team, - owner, - repo: name, - permission: 'admin', - }); - // no need to add access if it's the person who own's the personal account - } else if (access && access !== owner) { - await client.repos.addCollaborator({ - owner, - repo: name, - username: access, - permission: 'admin', - }); + try { + if (access?.startsWith(`${owner}/`)) { + const [, team] = access.split('/'); + await client.teams.addOrUpdateRepoPermissionsInOrg({ + org: owner, + team_slug: team, + owner, + repo: name, + permission: 'admin', + }); + // no need to add access if it's the person who own's the personal account + } else if (access && access !== owner) { + await client.repos.addCollaborator({ + owner, + repo: name, + username: access, + permission: 'admin', + }); + } + } catch (e) { + e.message = `Failed to add access to '${access}': ${e.message}`; + throw e; } - return data?.clone_url; } } From 12cdd556e7648b59c2b6fa444a171cf67b110a75 Mon Sep 17 00:00:00 2001 From: Johan Haals Date: Tue, 9 Mar 2021 15:40:01 +0100 Subject: [PATCH 2/3] Update plugins/scaffolder-backend/src/scaffolder/stages/publish/github.ts Signed-off-by: Johan Haals johan.haals@gmail.com Co-authored-by: Adam Harvey Signed-off-by: Johan Haals --- .../scaffolder-backend/src/scaffolder/stages/publish/github.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/scaffolder-backend/src/scaffolder/stages/publish/github.ts b/plugins/scaffolder-backend/src/scaffolder/stages/publish/github.ts index 22233ee5dc..bc2537a766 100644 --- a/plugins/scaffolder-backend/src/scaffolder/stages/publish/github.ts +++ b/plugins/scaffolder-backend/src/scaffolder/stages/publish/github.ts @@ -141,7 +141,7 @@ export class GithubPublisher implements PublisherBase { repo: name, permission: 'admin', }); - // no need to add access if it's the person who own's the personal account + // no need to add access if it's the person who owns the personal account } else if (access && access !== owner) { await client.repos.addCollaborator({ owner, From 3848bc1cfad06b7a97134a1ebb57d1e618895df2 Mon Sep 17 00:00:00 2001 From: Johan Haals Date: Wed, 10 Mar 2021 14:17:27 +0100 Subject: [PATCH 3/3] Throw error with status included Signed-off-by: Johan Haals --- .../src/scaffolder/stages/publish/github.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/plugins/scaffolder-backend/src/scaffolder/stages/publish/github.ts b/plugins/scaffolder-backend/src/scaffolder/stages/publish/github.ts index bc2537a766..d0bfc89529 100644 --- a/plugins/scaffolder-backend/src/scaffolder/stages/publish/github.ts +++ b/plugins/scaffolder-backend/src/scaffolder/stages/publish/github.ts @@ -151,8 +151,9 @@ export class GithubPublisher implements PublisherBase { }); } } catch (e) { - e.message = `Failed to add access to '${access}': ${e.message}`; - throw e; + throw new Error( + `Failed to add access to '${access}'. Status ${e.status} ${e.message}`, + ); } return data?.clone_url; }