17
17
# First-party/Local
18
18
import ccos .log
19
19
from ccos import gh_utils
20
- from ccos .norm import branch_protections
21
20
from ccos .norm .get_labels import get_labels , get_required_label_groups
22
21
from ccos .norm .set_labels import set_labels
23
22
from ccos .norm .validate_issues import validate_issues
@@ -93,6 +92,12 @@ def is_engineering_project(repo):
93
92
return metadata .get ("engineering_project" , False )
94
93
95
94
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
+
96
101
def update_branch_protection (repo ):
97
102
try :
98
103
default_branch = repo .get_branch (repo .default_branch )
@@ -102,20 +107,23 @@ def update_branch_protection(repo):
102
107
return
103
108
else :
104
109
raise
110
+ config = load_branch_protection_config ()
111
+ exempt_repositories = config ['EXEMPT_REPOSITORIES' ]
112
+ required_status_check_map = config ['REQUIRED_STATUS_CHECK_MAP' ]
105
113
if (
106
- repo .name not in branch_protections . EXEMPT_REPOSITORIES
114
+ repo .name not in exempt_repositories
107
115
and is_engineering_project (repo )
108
116
):
109
117
LOG .info (f"{ repo .name } : updating branch protections" )
110
118
# The following empty *_bypass_pull_request_allowance arguments ensure
111
119
# the required bypass_pull_request_allowances API parameter is
112
120
# populated:
113
121
# 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 :
115
123
default_branch .edit_protection (
116
124
required_approving_review_count = 1 ,
117
125
user_push_restrictions = [],
118
- contexts = branch_protections . REQUIRED_STATUS_CHECK_MAP [
126
+ contexts = required_status_check_map [
119
127
repo .name
120
128
],
121
129
users_bypass_pull_request_allowances = [],
0 commit comments