@@ -111,13 +111,11 @@ def __init__(self, query, variables={}, headers={}):
111
111
self .headers = headers
112
112
113
113
def paginate (self , page_info , name ):
114
- has_page = (
115
- page_info ["hasNextPage" ] if name .startswith ("after" ) else page_info ["hasPreviousPage" ]
116
- )
114
+ has_page = page_info ["hasNextPage" if name .startswith ("after" ) else "hasPreviousPage" ]
117
115
if has_page :
118
- self .variables [name ] = (
119
- page_info [ "endCursor" ] if name .startswith ("after" ) else page_info [ "startCursor" ]
120
- )
116
+ self .variables [name ] = page_info [
117
+ "endCursor" if name .startswith ("after" ) else "startCursor"
118
+ ]
121
119
return has_page
122
120
123
121
def fetch (self ):
@@ -142,32 +140,30 @@ def set_output(name, value):
142
140
143
141
144
142
def get_commit_depth_and_check_suite (query_commits ):
143
+ commit_depth = 0
145
144
while True :
146
145
commits = query_commits .fetch ()["data" ]["repository" ]["pullRequest" ]["commits" ]
147
-
148
146
if commits ["totalCount" ] > 0 :
149
147
nodes = commits ["nodes" ]
150
148
nodes .reverse ()
151
149
if nodes [0 ]["commit" ]["oid" ] == os .environ ["EXCLUDE_COMMIT" ]:
152
150
nodes .pop (0 )
153
- for index , commit in enumerate (nodes ):
151
+ for commit in nodes :
152
+ commit_depth += 1
154
153
commit = commit ["commit" ]
155
154
commit_sha = commit ["oid" ]
156
155
check_suites = commit ["checkSuites" ]
157
156
if check_suites ["totalCount" ] > 0 :
158
157
for check_suite in check_suites ["nodes" ]:
159
158
if check_suite ["workflowRun" ]["workflow" ]["name" ] == "Build CI" :
160
159
return [
161
- {"sha" : commit_sha , "depth" : index + 1 },
160
+ {"sha" : commit_sha , "depth" : commit_depth },
162
161
check_suite ["id" ]
163
162
if check_suite ["conclusion" ] != "SUCCESS"
164
163
else None ,
165
164
]
166
- else :
167
- if not query_commits .paginate (commits ["pageInfo" ], "beforeCommit" ):
168
- break
169
-
170
- return [None , None ]
165
+ if not query_commits .paginate (commits ["pageInfo" ], "beforeCommit" ):
166
+ return [None , None ]
171
167
172
168
173
169
def append_runs_to_list (runs , bad_runs_by_matrix ):
@@ -188,9 +184,10 @@ def append_runs_to_list(runs, bad_runs_by_matrix):
188
184
def get_bad_check_runs (query_check_runs ):
189
185
more_pages = True
190
186
bad_runs_by_matrix = {}
187
+ run_types = ["failed" , "incomplete" ]
188
+
191
189
while more_pages :
192
190
check_runs = query_check_runs .fetch ()["data" ]["node" ]
193
- run_types = ["failed" , "incomplete" ]
194
191
more_pages = False
195
192
196
193
for run_type in run_types :
@@ -221,19 +218,19 @@ def main():
221
218
222
219
commit , check_suite = get_commit_depth_and_check_suite (query_commits )
223
220
224
- if check_suite is None :
225
- if commit is None :
226
- print ("Abort: No check suite found" )
227
- else :
221
+ if not check_suite :
222
+ if commit :
228
223
set_commit (commit )
224
+ else :
225
+ print ("Abort: No check suite found" )
229
226
quit ()
230
227
231
228
query_check_runs = Query (QUERY_CHECK_RUNS , query_variables_check_runs , headers )
232
229
query_check_runs .variables ["checkSuiteID" ] = check_suite
233
230
234
231
check_runs = get_bad_check_runs (query_check_runs )
235
232
236
- if len ( check_runs ) == 0 :
233
+ if not check_runs :
237
234
print ("Abort: No check runs found" )
238
235
quit ()
239
236
0 commit comments