Merge pull request #31052 from praphull-purohit/github-provider-block-creations
Add block creations field to github branch protection scaffolder action
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/plugin-scaffolder-backend-module-github': patch
|
||||
---
|
||||
|
||||
Add block creations field in github branch protection scaffolder actions
|
||||
@@ -81,6 +81,7 @@ export function createGithubBranchProtectionAction(options: {
|
||||
requireLastPushApproval?: boolean | undefined;
|
||||
requiredCommitSigning?: boolean | undefined;
|
||||
requiredLinearHistory?: boolean | undefined;
|
||||
blockCreations?: boolean | undefined;
|
||||
token?: string | undefined;
|
||||
},
|
||||
{
|
||||
|
||||
@@ -44,6 +44,7 @@ type BranchProtectionOptions = {
|
||||
dismissStaleReviews?: boolean;
|
||||
requiredCommitSigning?: boolean;
|
||||
requiredLinearHistory?: boolean;
|
||||
blockCreations?: boolean;
|
||||
};
|
||||
|
||||
export const enableBranchProtectionOnDefaultRepoBranch = async ({
|
||||
@@ -64,6 +65,7 @@ export const enableBranchProtectionOnDefaultRepoBranch = async ({
|
||||
dismissStaleReviews = false,
|
||||
requiredCommitSigning = false,
|
||||
requiredLinearHistory = false,
|
||||
blockCreations = false,
|
||||
}: BranchProtectionOptions): Promise<void> => {
|
||||
const tryOnce = async () => {
|
||||
try {
|
||||
@@ -96,6 +98,7 @@ export const enableBranchProtectionOnDefaultRepoBranch = async ({
|
||||
},
|
||||
required_conversation_resolution: requiredConversationResolution,
|
||||
required_linear_history: requiredLinearHistory,
|
||||
block_creations: blockCreations,
|
||||
});
|
||||
|
||||
if (requiredCommitSigning) {
|
||||
|
||||
+4
@@ -99,6 +99,7 @@ describe('github:branch-protection:create', () => {
|
||||
},
|
||||
required_conversation_resolution: false,
|
||||
required_linear_history: false,
|
||||
block_creations: false,
|
||||
});
|
||||
expect(
|
||||
mockOctokit.rest.repos.createCommitSignatureProtection,
|
||||
@@ -132,6 +133,7 @@ describe('github:branch-protection:create', () => {
|
||||
},
|
||||
required_conversation_resolution: false,
|
||||
required_linear_history: false,
|
||||
block_creations: false,
|
||||
});
|
||||
expect(
|
||||
mockOctokit.rest.repos.createCommitSignatureProtection,
|
||||
@@ -165,6 +167,7 @@ describe('github:branch-protection:create', () => {
|
||||
},
|
||||
required_conversation_resolution: true,
|
||||
required_linear_history: false,
|
||||
block_creations: false,
|
||||
});
|
||||
expect(
|
||||
mockOctokit.rest.repos.createCommitSignatureProtection,
|
||||
@@ -202,6 +205,7 @@ describe('github:branch-protection:create', () => {
|
||||
},
|
||||
required_conversation_resolution: true,
|
||||
required_linear_history: true,
|
||||
block_creations: false,
|
||||
});
|
||||
expect(
|
||||
mockOctokit.rest.repos.createCommitSignatureProtection,
|
||||
|
||||
@@ -105,6 +105,7 @@ describe('github:branch-protection:create', () => {
|
||||
},
|
||||
required_conversation_resolution: false,
|
||||
required_linear_history: false,
|
||||
block_creations: false,
|
||||
});
|
||||
expect(
|
||||
mockOctokit.rest.repos.createCommitSignatureProtection,
|
||||
@@ -142,6 +143,7 @@ describe('github:branch-protection:create', () => {
|
||||
},
|
||||
required_conversation_resolution: false,
|
||||
required_linear_history: false,
|
||||
block_creations: false,
|
||||
});
|
||||
expect(
|
||||
mockOctokit.rest.repos.createCommitSignatureProtection,
|
||||
@@ -178,6 +180,7 @@ describe('github:branch-protection:create', () => {
|
||||
requireLastPushApproval: true,
|
||||
requiredCommitSigning: true,
|
||||
requiredLinearHistory: true,
|
||||
blockCreations: true,
|
||||
},
|
||||
});
|
||||
|
||||
@@ -211,6 +214,7 @@ describe('github:branch-protection:create', () => {
|
||||
},
|
||||
required_conversation_resolution: true,
|
||||
required_linear_history: true,
|
||||
block_creations: true,
|
||||
});
|
||||
expect(
|
||||
mockOctokit.rest.repos.createCommitSignatureProtection,
|
||||
|
||||
@@ -57,6 +57,7 @@ export function createGithubBranchProtectionAction(options: {
|
||||
requireLastPushApproval: inputProps.requireLastPushApproval,
|
||||
requiredCommitSigning: inputProps.requiredCommitSigning,
|
||||
requiredLinearHistory: inputProps.requiredLinearHistory,
|
||||
blockCreations: inputProps.blockCreations,
|
||||
token: inputProps.token,
|
||||
},
|
||||
},
|
||||
@@ -76,6 +77,7 @@ export function createGithubBranchProtectionAction(options: {
|
||||
requireLastPushApproval = false,
|
||||
requiredCommitSigning = false,
|
||||
requiredLinearHistory = false,
|
||||
blockCreations,
|
||||
token: providedToken,
|
||||
} = ctx.input;
|
||||
|
||||
@@ -129,6 +131,7 @@ export function createGithubBranchProtectionAction(options: {
|
||||
dismissStaleReviews,
|
||||
requiredCommitSigning,
|
||||
requiredLinearHistory,
|
||||
blockCreations,
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
@@ -348,6 +348,14 @@ const requiredLinearHistory = (z: typeof zod) =>
|
||||
})
|
||||
.optional();
|
||||
|
||||
const blockCreations = (z: typeof zod) =>
|
||||
z
|
||||
.boolean({
|
||||
description: `Prevents creation of new branches during push, unless the push is initiated by a user, team, or app (defined in restrictions) which has the ability to push.`,
|
||||
})
|
||||
.default(false)
|
||||
.optional();
|
||||
|
||||
const repoVariables = (z: typeof zod) =>
|
||||
z
|
||||
.record(z.string(), {
|
||||
@@ -449,4 +457,5 @@ export {
|
||||
protectEnforceAdmins,
|
||||
bypassPullRequestAllowances,
|
||||
branch,
|
||||
blockCreations,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user