Created
May 7, 2026 15:29
-
-
Save malfet/336dd98295ae5e858191a4f5043deebc to your computer and use it in GitHub Desktop.
Fetch commit statuses from HUD
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """Fetch the latest N commits' job statuses from hud.pytorch.org.""" | |
| import argparse | |
| import gzip | |
| import json | |
| import sys | |
| from curl_cffi import requests | |
| def fetch_hud(owner: str, repo: str, branch: str, count: int) -> dict: | |
| url = ( | |
| f"https://hud.pytorch.org/api/hud/{owner}/{repo}/{branch}/0" | |
| f"?per_page={count}" | |
| ) | |
| r = requests.get(url, impersonate="chrome124", timeout=30) | |
| if r.status_code != 200: | |
| raise RuntimeError( | |
| f"status={r.status_code} " | |
| f"mitigated={r.headers.get('x-vercel-mitigated')!r}" | |
| ) | |
| body = r.content | |
| if body[:2] == b"\x1f\x8b": | |
| body = gzip.decompress(body) | |
| return json.loads(body) | |
| def main() -> int: | |
| ap = argparse.ArgumentParser(description=__doc__.strip().splitlines()[0]) | |
| ap.add_argument( | |
| "-n", "--commit-count", type=int, default=50, | |
| help="Number of commits to fetch and display (default: 50)", | |
| ) | |
| ap.add_argument( | |
| "--slug", default="pytorch/pytorch", | |
| help="GitHub repo slug, e.g. pytorch/pytorch or pytorch/executorch", | |
| ) | |
| ap.add_argument("--branch", default="main") | |
| args = ap.parse_args() | |
| try: | |
| owner, repo = args.slug.split("/", 1) | |
| except ValueError: | |
| ap.error(f"--slug must be owner/repo, got {args.slug!r}") | |
| data = fetch_hud(owner, repo, args.branch, args.commit_count) | |
| sha_grid = data.get("shaGrid", []) | |
| job_names = data.get("jobNames", []) | |
| print( | |
| f"Got {len(sha_grid)} commits across {len(job_names)} jobs", | |
| file=sys.stderr, | |
| ) | |
| for row in sha_grid[: args.commit_count]: | |
| sha = (row.get("sha") or "")[:12] | |
| time = row.get("time", "") | |
| jobs = row.get("jobs") or [] | |
| ok = sum(1 for j in jobs if j.get("conclusion") == "success") | |
| fail = sum(1 for j in jobs if j.get("conclusion") == "failure") | |
| pend = sum( | |
| 1 for j in jobs | |
| if j.get("conclusion") in (None, "", "pending", "in_progress") | |
| ) | |
| author = (row.get("author") or "")[:20] | |
| title = (row.get("commitTitle") or "")[:70] | |
| print( | |
| f"{sha} {time} ok={ok:3d} fail={fail:3d} pend={pend:3d} " | |
| f"{author:20.20} {title}" | |
| ) | |
| return 0 | |
| if __name__ == "__main__": | |
| sys.exit(main()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment