1818 }
1919 nodes {
2020 commit {
21- checkSuites(first: 3 ) {
21+ checkSuites(first: 100 ) {
2222 nodes {
2323 conclusion
2424 workflowRun {
@@ -141,26 +141,29 @@ def set_output(name, value):
141141 print (f"Would set GitHub actions output { name } to '{ value } '" )
142142
143143
144- def get_commit_and_check_suite (query_commits ):
145- commits = query_commits .fetch ()["data" ]["repository" ]["pullRequest" ]["commits" ]
146-
147- if commits ["totalCount" ] > 0 :
148- for commit in reversed (commits ["nodes" ]):
149- commit = commit ["commit" ]
150- commit_sha = commit ["oid" ]
151- if commit_sha == os .environ ["EXCLUDE_COMMIT" ]:
152- continue
153- check_suites = commit ["checkSuites" ]
154- if check_suites ["totalCount" ] > 0 :
155- for check_suite in check_suites ["nodes" ]:
156- if check_suite ["workflowRun" ]["workflow" ]["name" ] == "Build CI" :
157- return [
158- commit_sha ,
159- check_suite ["id" ] if check_suite ["conclusion" ] != "SUCCESS" else None ,
160- ]
161- else :
162- if query_commits .paginate (commits ["pageInfo" ], "beforeCommit" ):
163- return get_commit_and_check_suite (query_commits )
144+ def get_commit_depth_and_check_suite (query_commits ):
145+ while True :
146+ commits = query_commits .fetch ()["data" ]["repository" ]["pullRequest" ]["commits" ]
147+
148+ if commits ["totalCount" ] > 0 :
149+ nodes = commits ["nodes" ]
150+ nodes .reverse ()
151+ if nodes [0 ]["commit" ]["oid" ] == os .environ ["EXCLUDE_COMMIT" ]:
152+ nodes .pop (0 )
153+ for index , commit in enumerate (nodes ):
154+ commit = commit ["commit" ]
155+ commit_sha = commit ["oid" ]
156+ check_suites = commit ["checkSuites" ]
157+ if check_suites ["totalCount" ] > 0 :
158+ for check_suite in check_suites ["nodes" ]:
159+ if check_suite ["workflowRun" ]["workflow" ]["name" ] == "Build CI" :
160+ return [
161+ {"sha" : commit_sha , "depth" : index + 1 },
162+ check_suite ["id" ] if check_suite ["conclusion" ] != "SUCCESS" else None ,
163+ ]
164+ else :
165+ if not query_commits .paginate (commits ["pageInfo" ], "beforeCommit" ):
166+ break
164167
165168 return [None , None ]
166169
@@ -201,19 +204,24 @@ def get_bad_check_runs(query_check_runs):
201204 return bad_runs_by_matrix
202205
203206
207+ def set_commit (commit ):
208+ set_output ("commit_sha" , commit ["sha" ])
209+ set_output ("commit_depth" , commit ["depth" ])
210+
211+
204212def main ():
205213 query_commits = Query (QUERY_COMMITS , query_variables_commits , headers )
206214 query_commits .variables ["owner" ], query_commits .variables ["name" ] = os .environ ["REPO" ].split (
207215 "/"
208216 )
209217
210- commit , check_suite = get_commit_and_check_suite (query_commits )
218+ commit , check_suite = get_commit_depth_and_check_suite (query_commits )
211219
212220 if check_suite is None :
213221 if commit is None :
214222 print ("Abort: No check suite found" )
215223 else :
216- set_output ( "commit" , commit )
224+ set_commit ( commit )
217225 quit ()
218226
219227 query_check_runs = Query (QUERY_CHECK_RUNS , query_variables_check_runs , headers )
@@ -225,7 +233,7 @@ def main():
225233 print ("Abort: No check runs found" )
226234 quit ()
227235
228- set_output ( "commit" , commit )
236+ set_commit ( commit )
229237 set_output ("check_runs" , json .dumps (check_runs ))
230238
231239
0 commit comments