Skip to content

Commit

Permalink
Change: Allow to enable/disable branch protection in create repo gith…
Browse files Browse the repository at this point in the history
…ub script

Make branch protection optional while creating a new repository.
  • Loading branch information
bjoernricks authored and greenbonebot committed Jan 30, 2024
1 parent c483e14 commit 88dacbf
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion pontos/github/scripts/create-repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"""

import shutil
from argparse import ArgumentParser, Namespace
from argparse import ArgumentParser, BooleanOptionalAction, Namespace
from typing import Union

from pontos.git import Git, MergeStrategy
Expand Down Expand Up @@ -67,6 +67,13 @@ def add_script_arguments(parser: ArgumentParser) -> None:
help="Visibility of the repository. Default: %(default)s.",
)
parser.add_argument("--description", help="Description of the repository.")
parser.add_argument(
"--branch-protection",
action=BooleanOptionalAction,
default=True,
help="Enable/Disable branch protection for the main branch. Default is "
"enabled.",
)
parser.add_argument("name", help="Repository to create.")
parser.add_argument(
"organization",
Expand All @@ -83,6 +90,7 @@ async def github_script(api: GitHubAsyncRESTApi, args: Namespace) -> int:
gitignore_template = GITIGNORE.get(args.template)
license_template = args.license
description = args.description
branch_protection = args.branch_protection

if args.team:
team = await api.teams.get(organization, args.team)
Expand Down Expand Up @@ -154,6 +162,7 @@ async def github_script(api: GitHubAsyncRESTApi, args: Namespace) -> int:

git.push(remote="upstream", force=True)

if branch_protection:
await api.branches.update_protection_rules(
f"{organization}/{repository}",
"main",
Expand Down

0 comments on commit 88dacbf

Please sign in to comment.