Skip to content

Commit fbd4764

Browse files
authored
Merge pull request #222 from empty-codes/Feature-Improve-branch-protections
Migrate branch protections configuration to YAML
2 parents 6984e99 + 74c4b79 commit fbd4764

File tree

3 files changed

+33
-31
lines changed

3 files changed

+33
-31
lines changed

ccos/norm/branch_protections.py

-22
This file was deleted.

ccos/norm/branch_protections.yml

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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+
# exempted for bot pushes to default branch
13+
- quantifying
14+
# special purpose repo
15+
- sre-wiki-js
16+
# special purpose repo
17+
- tech-support
18+
19+
REQUIRED_STATUS_CHECK_MAP:
20+
creativecommons.github.io-source:
21+
- Build and Deploy CC Open Source

normalize_repos.py

+12-9
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("ccos/norm/branch_protections.yml", "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,22 +107,20 @@ def update_branch_protection(repo):
102107
return
103108
else:
104109
raise
105-
if (
106-
repo.name not in branch_protections.EXEMPT_REPOSITORIES
107-
and is_engineering_project(repo)
108-
):
110+
config = load_branch_protection_config()
111+
exempt_repositories = config["EXEMPT_REPOSITORIES"]
112+
required_status_check_map = config["REQUIRED_STATUS_CHECK_MAP"]
113+
if repo.name not in exempt_repositories and is_engineering_project(repo):
109114
LOG.info(f"{repo.name}: updating branch protections")
110115
# The following empty *_bypass_pull_request_allowance arguments ensure
111116
# the required bypass_pull_request_allowances API parameter is
112117
# populated:
113118
# https://docs.github.com/rest/branches/branch-protection#update-branch-protection
114-
if repo.name in branch_protections.REQUIRED_STATUS_CHECK_MAP:
119+
if repo.name in required_status_check_map:
115120
default_branch.edit_protection(
116121
required_approving_review_count=1,
117122
user_push_restrictions=[],
118-
contexts=branch_protections.REQUIRED_STATUS_CHECK_MAP[
119-
repo.name
120-
],
123+
contexts=required_status_check_map[repo.name],
121124
users_bypass_pull_request_allowances=[],
122125
teams_bypass_pull_request_allowances=[],
123126
apps_bypass_pull_request_allowances=[],

0 commit comments

Comments
 (0)