Merge pull request #4889 from backstage/jhaals/better-error

scaffolder: Improve GitHub publishers permission update error message
This commit is contained in:
Johan Haals
2021-03-10 14:44:49 +01:00
committed by GitHub
2 changed files with 28 additions and 18 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/plugin-scaffolder-backend': patch
---
Update GitHub publisher to display a more helpful error message when repository access update fails.
@@ -131,25 +131,30 @@ 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 owns the personal account
} else if (access && access !== owner) {
await client.repos.addCollaborator({
owner,
repo: name,
username: access,
permission: 'admin',
});
}
} catch (e) {
throw new Error(
`Failed to add access to '${access}'. Status ${e.status} ${e.message}`,
);
}
return data?.clone_url;
}
}