"""The titles of larv-review's round commits, `Answer round : 🔴, 🟡 ( misread); `: each pass's round count, and the findings the rounds reported. counts the 🔴 and 🟡 findings a reviewer marked `[misread]`, because the implementer misread code that had already shipped.""" import re from review_passes import PASSES # The most rounds a pass takes before the run asks the human, per `docs/decisions.md` → `review: a pass gets at most three rounds per chunk; …`. rule-hook's `round-cap` refuses a round title past it, and `larv-review round-count` marks a pass at or past it. CAP = 3 ROUND = re.compile(r"^Answer (.+?) round ([0-9]+):", re.IGNORECASE) # What follows a round title's colon: the round's 🔴 and 🟡 counts, then how many of them were misread, which titles from before the count lack, then `;` and its summary, if any. FINDINGS = re.compile(r" ([0-9]+) 🔴, ([0-9]+) 🟡(?: \(([0-9]+) misread\))?(?:;|$)") def round_counts(titles: list[str]) -> dict[str, int]: """Each pass's round count among the branch's `Answer round :` commit titles: the highest , or the number of such commits where that is more, so a repeated number still counts. A pass with none has 0, and a title naming no known pass adds its name. Case is ignored.""" highest: dict[str, int] = dict.fromkeys(PASSES, 0) commits: dict[str, int] = dict.fromkeys(PASSES, 0) for title in titles: if named := ROUND.match(title): name = named.group(1).lower() highest[name] = max(highest.get(name, 0), int(named.group(2))) commits[name] = commits.get(name, 0) + 1 return {name: max(highest[name], commits[name]) for name in highest} def lacks_counts(title: str) -> bool: """Whether title is a round title without all three counts after its colon.""" named = ROUND.match(title) return named is not None and ((found := FINDINGS.match(title, named.end())) is None or found.group(3) is None) def past_cap(title: str) -> bool: """Whether title is a round title numbered past CAP.""" named = ROUND.match(title) return named is not None and int(named.group(2)) > CAP def round_findings(titles: list[str]) -> tuple[int, int] | None: """The 🔴 and 🟡 counts summed over the round titles among titles; None where a round title lacks them, or no title is a round.""" counts = [] for title in titles: if named := ROUND.match(title): found = FINDINGS.match(title, named.end()) if not found: return None counts.append((int(found.group(1)), int(found.group(2)))) return (sum(red for red, _ in counts), sum(yellow for _, yellow in counts)) if counts else None def round_misreads(titles: list[str]) -> int | None: """The misread counts summed over the round titles among titles; None where a round title lacks one, or no title is a round.""" counts = [] for title in titles: if named := ROUND.match(title): found = FINDINGS.match(title, named.end()) if not found or found.group(3) is None: return None counts.append(int(found.group(3))) return sum(counts) if counts else None