Skip to content

Commit

Permalink
Merge pull request #224 from Silvia-Wachira/update_branch_protection
Browse files Browse the repository at this point in the history
Implement Exclusion of Exempt Users
  • Loading branch information
TimidRobot authored Oct 15, 2024
2 parents fbd4764 + f2bb29c commit 532203e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
23 changes: 21 additions & 2 deletions ccos/norm/branch_protections.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# Specify repositories that are excluded from branch protections.
#
# Format:
# # comment indicating reason for exclusion
# - REPOSITORY
EXEMPT_REPOSITORIES:
# special purpose repo
- australian-chapter
Expand All @@ -9,13 +14,27 @@ EXEMPT_REPOSITORIES:
- global-network-strategy
# special purpose repo
- network-platforms
# exempted for bot pushes to default branch
- quantifying
# special purpose repo
- sre-wiki-js
# special purpose repo
- tech-support

# Specify non-exempt repositories requiring specific status checks
#
# Format:
# REPOSITORY:
# - STATUS_CHECK_NAME
REQUIRED_STATUS_CHECK_MAP:
creativecommons.github.io-source:
- Build and Deploy CC Open Source

# Specify non-exempt repositories and the people, teams, or apps who are
# allowed to bypass required pull requests (PRs)
#
# Format:
# REPOSITORY:
# - GITHUB_USER_TEAM_OR_APP
# - GITHUB_USER_TEAM_OR_APP
EXEMPT_USERS:
quantifying:
- cc-quantifying-bot
8 changes: 6 additions & 2 deletions normalize_repos.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ def update_branch_protection(repo):
config = load_branch_protection_config()
exempt_repositories = config["EXEMPT_REPOSITORIES"]
required_status_check_map = config["REQUIRED_STATUS_CHECK_MAP"]

exempt_users = config.get("EXEMPT_USERS", {}).get(repo.name, [])

if repo.name not in exempt_repositories and is_engineering_project(repo):
LOG.info(f"{repo.name}: updating branch protections")
# The following empty *_bypass_pull_request_allowance arguments ensure
Expand All @@ -121,15 +124,15 @@ def update_branch_protection(repo):
required_approving_review_count=1,
user_push_restrictions=[],
contexts=required_status_check_map[repo.name],
users_bypass_pull_request_allowances=[],
users_bypass_pull_request_allowances=exempt_users,
teams_bypass_pull_request_allowances=[],
apps_bypass_pull_request_allowances=[],
)
else:
default_branch.edit_protection(
required_approving_review_count=1,
user_push_restrictions=[],
users_bypass_pull_request_allowances=[],
users_bypass_pull_request_allowances=exempt_users,
teams_bypass_pull_request_allowances=[],
apps_bypass_pull_request_allowances=[],
)
Expand All @@ -140,6 +143,7 @@ def update_branch_protection(repo):
def update_branches(args, repos):
if args.skip_branches:
return

LOG.info("Evaluting repositories for branch protections...")
for repo in repos:
update_branch_protection(repo)
Expand Down

0 comments on commit 532203e

Please sign in to comment.