@@ -58,11 +58,37 @@ def fetch_buildkite_data(build_url):
5858 file = sys .stderr ,
5959 )
6060 return None
61- return json .loads (response .read ().decode ())
61+ data = json .loads (response .read ().decode ())
6262 except Exception as e :
6363 print (f"Error fetching data from { json_url } : { e } " , file = sys .stderr )
6464 return None
6565
66+ # If jobs list is truncated or empty but statistics says there are more jobs,
67+ # try to fetch from /data/jobs.json
68+ jobs = data .get ("jobs" , [])
69+ jobs_count = data .get ("statistics" , {}).get ("jobs_count" , 0 )
70+
71+ if len (jobs ) < jobs_count :
72+ # Try fetching from /data/jobs.json
73+ # Build URL might have .json already from the check above
74+ base_url = build_url
75+ if base_url .endswith (".json" ):
76+ base_url = base_url [:- 5 ]
77+
78+ jobs_url = f"{ base_url } /data/jobs.json"
79+ try :
80+ with urllib .request .urlopen (jobs_url ) as response :
81+ if response .status == 200 :
82+ jobs_data = json .loads (response .read ().decode ())
83+ if isinstance (jobs_data , list ):
84+ data ["jobs" ] = jobs_data
85+ elif isinstance (jobs_data , dict ) and "records" in jobs_data :
86+ data ["jobs" ] = jobs_data ["records" ]
87+ except Exception as e :
88+ print (f"Warning: Could not fetch detailed jobs from { jobs_url } : { e } " , file = sys .stderr )
89+
90+ return data
91+
6692
6793def download_log (job_url , output_path ):
6894 # Construct raw log URL: job_url + "/raw" (Buildkite convention)
@@ -119,7 +145,11 @@ def main():
119145
120146 args = parser .parse_args ()
121147
122- print (f"Fetching checks for PR #{ args .pr_number } ..." , file = sys .stderr )
148+ pr_display = args .pr_number
149+ if "pull/" in pr_display :
150+ pr_display = pr_display .split ("pull/" )[1 ].split ("#" )[0 ].split ("/" )[0 ]
151+
152+ print (f"Fetching checks for PR #{ pr_display } ..." , file = sys .stderr )
123153 checks = get_pr_checks (args .pr_number )
124154
125155 build_url = get_buildkite_build_url (checks )
@@ -133,10 +163,19 @@ def main():
133163 if not data :
134164 sys .exit (1 )
135165
136- print ( f"Build State: { data .get (' state' ) } " )
137- print ("-" * 40 )
138-
166+ build_state = data .get (" state" , "Unknown " )
167+ print (f"Build State: { build_state } " )
168+
139169 jobs = data .get ("jobs" , [])
170+ jobs_count = data .get ("statistics" , {}).get ("jobs_count" , 0 )
171+
172+ print (f"Total jobs reported: { jobs_count } " )
173+ print (f"Jobs found in data: { len (jobs )} " )
174+
175+ if jobs_count != len (jobs ):
176+ print (f"WARNING: Reported job count ({ jobs_count } ) does not match jobs found ({ len (jobs )} )." , file = sys .stderr )
177+
178+ print ("-" * 40 )
140179
141180 filtered_jobs = []
142181 if args .jobs :
0 commit comments