Skip to content

Commit c97d31b

Browse files
committed
chore: make buildkite-get-results skill work with large job numbers
1 parent d7ae199 commit c97d31b

File tree

1 file changed

+43
-5
lines changed

1 file changed

+43
-5
lines changed

.agents/skills/buildkite-get-results/scripts/get_buildkite_results.py

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,36 @@ 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 is empty but statistics says there are jobs, try to fetch from /data/jobs.json
67+
jobs = data.get("jobs", [])
68+
jobs_count = data.get("statistics", {}).get("jobs_count", 0)
69+
70+
if not jobs and jobs_count > 0:
71+
# Try fetching from /data/jobs.json
72+
# Build URL might have .json already from the check above
73+
base_url = build_url
74+
if base_url.endswith(".json"):
75+
base_url = base_url[:-5]
76+
77+
jobs_url = f"{base_url}/data/jobs.json"
78+
try:
79+
with urllib.request.urlopen(jobs_url) as response:
80+
if response.status == 200:
81+
jobs_data = json.loads(response.read().decode())
82+
if isinstance(jobs_data, dict) and "records" in jobs_data:
83+
data["jobs"] = jobs_data["records"]
84+
elif isinstance(jobs_data, list):
85+
data["jobs"] = jobs_data
86+
except Exception as e:
87+
print(f"Warning: Could not fetch detailed jobs from {jobs_url}: {e}", file=sys.stderr)
88+
89+
return data
90+
6691

6792
def download_log(job_url, output_path):
6893
# Construct raw log URL: job_url + "/raw" (Buildkite convention)
@@ -119,7 +144,11 @@ def main():
119144

120145
args = parser.parse_args()
121146

122-
print(f"Fetching checks for PR #{args.pr_number}...", file=sys.stderr)
147+
pr_display = args.pr_number
148+
if "pull/" in pr_display:
149+
pr_display = pr_display.split("pull/")[1].split("#")[0].split("/")[0]
150+
151+
print(f"Fetching checks for PR #{pr_display}...", file=sys.stderr)
123152
checks = get_pr_checks(args.pr_number)
124153

125154
build_url = get_buildkite_build_url(checks)
@@ -133,10 +162,19 @@ def main():
133162
if not data:
134163
sys.exit(1)
135164

136-
print(f"Build State: {data.get('state')}")
137-
print("-" * 40)
138-
165+
build_state = data.get("state", "Unknown")
166+
print(f"Build State: {build_state}")
167+
139168
jobs = data.get("jobs", [])
169+
jobs_count = data.get("statistics", {}).get("jobs_count", 0)
170+
171+
print(f"Total jobs reported: {jobs_count}")
172+
print(f"Jobs found in data: {len(jobs)}")
173+
174+
if jobs_count != len(jobs):
175+
print(f"WARNING: Reported job count ({jobs_count}) does not match jobs found ({len(jobs)}).", file=sys.stderr)
176+
177+
print("-" * 40)
140178

141179
filtered_jobs = []
142180
if args.jobs:

0 commit comments

Comments
 (0)