feat: add option to not protect the default branch
Signed-off-by: Leonardo Dagnino <leodag.sch@gmail.com>
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/plugin-scaffolder-backend': minor
|
||||
---
|
||||
|
||||
Add an option to not protect the default branch.
|
||||
@@ -727,4 +727,26 @@ describe('publish:github', () => {
|
||||
requiredStatusCheckContexts: [],
|
||||
});
|
||||
});
|
||||
|
||||
it('should not call enableBranchProtectionOnDefaultRepoBranch with protectDefaultBranch disabled', async () => {
|
||||
mockOctokit.rest.users.getByUsername.mockResolvedValue({
|
||||
data: { type: 'User' },
|
||||
});
|
||||
|
||||
mockOctokit.rest.repos.createForAuthenticatedUser.mockResolvedValue({
|
||||
data: {
|
||||
name: 'repository',
|
||||
},
|
||||
});
|
||||
|
||||
await action.handler({
|
||||
...mockContext,
|
||||
input: {
|
||||
...mockContext.input,
|
||||
protectDefaultBranch: false,
|
||||
},
|
||||
});
|
||||
|
||||
expect(enableBranchProtectionOnDefaultRepoBranch).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -46,6 +46,7 @@ export function createPublishGithubAction(options: {
|
||||
description?: string;
|
||||
access?: string;
|
||||
defaultBranch?: string;
|
||||
protectDefaultBranch?: boolean;
|
||||
deleteBranchOnMerge?: boolean;
|
||||
gitCommitMessage?: string;
|
||||
gitAuthorName?: string;
|
||||
@@ -111,6 +112,11 @@ export function createPublishGithubAction(options: {
|
||||
type: 'string',
|
||||
description: `Sets the default branch on the repository. The default value is 'master'`,
|
||||
},
|
||||
protectDefaultBranch: {
|
||||
title: 'Protect Default Branch',
|
||||
type: 'boolean',
|
||||
description: `Protect the default branch after creating the repository. The default value is 'true'`,
|
||||
},
|
||||
deleteBranchOnMerge: {
|
||||
title: 'Delete Branch On Merge',
|
||||
type: 'boolean',
|
||||
@@ -209,6 +215,7 @@ export function createPublishGithubAction(options: {
|
||||
requiredStatusCheckContexts = [],
|
||||
repoVisibility = 'private',
|
||||
defaultBranch = 'master',
|
||||
protectDefaultBranch = true,
|
||||
deleteBranchOnMerge = false,
|
||||
gitCommitMessage = 'initial commit',
|
||||
gitAuthorName,
|
||||
@@ -360,21 +367,23 @@ export function createPublishGithubAction(options: {
|
||||
gitAuthorInfo,
|
||||
});
|
||||
|
||||
try {
|
||||
await enableBranchProtectionOnDefaultRepoBranch({
|
||||
owner,
|
||||
client,
|
||||
repoName: newRepo.name,
|
||||
logger: ctx.logger,
|
||||
defaultBranch,
|
||||
requireCodeOwnerReviews,
|
||||
requiredStatusCheckContexts,
|
||||
});
|
||||
} catch (e) {
|
||||
assertError(e);
|
||||
ctx.logger.warn(
|
||||
`Skipping: default branch protection on '${newRepo.name}', ${e.message}`,
|
||||
);
|
||||
if (protectDefaultBranch) {
|
||||
try {
|
||||
await enableBranchProtectionOnDefaultRepoBranch({
|
||||
owner,
|
||||
client,
|
||||
repoName: newRepo.name,
|
||||
logger: ctx.logger,
|
||||
defaultBranch,
|
||||
requireCodeOwnerReviews,
|
||||
requiredStatusCheckContexts,
|
||||
});
|
||||
} catch (e) {
|
||||
assertError(e);
|
||||
ctx.logger.warn(
|
||||
`Skipping: default branch protection on '${newRepo.name}', ${e.message}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
ctx.output('remoteUrl', remoteUrl);
|
||||
|
||||
Reference in New Issue
Block a user