Merge pull request #5750 from backstage/blam/fail-branch-protection
fix(scaffolder): added some logging if we can't enable branch protection for free repos
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/plugin-scaffolder-backend': patch
|
||||
---
|
||||
|
||||
Instead of failing, warn when you need to pay for GitHub Pro.
|
||||
@@ -233,6 +233,7 @@ export function createPublishGithubAction(options: {
|
||||
owner,
|
||||
client,
|
||||
repoName: newRepo.name,
|
||||
logger: ctx.logger,
|
||||
});
|
||||
} catch (e) {
|
||||
throw new Error(
|
||||
|
||||
@@ -109,6 +109,7 @@ export class GithubPublisher implements PublisherBase {
|
||||
owner,
|
||||
client,
|
||||
repoName: name,
|
||||
logger,
|
||||
});
|
||||
} catch (e) {
|
||||
throw new Error(`Failed to add branch protection to '${name}', ${e}`);
|
||||
|
||||
@@ -73,33 +73,49 @@ type BranchProtectionOptions = {
|
||||
client: Octokit;
|
||||
owner: string;
|
||||
repoName: string;
|
||||
logger: Logger;
|
||||
};
|
||||
|
||||
export const enableBranchProtectionOnDefaultRepoBranch = async ({
|
||||
repoName,
|
||||
client,
|
||||
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 {
|
||||
|
||||
Reference in New Issue
Block a user