@@ -172,48 +172,57 @@ fn get_checks_for_pr(pr_number int) []Check {
172172 return checks
173173}
174174
175+ struct GhCheckRun {
176+ name string
177+ status string
178+ conclusion string
179+ html_url string @[json: html_url]
180+ }
181+
182+ struct GhCheckRunsResponse {
183+ total_count int @[json: total_count]
184+ check_runs []GhCheckRun @[json: check_runs]
185+ }
186+
175187fn get_checks_for_commit (commit string ) []Check {
176188 mut checks := []Check{}
177189 println (c (tg, 'Fetching checks for ref ${c(tb, commit)} ...' ))
178- runs_res := execute_with_progress ('gh run list --commit ${commit} --limit 100 --json databaseId,workflowName' )
179- if runs_res.exit_code != 0 {
180- println ('Error fetching runs: ${runs_res.output} ' )
190+ // Fetch all check runs for this commit in one go
191+ cmd := 'gh api repos/:owner/:repo/commits/${commit} /check-runs?per_page=100'
192+ res := execute_with_progress (cmd)
193+ if res.exit_code != 0 {
194+ println ('Error fetching check runs: ${res.output} ' )
181195 exit (1 )
182196 }
183- runs := json.decode ([]GhRun, runs_res .output) or {
184- println ('Failed to decode runs JSON: ${err} ' )
197+ response := json.decode (GhCheckRunsResponse, res .output) or {
198+ println ('Failed to decode check runs JSON: ${err} ' )
185199 exit (1 )
186200 }
187- for run in runs {
188- view_res := execute_with_progress ('gh run view ${run.database_id} --json jobs,workflowName' )
189- if view_res.exit_code != 0 {
190- continue
201+ for cr in response.check_runs {
202+ mut bucket := 'pass'
203+ mut state := cr.conclusion.to_upper ()
204+ if state == '' {
205+ state = cr.status.to_upper ()
191206 }
192- view := json.decode (GhRunView, view_res.output) or { continue }
193- for job in view.jobs {
194- mut bucket := 'pass'
195- mut state := job.conclusion.to_upper ()
207+ if cr.conclusion == 'failure' {
208+ bucket = 'fail'
209+ } else if cr.conclusion == 'cancelled' {
210+ bucket = 'cancel'
211+ } else if cr.status in ['in_progress' , 'queued' , 'waiting' ] {
212+ bucket = 'pending'
196213 if state == '' {
197- state = job.status.to_upper ()
198- }
199- if job.conclusion == 'failure' {
200- bucket = 'fail'
201- } else if job.conclusion == 'cancelled' {
202- bucket = 'cancel'
203- } else if job.status in ['in_progress' , 'queued' , 'waiting' ] {
204- bucket = 'pending'
205- if state == '' {
206- state = 'PENDING'
207- }
208- }
209- checks << Check{
210- name: job.name
211- bucket: bucket
212- state: state
213- link: job.url
214- workflow: view.workflow_name
214+ state = 'PENDING'
215215 }
216216 }
217+ // The API doesn't directly give workflow name, but it's often in the name
218+ // or we can just use the job name for both if it's not available.
219+ checks << Check{
220+ name: cr.name
221+ bucket: bucket
222+ state: state
223+ link: cr.html_url
224+ workflow: 'Actions' // Default if unknown
225+ }
217226 }
218227 return checks
219228}
0 commit comments