"""The titles of larv-review's round commits, `Answer round : 🔴, 🟡; `: each pass's round count, and the findings the rounds reported.""" import re CAP = 3 PASSES = ("architecture", "principles", "full scan", "security", "overrides", "stability", "product-owner", "prose") ROUND = re.compile(r"^Answer (.+?) round ([0-9]+):", re.IGNORECASE) # What follows a round title's colon: the round's 🔴 and 🟡 counts, then `;` and its summary, if any. FINDINGS = re.compile(r" ([0-9]+) 🔴, ([0-9]+) 🟡(?:;|$)") 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 the counts after its colon.""" named = ROUND.match(title) return named is not None and not FINDINGS.match(title, named.end()) 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