From 2e57922dead255a7f6d90d6d47c5fb642ad836d1 Mon Sep 17 00:00:00 2001 From: Johan Haals Date: Tue, 9 Mar 2021 14:58:14 +0100 Subject: [PATCH] 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; } }