31 lines
1.9 KiB
Python
31 lines
1.9 KiB
Python
"""rule-hook's check of a round commit's counts against the round's report in the chunk's review folder."""
|
|
import pathlib
|
|
|
|
from rule_hook.rules import Breach
|
|
from git_cli.git_command import CommitCall
|
|
from failure import Failure
|
|
from review_rules.review_folder import findings_in, review_folder, standing_report
|
|
from git_cli.git_repo import git
|
|
from review_rules.round_titles import ROUND, round_prefix, title_counts
|
|
from project_config.templates import Titles
|
|
|
|
|
|
def round_report_breaches(commit: CommitCall, titles: Titles, home: pathlib.Path) -> list[Breach]:
|
|
"""A breach for each round title whose counts differ from those its round's report gives. The round title is the commit title's summary, as `titles` cuts it. A title without all three counts is title_breaches' to refuse. A round whose report is missing or unreadable, or says BLOCK without a finding heading, 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} counts `{round_prefix(pass_, round_, found)}`; open the title's summary with that, which `larv-review round-title {pass_}` prints", commit.directory))
|
|
return breaches
|