Skip to content

Commit

Permalink
Add: Script for checking the presence of branch protection
Browse files Browse the repository at this point in the history
This script is intended to support compliance checks for GitHub
repositories regarding requirements on branch protection.

Note that the current implementation only verifies whether branch
protection *exists at all* and does not verify individual branch
protection setting which may be required by compliance policies.
  • Loading branch information
wiegandm authored and greenbonebot committed Feb 2, 2024
1 parent b762595 commit 1544ce6
Showing 1 changed file with 30 additions and 0 deletions.
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

0 comments on commit 1544ce6

Please sign in to comment.