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 {
39
39
}
40
40
"""
41
41
42
- QUERY_CHECKRUNS = """
42
+ QUERY_CHECK_RUNS = """
43
43
query ($checkSuiteID: ID!,
44
44
$afterFailedRun: String, $afterIncompleteRun: String,
45
45
$includeFailedRuns: Boolean!, $includeIncompleteRuns: Boolean!) {
92
92
}
93
93
94
94
95
- query_variables_checkruns = {
95
+ query_variables_check_runs = {
96
96
"checkSuiteID" : "" ,
97
97
"afterFailedRun" : None ,
98
98
"afterIncompleteRun" : None ,
@@ -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 ):
@@ -141,28 +139,31 @@ def set_output(name, value):
141
139
print (f"Would set GitHub actions output { name } to '{ value } '" )
142
140
143
141
144
- def get_commit_and_checksuite (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
- checksuites = commit ["checkSuites" ]
154
- if checksuites ["totalCount" ] > 0 :
155
- for checksuite in checksuites ["nodes" ]:
156
- if checksuite ["workflowRun" ]["workflow" ]["name" ] == "Build CI" :
157
- return [
158
- commit_sha ,
159
- checksuite ["id" ] if checksuite ["conclusion" ] != "SUCCESS" else None ,
160
- ]
161
- else :
162
- if query_commits .paginate (commits ["pageInfo" ], "beforeCommit" ):
163
- return get_commit_and_checksuite (query_commits )
164
-
165
- return [None , None ]
142
+ def get_commit_depth_and_check_suite (query_commits ):
143
+ commit_depth = 0
144
+ while True :
145
+ commits = query_commits .fetch ()["data" ]["repository" ]["pullRequest" ]["commits" ]
146
+ if commits ["totalCount" ] > 0 :
147
+ nodes = commits ["nodes" ]
148
+ nodes .reverse ()
149
+ if nodes [0 ]["commit" ]["oid" ] == os .environ ["EXCLUDE_COMMIT" ]:
150
+ nodes .pop (0 )
151
+ for commit in nodes :
152
+ commit_depth += 1
153
+ commit = commit ["commit" ]
154
+ commit_sha = commit ["oid" ]
155
+ check_suites = commit ["checkSuites" ]
156
+ if check_suites ["totalCount" ] > 0 :
157
+ for check_suite in check_suites ["nodes" ]:
158
+ if check_suite ["workflowRun" ]["workflow" ]["name" ] == "Build CI" :
159
+ return [
160
+ {"sha" : commit_sha , "depth" : commit_depth },
161
+ check_suite ["id" ]
162
+ if check_suite ["conclusion" ] != "SUCCESS"
163
+ else None ,
164
+ ]
165
+ if not query_commits .paginate (commits ["pageInfo" ], "beforeCommit" ):
166
+ return [None , None ]
166
167
167
168
168
169
def append_runs_to_list (runs , bad_runs_by_matrix ):
@@ -180,53 +181,61 @@ def append_runs_to_list(runs, bad_runs_by_matrix):
180
181
bad_runs_by_matrix [matrix ].append (res_board .group ()[1 :- 1 ])
181
182
182
183
183
- def get_bad_checkruns ( query_checkruns ):
184
+ def get_bad_check_runs ( query_check_runs ):
184
185
more_pages = True
185
186
bad_runs_by_matrix = {}
187
+ run_types = ["failed" , "incomplete" ]
188
+
186
189
while more_pages :
187
- checkruns = query_checkruns .fetch ()["data" ]["node" ]
188
- run_types = ["failed" , "incomplete" ]
190
+ check_runs = query_check_runs .fetch ()["data" ]["node" ]
189
191
more_pages = False
190
192
191
193
for run_type in run_types :
192
194
run_type_camel = run_type .capitalize () + "Run"
193
195
run_type = run_type + "Runs"
194
196
195
- append_runs_to_list (checkruns [run_type ], bad_runs_by_matrix )
197
+ append_runs_to_list (check_runs [run_type ], bad_runs_by_matrix )
196
198
197
- if query_checkruns .paginate (checkruns [run_type ]["pageInfo" ], "after" + run_type_camel ):
198
- query_checkruns .variables ["include" + run_type_camel ] = True
199
+ if query_check_runs .paginate (
200
+ check_runs [run_type ]["pageInfo" ], "after" + run_type_camel
201
+ ):
202
+ query_check_runs .variables ["include" + run_type_camel ] = True
199
203
more_pages = True
200
204
201
205
return bad_runs_by_matrix
202
206
203
207
208
+ def set_commit (commit ):
209
+ set_output ("commit_sha" , commit ["sha" ])
210
+ set_output ("commit_depth" , commit ["depth" ])
211
+
212
+
204
213
def main ():
205
214
query_commits = Query (QUERY_COMMITS , query_variables_commits , headers )
206
215
query_commits .variables ["owner" ], query_commits .variables ["name" ] = os .environ ["REPO" ].split (
207
216
"/"
208
217
)
209
218
210
- commit , checksuite = get_commit_and_checksuite (query_commits )
219
+ commit , check_suite = get_commit_depth_and_check_suite (query_commits )
211
220
212
- if checksuite is None :
213
- if commit is None :
214
- print ( "No checkSuites found -> Abort" )
221
+ if not check_suite :
222
+ if commit :
223
+ set_commit ( commit )
215
224
else :
216
- set_output ( "commit" , commit )
225
+ print ( "Abort: No check suite found" )
217
226
quit ()
218
227
219
- query_checkruns = Query (QUERY_CHECKRUNS , query_variables_checkruns , headers )
220
- query_checkruns .variables ["checkSuiteID" ] = checksuite
228
+ query_check_runs = Query (QUERY_CHECK_RUNS , query_variables_check_runs , headers )
229
+ query_check_runs .variables ["checkSuiteID" ] = check_suite
221
230
222
- checkruns = get_bad_checkruns ( query_checkruns )
231
+ check_runs = get_bad_check_runs ( query_check_runs )
223
232
224
- if len ( checkruns ) == 0 :
225
- print ("No checkRuns found -> Abort " )
233
+ if not check_runs :
234
+ print ("Abort: No check runs found " )
226
235
quit ()
227
236
228
- set_output ( "commit" , commit )
229
- set_output ("checkruns " , json .dumps (checkruns ))
237
+ set_commit ( commit )
238
+ set_output ("check_runs " , json .dumps (check_runs ))
230
239
231
240
232
241
if __name__ == "__main__" :
0 commit comments