Skip to content

Commit cf18dcf

Browse files
committed
Migrate branch protections configuration to YAML
1 parent e45c93e commit cf18dcf

File tree

2 files changed

+31
-4
lines changed

2 files changed

+31
-4
lines changed

ccos/norm/branch_protections.yml

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
EXEMPT_REPOSITORIES:
2+
# special purpose repo
3+
- australian-chapter
4+
# exempted for bot pushes to default branch
5+
- creativecommons.github.io-source
6+
# exempted for bot pushes to default branch
7+
- creativecommons.github.io
8+
# special purpose repo
9+
- global-network-strategy
10+
# special purpose repo
11+
- network-platforms
12+
# special purpose repo
13+
- sre-wiki-js
14+
# special purpose repo
15+
- tech-support
16+
17+
REQUIRED_STATUS_CHECK_MAP:
18+
creativecommons.github.io-source:
19+
- Build and Deploy CC Open Source

normalize_repos.py

+12-4
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
# First-party/Local
1818
import ccos.log
1919
from ccos import gh_utils
20-
from ccos.norm import branch_protections
2120
from ccos.norm.get_labels import get_labels, get_required_label_groups
2221
from ccos.norm.set_labels import set_labels
2322
from ccos.norm.validate_issues import validate_issues
@@ -93,6 +92,12 @@ def is_engineering_project(repo):
9392
return metadata.get("engineering_project", False)
9493

9594

95+
def load_branch_protection_config():
96+
with open('branch_protections.yaml', 'r') as file:
97+
config = yaml.safe_load(file)
98+
return config
99+
100+
96101
def update_branch_protection(repo):
97102
try:
98103
default_branch = repo.get_branch(repo.default_branch)
@@ -102,20 +107,23 @@ def update_branch_protection(repo):
102107
return
103108
else:
104109
raise
110+
config = load_branch_protection_config()
111+
exempt_repositories = config['EXEMPT_REPOSITORIES']
112+
required_status_check_map = config['REQUIRED_STATUS_CHECK_MAP']
105113
if (
106-
repo.name not in branch_protections.EXEMPT_REPOSITORIES
114+
repo.name not in exempt_repositories
107115
and is_engineering_project(repo)
108116
):
109117
LOG.info(f"{repo.name}: updating branch protections")
110118
# The following empty *_bypass_pull_request_allowance arguments ensure
111119
# the required bypass_pull_request_allowances API parameter is
112120
# populated:
113121
# https://docs.github.com/rest/branches/branch-protection#update-branch-protection
114-
if repo.name in branch_protections.REQUIRED_STATUS_CHECK_MAP:
122+
if repo.name in required_status_check_map:
115123
default_branch.edit_protection(
116124
required_approving_review_count=1,
117125
user_push_restrictions=[],
118-
contexts=branch_protections.REQUIRED_STATUS_CHECK_MAP[
126+
contexts=required_status_check_map[
119127
repo.name
120128
],
121129
users_bypass_pull_request_allowances=[],

0 commit comments

Comments
 (0)