import re CAP = 3 PASSES = ("architecture", "full scan", "security", "overrides", "stability", "product-owner", "prose") ROUND = re.compile(r"^Answer (.+?) round ([0-9]+):", re.IGNORECASE) 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}