#!/usr/bin/env python3 """Refresh public Gerrit status and optional HTTPS RR lab file snapshots.""" import argparse import json import shutil import subprocess from datetime import datetime, timezone from pathlib import Path CHANGES = ( (1, 7984025, "cl/7984025"), (2, 7984026, "cl/7984026"), (3, 7984027, "cl/7984027"), (4, 7984028, "cl/7984028"), (5, None, "httpsrr-alternate-port"), ) LAB_FILES = { "https_rr_test_server.py": "server.py", "run_browser_tests.py": "run_browser_tests.py", "validate_netlog.py": "validate_netlog.py", "Caddyfile.snippet": "Caddyfile", "bartlby.org.bind": "bartlby.org.bind", "Dockerfile": "Dockerfile", } def run(*args, cwd=None): return subprocess.run( args, cwd=cwd, check=True, capture_output=True, text=True, ).stdout.strip() def branch_issue(src, branch): result = subprocess.run( ["git", "config", "--get", f"branch.{branch}.gerritissue"], cwd=src, capture_output=True, text=True, ) value = result.stdout.strip() return int(value) if result.returncode == 0 and value.isdigit() else None def local_subject(src, branch): return run("git", "show", "-s", "--format=%s", branch, cwd=src) def gerrit_change(number, order): data = json.loads(run("ch", "-f", "json", "gerrit", "status", str(number))) return { "order": order, "total": len(CHANGES), "number": data.get("_number", number), "status": data["status"], "subject": data["subject"], "url": f"https://chromium-review.googlesource.com/c/chromium/src/+/{number}", "updated": data.get("updated"), "comments": data.get("total_comment_count", 0), "unresolved_comments": data.get("unresolved_comment_count", 0), "review_started": data.get("has_review_started", False), } def main(): parser = argparse.ArgumentParser(description=__doc__) parser.add_argument( "--src", type=Path, help="Chromium src checkout, used to discover the fifth CL", ) parser.add_argument( "--fifth-cl", type=int, help="Gerrit number for the alternate-port child before branch config exists", ) parser.add_argument( "--lab-dir", type=Path, help="Copy the public lab files from this directory into ./lab", ) args = parser.parse_args() output_dir = Path(__file__).resolve().parent changes = [] for order, number, branch in CHANGES: if order == 5: number = args.fifth_cl if number is None and args.src: number = branch_issue(args.src, branch) if number: changes.append(gerrit_change(number, order)) else: if not args.src: subject = "[HTTPS-RR 5/5] Honor alternate ports from HTTPS resource records" else: subject = local_subject(args.src, branch) changes.append( { "order": order, "total": len(CHANGES), "number": None, "status": "LOCAL", "subject": subject, "url": None, "updated": None, "comments": 0, "unresolved_comments": 0, "review_started": False, } ) payload = { "generated_at": datetime.now(timezone.utc).isoformat(), "changes": changes, } status_path = output_dir / "status.json" status_path.write_text(json.dumps(payload, indent=2) + "\n") print(f"wrote {status_path}") if args.lab_dir: lab_output = output_dir / "lab" lab_output.mkdir(exist_ok=True) for source_name, public_name in LAB_FILES.items(): source = args.lab_dir / source_name destination = lab_output / public_name shutil.copyfile(source, destination) print(f"copied {source} -> {destination}") if __name__ == "__main__": main()