#!/usr/bin/env bash # Prints the next eligible queue issue as JSON: {issue_num, canonical_id, driver, plan_pr_id, branch, ...} # Eligible = open + label queue/queued + all canonical deps closed. # Picks lowest phase first, then lowest issue number within phase. set -euo pipefail HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" . "$HERE/lib.sh" python - <', it.get("body","") or "", re.S) if not m: continue try: meta = json.loads(m.group(1)) except: continue by_id[meta["id"]] = (it, meta) def is_done(issue): if issue["state"] == "closed": return True labels = {l["name"] for l in issue["labels"]} return "queue/done" in labels eligible = [] for cid, (it, meta) in by_id.items(): labels = {l["name"] for l in it["labels"]} if it["state"] != "open": continue if "queue/queued" not in labels: continue deps = meta.get("deps", []) blocked = False for d in deps: if d not in by_id: blocked = True; break if not is_done(by_id[d][0]): blocked = True; break if blocked: continue eligible.append((meta.get("phase",99), it["number"], cid, it, meta)) if not eligible: print(json.dumps({"empty": True})) sys.exit(0) eligible.sort(key=lambda x: (x[0], x[1])) phase, num, cid, it, meta = eligible[0] plan_pr = meta.get("plan_pr_id","").replace("/","-") result = { "empty": False, "issue_num": num, "canonical_id": cid, "driver": meta["driver"], "phase": meta["phase"], "plan_pr_id": meta.get("plan_pr_id",""), "title": it["title"], "branch": f"auto/{meta['driver']}/{plan_pr}", "url": it["html_url"], } print(json.dumps(result, indent=2)) PY