29
29
def run_gh_rest_check (
30
30
lib_repo : Repository ,
31
31
user : Optional [str ] = None ,
32
+ branch : Optional [str ] = "main" ,
32
33
workflow_filename : Optional [str ] = "build.yml" ,
33
34
) -> str :
34
35
"""Uses ``PyGithub`` to check the CI status of a repository
35
36
36
37
:param Repository lib_repo: The repo as a github.Repository.Repository object
37
38
:param str|None user: The user that triggered the run; if `None` is
38
39
provided, any user is acceptable
40
+ :param str|None branch: The branch name to specifically check; if `None` is
41
+ provided, all branches are allowed; the default is ``"main"``
39
42
:param str|None workflow_filename: The filename of the workflow; if `None` is
40
- provided, any workflow name is acceptable; the default is `"build.yml"`
43
+ provided, any workflow name is acceptable; the default is `` "build.yml"` `
41
44
:return: The requested runs conclusion
42
45
:rtype: str
43
46
"""
44
47
45
48
arg_dict = {}
46
49
if user is not None :
47
50
arg_dict ["actor" ] = user
51
+ if branch is not None :
52
+ arg_dict ["branch" ] = branch
48
53
49
54
workflow : Workflow = lib_repo .get_workflow (workflow_filename )
50
55
workflow_runs = workflow .get_runs (** arg_dict )
@@ -54,6 +59,7 @@ def run_gh_rest_check(
54
59
def check_build_status (
55
60
lib_repo : Repository ,
56
61
user : Optional [str ] = None ,
62
+ branch : Optional [str ] = "main" ,
57
63
workflow_filename : Optional [str ] = "build.yml" ,
58
64
debug : bool = False ,
59
65
) -> Optional [str ]:
@@ -63,6 +69,8 @@ def check_build_status(
63
69
:param Repository lib_repo: The repo as a github.Repository.Repository object
64
70
:param str|None user: The user that triggered the run; if `None` is
65
71
provided, any user is acceptable
72
+ :param str|None branch: The branch name to specifically check; if `None` is
73
+ provided, all branches are allowed; the default is ``"main"``
66
74
:param str|None workflow_filename: The filename of the workflow; if `None`
67
75
is provided, any workflow name is acceptable; the defail is `"build.yml"`
68
76
:param bool debug: Whether debug statements should be printed to the standard
@@ -79,7 +87,9 @@ def check_build_status(
79
87
return True
80
88
81
89
try :
82
- result = run_gh_rest_check (lib_repo , user , workflow_filename ) == "success"
90
+ result = (
91
+ run_gh_rest_check (lib_repo , user , branch , workflow_filename ) == "success"
92
+ )
83
93
if debug and not result :
84
94
print ("***" , "Library" , lib_repo .name , "failed the patch!" , "***" )
85
95
return result
@@ -98,6 +108,7 @@ def check_build_status(
98
108
def check_build_statuses (
99
109
gh_token : str ,
100
110
user : Optional [str ] = None ,
111
+ branch : Optional [str ] = "main" ,
101
112
workflow_filename : Optional [str ] = "build.yml" ,
102
113
* ,
103
114
debug : bool = False ,
@@ -108,6 +119,8 @@ def check_build_statuses(
108
119
:param str gh_token: The Github token to be used for with the Github API
109
120
:param str|None user: The user that triggered the run; if `None` is
110
121
provided, any user is acceptable
122
+ :param str|None branch: The branch name to specifically check; if `None` is
123
+ provided, all branches are allowed; the default is ``"main"``
111
124
:param str|None workflow_filename: The filename of the workflow; if `None` is
112
125
provided, any workflow name is acceptable; the defail is `"build.yml"`
113
126
:param bool debug: Whether debug statements should be printed to
@@ -118,7 +131,8 @@ def check_build_statuses(
118
131
"""
119
132
120
133
return iter_remote_bundle_with_func (
121
- gh_token , [(check_build_status , (user , workflow_filename ), {"debug" : debug })]
134
+ gh_token ,
135
+ [(check_build_status , (user , branch , workflow_filename ), {"debug" : debug })],
122
136
)
123
137
124
138
@@ -160,6 +174,14 @@ def save_build_statuses(
160
174
default = None ,
161
175
help = "Select a specific user that triggered the workflow" ,
162
176
)
177
+ parser .add_argument (
178
+ "--branch" ,
179
+ metavar = "B" ,
180
+ type = str ,
181
+ dest = "branch" ,
182
+ default = "main" ,
183
+ help = 'Branch name; default is "main"' ,
184
+ )
163
185
parser .add_argument (
164
186
"--workflow" ,
165
187
metavar = "W" ,
@@ -175,7 +197,7 @@ def save_build_statuses(
175
197
args = parser .parse_args ()
176
198
177
199
results = check_build_statuses (
178
- args .gh_token , args .user , args .workflow , debug = args .debug
200
+ args .gh_token , args .user , args .branch , args . workflow , debug = args .debug
179
201
)
180
202
fail_list = [
181
203
repo_name .name for repo_name , repo_results in results if not repo_results [0 ]
0 commit comments