Files

54 lines
2.6 KiB
Python

"""Could code find a release ready to cut where the judge did? For each archived interrupt, prints whether the plan, as the project's default branch and tags stood at the verdict's stamp, read ReadyToCut, and whether the judge's question is about a cut."""
import collections
import datetime
import pathlib
import re
from cases import cases
from transcript_archive.project_key import checkout_of
from release_plan.release_standing import chunk_item, default_plan, ReadyToCut
from git_cli.git_repo import default_ref, git
from plan.todo_table import items
ABOUT_CUT = re.compile(r"\bcut\b|ready to (?:cut|release|ship)|tag (?:it|v\d)|version bump", re.IGNORECASE)
def as_of(stamp: str):
"""A git runner that lists only the tags created by stamp, so a later cut doesn't count."""
def run(*args, cwd=None, **kwargs):
out = git(*args, cwd=cwd, **kwargs)
if "tag" in args and "--list" in args and isinstance(out, str):
dates = git("for-each-ref", "--format=%(refname:short) %(creatordate:iso-strict)", "refs/tags", cwd=cwd)
created = dict(line.split(" ", 1) for line in dates.splitlines()) if isinstance(dates, str) else {}
out = "\n".join(tag for tag in out.split() if utc(created.get(tag, "")) <= stamp)
return out
return run
def utc(iso: str) -> str:
"""iso in the verdict stamp's form, or "" for no date, which sorts before every stamp."""
return datetime.datetime.fromisoformat(iso).astimezone(datetime.timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ") if iso else ""
table = collections.Counter()
for outcomes, (stamp, kind, block), entries in cases():
if kind != "Verdict: interrupt":
continue
project = outcomes.parent.parent.name
root = str(checkout_of(project, pathlib.Path.home()))
question = block.split("\n\n", 2)[1] if block.count("\n\n") >= 2 else ""
about = bool(ABOUT_CUT.search(question))
ref = default_ref(root, 10) if pathlib.Path(root).is_dir() else None
commit = git("rev-list", "-1", f"--before={stamp}", ref, cwd=root) if isinstance(ref, str) else None
if not isinstance(commit, str) or not commit.strip():
table[("no checkout or commit", about)] += 1
continue
plan = default_plan(root, commit.strip(), as_of(stamp))
found = items(plan.plan) if isinstance(plan.plan, str) else plan.plan
pick = chunk_item(found, plan.cut) if isinstance(found, list) else found
ready = isinstance(pick, ReadyToCut)
table[(ready, about)] += 1
print(f"{'ready' if ready else 'not '} {'cut?' if about else ' '} {project} {stamp} {type(pick).__name__}: {question[:220]!r}")
for (ready, about), count in sorted(table.items(), key=str):
print(f"ReadyToCut {ready}, asks about a cut {about}: {count}")