18
18
}
19
19
nodes {
20
20
commit {
21
- checkSuites(first: 3 ) {
21
+ checkSuites(first: 100 ) {
22
22
nodes {
23
23
conclusion
24
24
workflowRun {
@@ -141,26 +141,29 @@ def set_output(name, value):
141
141
print (f"Would set GitHub actions output { name } to '{ value } '" )
142
142
143
143
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
164
167
165
168
return [None , None ]
166
169
@@ -201,19 +204,24 @@ def get_bad_check_runs(query_check_runs):
201
204
return bad_runs_by_matrix
202
205
203
206
207
+ def set_commit (commit ):
208
+ set_output ("commit_sha" , commit ["sha" ])
209
+ set_output ("commit_depth" , commit ["depth" ])
210
+
211
+
204
212
def main ():
205
213
query_commits = Query (QUERY_COMMITS , query_variables_commits , headers )
206
214
query_commits .variables ["owner" ], query_commits .variables ["name" ] = os .environ ["REPO" ].split (
207
215
"/"
208
216
)
209
217
210
- commit , check_suite = get_commit_and_check_suite (query_commits )
218
+ commit , check_suite = get_commit_depth_and_check_suite (query_commits )
211
219
212
220
if check_suite is None :
213
221
if commit is None :
214
222
print ("Abort: No check suite found" )
215
223
else :
216
- set_output ( "commit" , commit )
224
+ set_commit ( commit )
217
225
quit ()
218
226
219
227
query_check_runs = Query (QUERY_CHECK_RUNS , query_variables_check_runs , headers )
@@ -225,7 +233,7 @@ def main():
225
233
print ("Abort: No check runs found" )
226
234
quit ()
227
235
228
- set_output ( "commit" , commit )
236
+ set_commit ( commit )
229
237
set_output ("check_runs" , json .dumps (check_runs ))
230
238
231
239
0 commit comments