Made "github:branch-protection:create" action idempotent

Signed-off-by: Bogdan Nechyporenko <bnechyporenko@bol.com>
This commit is contained in:
Bogdan Nechyporenko
2025-03-18 20:20:43 +01:00
parent 403bb43d3d
commit 180ea6eae4
2 changed files with 37 additions and 21 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/plugin-scaffolder-backend-module-github': patch
---
Made "github:branch-protection:create" action idempotent
@@ -130,29 +130,40 @@ export function createGithubBranchProtectionAction(options: {
});
const client = new Octokit(octokitOptions);
const repository = await client.rest.repos.get({
owner: owner,
repo: repo,
const defaultBranch = await ctx.checkpoint({
key: `read.default.branch.${owner}.${repo}`,
fn: async () => {
const repository = await client.rest.repos.get({
owner: owner,
repo: repo,
});
return repository.data.default_branch;
},
});
await enableBranchProtectionOnDefaultRepoBranch({
repoName: repo,
client,
owner,
logger: ctx.logger,
requireCodeOwnerReviews,
bypassPullRequestAllowances,
requiredApprovingReviewCount,
restrictions,
requiredStatusCheckContexts,
requireBranchesToBeUpToDate,
requiredConversationResolution,
requireLastPushApproval,
defaultBranch: branch ?? repository.data.default_branch,
enforceAdmins,
dismissStaleReviews,
requiredCommitSigning,
requiredLinearHistory,
await ctx.checkpoint({
key: `enable.branch.protection.${owner}.${repo}`,
fn: async () => {
await enableBranchProtectionOnDefaultRepoBranch({
repoName: repo,
client,
owner,
logger: ctx.logger,
requireCodeOwnerReviews,
bypassPullRequestAllowances,
requiredApprovingReviewCount,
restrictions,
requiredStatusCheckContexts,
requireBranchesToBeUpToDate,
requiredConversationResolution,
requireLastPushApproval,
defaultBranch: branch ?? defaultBranch,
enforceAdmins,
dismissStaleReviews,
requiredCommitSigning,
requiredLinearHistory,
});
},
});
},
});