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

Add: Script for checking the presence of branch protection #973

Merged
merged 1 commit into from
Feb 2, 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
30 changes: 30 additions & 0 deletions pontos/github/scripts/branchprotection-check.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# SPDX-FileCopyrightText: 2024 Greenbone AG
#
# SPDX-License-Identifier: GPL-3.0-or-later
#

from argparse import ArgumentParser, Namespace

from pontos.github.api import GitHubAsyncRESTApi


def add_script_arguments(parser: ArgumentParser) -> None:
parser.add_argument("repo")
parser.add_argument("branch")


async def github_script(api: GitHubAsyncRESTApi, args: Namespace) -> int:
# draft script for checking the branch protection
branch_protection = await api.branches.protection_rules(
args.repo, args.branch
)
if branch_protection:
print(
f"Branch protection enabled for the '{args.branch}' branch of the '{args.repo}' repository."
)
return 0
else:
print(
f"Branch protection NOT enabled for the '{args.branch}' branch of the '{args.repo}' repository."
)
return 1
Loading