Skip to content

Commit 532203e

Browse files
authored
Merge pull request #224 from Silvia-Wachira/update_branch_protection
Implement Exclusion of Exempt Users
2 parents fbd4764 + f2bb29c commit 532203e

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

ccos/norm/branch_protections.yml

+21-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# Specify repositories that are excluded from branch protections.
2+
#
3+
# Format:
4+
# # comment indicating reason for exclusion
5+
# - REPOSITORY
16
EXEMPT_REPOSITORIES:
27
# special purpose repo
38
- australian-chapter
@@ -9,13 +14,27 @@ EXEMPT_REPOSITORIES:
914
- global-network-strategy
1015
# special purpose repo
1116
- network-platforms
12-
# exempted for bot pushes to default branch
13-
- quantifying
1417
# special purpose repo
1518
- sre-wiki-js
1619
# special purpose repo
1720
- tech-support
1821

22+
# Specify non-exempt repositories requiring specific status checks
23+
#
24+
# Format:
25+
# REPOSITORY:
26+
# - STATUS_CHECK_NAME
1927
REQUIRED_STATUS_CHECK_MAP:
2028
creativecommons.github.io-source:
2129
- Build and Deploy CC Open Source
30+
31+
# Specify non-exempt repositories and the people, teams, or apps who are
32+
# allowed to bypass required pull requests (PRs)
33+
#
34+
# Format:
35+
# REPOSITORY:
36+
# - GITHUB_USER_TEAM_OR_APP
37+
# - GITHUB_USER_TEAM_OR_APP
38+
EXEMPT_USERS:
39+
quantifying:
40+
- cc-quantifying-bot

normalize_repos.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,9 @@ def update_branch_protection(repo):
110110
config = load_branch_protection_config()
111111
exempt_repositories = config["EXEMPT_REPOSITORIES"]
112112
required_status_check_map = config["REQUIRED_STATUS_CHECK_MAP"]
113+
114+
exempt_users = config.get("EXEMPT_USERS", {}).get(repo.name, [])
115+
113116
if repo.name not in exempt_repositories and is_engineering_project(repo):
114117
LOG.info(f"{repo.name}: updating branch protections")
115118
# The following empty *_bypass_pull_request_allowance arguments ensure
@@ -121,15 +124,15 @@ def update_branch_protection(repo):
121124
required_approving_review_count=1,
122125
user_push_restrictions=[],
123126
contexts=required_status_check_map[repo.name],
124-
users_bypass_pull_request_allowances=[],
127+
users_bypass_pull_request_allowances=exempt_users,
125128
teams_bypass_pull_request_allowances=[],
126129
apps_bypass_pull_request_allowances=[],
127130
)
128131
else:
129132
default_branch.edit_protection(
130133
required_approving_review_count=1,
131134
user_push_restrictions=[],
132-
users_bypass_pull_request_allowances=[],
135+
users_bypass_pull_request_allowances=exempt_users,
133136
teams_bypass_pull_request_allowances=[],
134137
apps_bypass_pull_request_allowances=[],
135138
)
@@ -140,6 +143,7 @@ def update_branch_protection(repo):
140143
def update_branches(args, repos):
141144
if args.skip_branches:
142145
return
146+
143147
LOG.info("Evaluting repositories for branch protections...")
144148
for repo in repos:
145149
update_branch_protection(repo)

0 commit comments

Comments
 (0)