chore: reworking the logic

Signed-off-by: blam <ben@blam.sh>
This commit is contained in:
blam
2021-05-20 15:49:21 +02:00
parent 5fc87a693c
commit 021eb366a8
2 changed files with 39 additions and 31 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/plugin-scaffolder-backend': patch
---
Instead of failing, warn when you need to pay for GitHub Pro.
@@ -82,42 +82,45 @@ export const enableBranchProtectionOnDefaultRepoBranch = async ({
owner,
logger,
}: BranchProtectionOptions): Promise<void> => {
const tryOnce = () => {
return client.repos.updateBranchProtection({
mediaType: {
/**
* 👇 we need this preview because allowing a custom
* reviewer count on branch protection is a preview
* feature
*
* More here: https://docs.github.com/en/rest/overview/api-previews#require-multiple-approving-reviews
*/
previews: ['luke-cage-preview'],
},
owner,
repo: repoName,
branch: 'master',
required_status_checks: { strict: true, contexts: [] },
restrictions: null,
enforce_admins: true,
required_pull_request_reviews: { required_approving_review_count: 1 },
});
const tryOnce = async () => {
try {
await client.repos.updateBranchProtection({
mediaType: {
/**
* 👇 we need this preview because allowing a custom
* reviewer count on branch protection is a preview
* feature
*
* More here: https://docs.github.com/en/rest/overview/api-previews#require-multiple-approving-reviews
*/
previews: ['luke-cage-preview'],
},
owner,
repo: repoName,
branch: 'master',
required_status_checks: { strict: true, contexts: [] },
restrictions: null,
enforce_admins: true,
required_pull_request_reviews: { required_approving_review_count: 1 },
});
} catch (e) {
if (
e.message.includes(
'Upgrade to GitHub Pro or make this repository public to enable this feature',
)
) {
logger.warn(
'Branch protection was not enabled as it requires GitHub Pro for private repositories',
);
} else {
throw e;
}
}
};
try {
await tryOnce();
} catch (e) {
if (
e.message.includes(
'Upgrade to GitHub Pro or make this repository public to enable this feature',
)
) {
logger.warn(
'Branch protection was not enabled as it requires GitHub Pro for private repositories',
);
return;
}
if (!e.message.includes('Branch not found')) {
throw e;
}