diff options
| author | hamdog0203 <360416966+hamdog0203@users.noreply.github.com> | 2026-11-24 11:09:17 +0100 |
|---|---|---|
| committer | hamdog0203 <360416966+hamdog0203@users.noreply.github.com> | 2026-11-24 11:09:17 +0100 |
| commit | 151e300abe18d760cf29d724b10cfaf62154ee9f (patch) | |
| tree | 832b94bf27965d7590a60d7e695985892875e56d /tools/progress_dashboard.py | |
| parent | 21625bca8c675c62f9dbffc318ce6a59d57faf31 (diff) | |
progress_dashboard: handle null comment authors, require --run-tests for --tests, and catch I/O and history errors (DASH-HARDEN-CLI)
Diffstat (limited to 'tools/progress_dashboard.py')
| -rw-r--r-- | tools/progress_dashboard.py | 36 |
1 files changed, 30 insertions, 6 deletions
diff --git a/tools/progress_dashboard.py b/tools/progress_dashboard.py index 9e9d0eb28..8c4c22447 100644 --- a/tools/progress_dashboard.py +++ b/tools/progress_dashboard.py | |||
| @@ -951,9 +951,11 @@ def collect_github(col, repo, login, d3d_issue=None): | |||
| 951 | claims = [] | 951 | claims = [] |
| 952 | for n in [num] + ([int(prev.group(1))] if prev else []): | 952 | for n in [num] + ([int(prev.group(1))] if prev else []): |
| 953 | comments = gh_json(["issue", "view", str(n), "-R", repo, "--json", "comments"]) or {} | 953 | comments = gh_json(["issue", "view", str(n), "-R", repo, "--json", "comments"]) or {} |
| 954 | claims += [{"at": c.get("createdAt"), "issue": n, "text": plain(c["body"].splitlines()[0])[:160]} | 954 | for c in comments.get("comments", []): |
| 955 | for c in comments.get("comments", []) | 955 | body_text = c.get("body") or "" |
| 956 | if c.get("author", {}).get("login") == login and "claiming" in c["body"].lower()] | 956 | if (c.get("author") or {}).get("login") == login and "claiming" in body_text.lower(): |
| 957 | first_line = (body_text.splitlines() or [""])[0] | ||
| 958 | claims.append({"at": c.get("createdAt"), "issue": n, "text": plain(first_line)[:160]}) | ||
| 957 | prs = gh_json(["pr", "list", "-R", repo, "--author", login, "--state", "all", "--limit", "50", | 959 | prs = gh_json(["pr", "list", "-R", repo, "--author", login, "--state", "all", "--limit", "50", |
| 958 | "--json", "number,title,state,isDraft,updatedAt"]) or [] | 960 | "--json", "number,title,state,isDraft,updatedAt"]) or [] |
| 959 | summary["mine"] = {"login": login, "claims": claims, | 961 | summary["mine"] = {"login": login, "claims": claims, |
| @@ -1018,10 +1020,22 @@ def render_page(snap, history): | |||
| 1018 | return template.replace("/*__PROGRESS_LOGO__*/", logo_src()).replace("/*__PROGRESS_DATA__*/null", payload) | 1020 | return template.replace("/*__PROGRESS_LOGO__*/", logo_src()).replace("/*__PROGRESS_DATA__*/null", payload) |
| 1019 | 1021 | ||
| 1020 | 1022 | ||
| 1023 | def _load_history(hist_path): | ||
| 1024 | if not os.path.isfile(hist_path): | ||
| 1025 | return [] | ||
| 1026 | try: | ||
| 1027 | history = json.loads(read_utf8(hist_path).lstrip("\ufeff")) | ||
| 1028 | except ValueError as exc: | ||
| 1029 | raise ValueError(f"{hist_path}: invalid JSON: {exc}") from None | ||
| 1030 | if not isinstance(history, list) or any(not isinstance(item, dict) or "content_hash" not in item for item in history): | ||
| 1031 | raise ValueError(f"{hist_path}: expected a JSON list of snapshot summaries") | ||
| 1032 | return history | ||
| 1033 | |||
| 1034 | |||
| 1021 | def write_outputs(snap, out_dir): | 1035 | def write_outputs(snap, out_dir): |
| 1022 | os.makedirs(os.path.join(out_dir, "snapshots"), exist_ok=True) | 1036 | os.makedirs(os.path.join(out_dir, "snapshots"), exist_ok=True) |
| 1023 | hist_path = os.path.join(out_dir, "history.json") | 1037 | hist_path = os.path.join(out_dir, "history.json") |
| 1024 | history = json.loads(read_utf8(hist_path)) if os.path.isfile(hist_path) else [] | 1038 | history = _load_history(hist_path) |
| 1025 | new = not history or history[-1]["content_hash"] != snap["content_hash"][:16] | 1039 | new = not history or history[-1]["content_hash"] != snap["content_hash"][:16] |
| 1026 | if new: | 1040 | if new: |
| 1027 | stamp = snap["generated_at"].replace("-", "").replace(":", "") | 1041 | stamp = snap["generated_at"].replace("-", "").replace(":", "") |
| @@ -1058,6 +1072,8 @@ def main(argv=None): | |||
| 1058 | ap.error("--d3d-issue requires --github") | 1072 | ap.error("--d3d-issue requires --github") |
| 1059 | if args.d3d_issue is not None and args.d3d_issue < 1: | 1073 | if args.d3d_issue is not None and args.d3d_issue < 1: |
| 1060 | ap.error("--d3d-issue must be a positive integer") | 1074 | ap.error("--d3d-issue must be a positive integer") |
| 1075 | if args.tests is not None and not args.run_tests: | ||
| 1076 | ap.error("--tests requires --run-tests") | ||
| 1061 | if args.jobs < 1: | 1077 | if args.jobs < 1: |
| 1062 | ap.error("--jobs must be a positive integer") | 1078 | ap.error("--jobs must be a positive integer") |
| 1063 | if args.test_timeout < 1: | 1079 | if args.test_timeout < 1: |
| @@ -1075,7 +1091,12 @@ def main(argv=None): | |||
| 1075 | print(f"--work {args.work} is not a folder", file=sys.stderr) | 1091 | print(f"--work {args.work} is not a folder", file=sys.stderr) |
| 1076 | return 2 | 1092 | return 2 |
| 1077 | if args.run_tests: | 1093 | if args.run_tests: |
| 1078 | args.test_files = [f for f in ci_test_files() if not args.tests or re.search(args.tests, f)] | 1094 | try: |
| 1095 | all_tests = ci_test_files() | ||
| 1096 | except OSError as exc: | ||
| 1097 | print(f"error: {exc.filename or ''}: {exc.strerror or exc}", file=sys.stderr) | ||
| 1098 | return 2 | ||
| 1099 | args.test_files = [f for f in all_tests if not args.tests or re.search(args.tests, f)] | ||
| 1079 | if args.tests and not args.test_files: | 1100 | if args.tests and not args.test_files: |
| 1080 | ap.error("--tests did not match any test files") | 1101 | ap.error("--tests did not match any test files") |
| 1081 | if os.path.exists(out_dir) and not os.path.isdir(out_dir): | 1102 | if os.path.exists(out_dir) and not os.path.isdir(out_dir): |
| @@ -1088,10 +1109,13 @@ def main(argv=None): | |||
| 1088 | return 2 | 1109 | return 2 |
| 1089 | try: | 1110 | try: |
| 1090 | snap = build(args, out_dir) | 1111 | snap = build(args, out_dir) |
| 1112 | new = write_outputs(snap, out_dir) | ||
| 1091 | except OSError as exc: | 1113 | except OSError as exc: |
| 1092 | print(f"error: {exc.filename or ''}: {exc.strerror or exc}", file=sys.stderr) | 1114 | print(f"error: {exc.filename or ''}: {exc.strerror or exc}", file=sys.stderr) |
| 1093 | return 2 | 1115 | return 2 |
| 1094 | new = write_outputs(snap, out_dir) | 1116 | except ValueError as exc: |
| 1117 | print(f"error: {exc}", file=sys.stderr) | ||
| 1118 | return 2 | ||
| 1095 | n = len(snap["components"]) | 1119 | n = len(snap["components"]) |
| 1096 | print(f"{n} units, {len(snap['metrics'])} metrics -> {os.path.join(out_dir, 'progress.html')}" | 1120 | print(f"{n} units, {len(snap['metrics'])} metrics -> {os.path.join(out_dir, 'progress.html')}" |
| 1097 | + ("" if new else " (no change since the last snapshot)")) | 1121 | + ("" if new else " (no change since the last snapshot)")) |