Have larv-review round-title print a round commit's counts from its report, and rule-hook refuse a title that differs
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
"""rule-hook's check of a round commit's counts against the round's report in the chunk's review folder."""
|
||||
import pathlib
|
||||
|
||||
from failure import Failure
|
||||
from git_cli.git_command import CommitCall
|
||||
from git_cli.git_repo import git
|
||||
from project_config.templates import Titles
|
||||
from review_rules.review_folder import findings_in, review_folder, standing_report
|
||||
from review_rules.round_titles import ROUND, round_prefix, title_counts
|
||||
from rule_hook.rules import Breach
|
||||
|
||||
|
||||
def round_report_breaches(commit: CommitCall, titles: Titles, home: pathlib.Path) -> list[Breach]:
|
||||
"""A breach for each round title, read as its summary in titles, whose counts differ from those its round's report gives. A title without all three counts is title_breaches' to refuse. A round whose report is missing goes through, as does every round where git cannot name the commit's checkout within 5 seconds."""
|
||||
summaries = [titles.summary(message.strip()) for message in commit.messages]
|
||||
rounds = [(named, counts) for summary in summaries if (named := ROUND.match(summary)) and (counts := title_counts(summary)) and counts.misread is not None]
|
||||
if not rounds:
|
||||
return []
|
||||
worktree = git("rev-parse", "--show-toplevel", cwd=commit.directory, timeout=5, guarded=True)
|
||||
if isinstance(worktree, Failure):
|
||||
return []
|
||||
folder = pathlib.Path(review_folder(str(home), worktree.strip()))
|
||||
breaches = []
|
||||
for named, counts in rounds:
|
||||
pass_, round_ = named.group(1).lower(), int(named.group(2))
|
||||
report = standing_report(folder, pass_, round_)
|
||||
found = findings_in(report)
|
||||
if not isinstance(found, Failure) and found != counts:
|
||||
breaches.append(Breach("round-title-counts", f"{report} reports `{round_prefix(pass_, round_, found)}`; open the title so, as `larv-review round-title {pass_}` prints it before the round's commit", commit.directory))
|
||||
return breaches
|
||||
Reference in New Issue
Block a user