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 ("ccos/norm/branch_protections.yml" , "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,22 +107,20 @@ def update_branch_protection(repo):
102
107
return
103
108
else :
104
109
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 ):
109
114
LOG .info (f"{ repo .name } : updating branch protections" )
110
115
# The following empty *_bypass_pull_request_allowance arguments ensure
111
116
# the required bypass_pull_request_allowances API parameter is
112
117
# populated:
113
118
# 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 :
115
120
default_branch .edit_protection (
116
121
required_approving_review_count = 1 ,
117
122
user_push_restrictions = [],
118
- contexts = branch_protections .REQUIRED_STATUS_CHECK_MAP [
119
- repo .name
120
- ],
123
+ contexts = required_status_check_map [repo .name ],
121
124
users_bypass_pull_request_allowances = [],
122
125
teams_bypass_pull_request_allowances = [],
123
126
apps_bypass_pull_request_allowances = [],
0 commit comments