Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change: Allow to enable/disable branch protection in create repo github script #972

Merged
merged 1 commit into from
Jan 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading