11#!/usr/bin/env python3
22
3- import sys
3+ import argparse
44import os
5+ import sys
6+
57import yaml
6- import argparse
78from github import Github
89
10+
911def load_areas (filename : str ):
10- with open (filename , "r" ) as f :
12+ with open (filename ) as f :
1113 doc = yaml .safe_load (f )
12- return {k : v for k , v in doc .items () if isinstance (v , dict ) and ("files" in v or "files-regex" in v )}
14+ return {
15+ k : v for k , v in doc .items () if isinstance (v , dict ) and ("files" in v or "files-regex" in v )
16+ }
17+
1318
1419def set_or_empty (d , key ):
1520 return set (d .get (key , []) or [])
1621
22+
1723def check_github_access (usernames , repo_fullname , token ):
1824 """Check if each username has at least Triage access to the repo."""
1925 gh = Github (token )
@@ -29,6 +35,7 @@ def check_github_access(usernames, repo_fullname, token):
2935 missing_access .add (username )
3036 return missing_access
3137
38+
3239def compare_areas (old , new , repo_fullname = None , token = None ):
3340 old_areas = set (old .keys ())
3441 new_areas = set (new .keys ())
@@ -144,6 +151,10 @@ def compare_areas(old, new, repo_fullname=None, token=None):
144151 print (f" - { u } " )
145152 if not missing_maint and not missing_collab :
146153 print ("All added maintainers and collaborators have at least triage access." )
154+ else :
155+ print ("Some added maintainers or collaborators do not have sufficient access." )
156+ sys .exit (1 )
157+
147158
148159def main ():
149160 parser = argparse .ArgumentParser (
@@ -160,5 +171,6 @@ def main():
160171 token = os .environ .get ("GITHUB_TOKEN" ) or args .token
161172 compare_areas (old_areas , new_areas , repo_fullname = args .repo , token = token )
162173
174+
163175if __name__ == "__main__" :
164- main ()
176+ main ()
0 commit comments