1
1
#!/usr/bin/env python3
2
2
3
- import sys
3
+ import argparse
4
4
import os
5
+ import sys
6
+
5
7
import yaml
6
- import argparse
7
8
from github import Github
8
9
10
+
9
11
def load_areas (filename : str ):
10
- with open (filename , "r" ) as f :
12
+ with open (filename ) as f :
11
13
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
+
13
18
14
19
def set_or_empty (d , key ):
15
20
return set (d .get (key , []) or [])
16
21
22
+
17
23
def check_github_access (usernames , repo_fullname , token ):
18
24
"""Check if each username has at least Triage access to the repo."""
19
25
gh = Github (token )
@@ -29,6 +35,7 @@ def check_github_access(usernames, repo_fullname, token):
29
35
missing_access .add (username )
30
36
return missing_access
31
37
38
+
32
39
def compare_areas (old , new , repo_fullname = None , token = None ):
33
40
old_areas = set (old .keys ())
34
41
new_areas = set (new .keys ())
@@ -144,6 +151,10 @@ def compare_areas(old, new, repo_fullname=None, token=None):
144
151
print (f" - { u } " )
145
152
if not missing_maint and not missing_collab :
146
153
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
+
147
158
148
159
def main ():
149
160
parser = argparse .ArgumentParser (
@@ -160,5 +171,6 @@ def main():
160
171
token = os .environ .get ("GITHUB_TOKEN" ) or args .token
161
172
compare_areas (old_areas , new_areas , repo_fullname = args .repo , token = token )
162
173
174
+
163
175
if __name__ == "__main__" :
164
- main ()
176
+ main ()
0 commit comments