"""Run reports (raw: the "run report" issues from the GitHub API) -> data/public/reports.json. Kept per report: the issue number, the date it was opened, and the answers (the option labels chosen). GitHub usernames and any other text are dropped. Reports closed as "not planned" or carrying a reject label (e.g. invalid, duplicate) are left out, so a maintainer removes a bad report by closing it that way.""" import json from pathlib import Path from .. import report_form def transform(raw_path, spec, ctx): issues = json.loads(Path(raw_path).read_text(encoding="utf-8")) reject = set(spec["transform"].get("reject_labels", [])) form = report_form.spec() reports = [] for i in sorted(issues, key=lambda i: i["number"]): labels = {lb["name"] if isinstance(lb, dict) else lb for lb in i.get("labels") or []} if labels & reject or i.get("state_reason") == "not_planned": continue answers = report_form.parse_body(i.get("body"), form) if not answers: continue reports.append({"number": i["number"], "opened": (i.get("created_at") or "")[:10] or None, "answers": answers}) return {"source": spec["label"], "reports": reports} def describe(old, new): o = {r["number"] for r in (old or {}).get("reports", [])} n = {r["number"] for r in new["reports"]} return [f"{len(n)} report(s) ({len(n - o)} new, {len(o - n)} removed)"]