Read a project's language, title templates and branch template from its config

This commit is contained in:
2026-11-14 01:08:48 +01:00
parent 499d1772be
commit 82f4bbd91b
22 changed files with 316 additions and 43 deletions
+11 -4
View File
@@ -1,18 +1,25 @@
import functools
import pathlib
from rule_hook.rules import Breach
from review_rules.round_titles import cap, past_cap, round_counts, round_pass
from project_config.main import commit_title
from git_cli.git_command import CommitCall
from failure import Failure
from git_cli import git_repo
from review_rules.review_passes import PASSES
from project_config import templates
def round_cap_breaches(commit: CommitCall) -> list[Breach]:
"""A breach where the commit's title names no pass, or takes its pass past the cap, counted with the branch's earlier round commits."""
named = [(name, message) for message in commit.messages if (name := round_pass(message))]
def round_cap_breaches(commit: CommitCall, home: pathlib.Path) -> list[Breach]:
"""A breach where the commit's title names no pass, or takes its pass past the cap, counted with the branch's earlier round commits. Each title is read as its summary in the project's `commit-title` template."""
template = commit_title(commit.directory, home, functools.partial(git_repo.git, guarded=True))
summaries = [templates.summary_of(template, message.strip()) for message in commit.messages]
named = [(name, summary) for summary in summaries if (name := round_pass(summary))]
unknown = [Breach("round-cap", f"`{name}` names no larv-review pass, so its rounds would never reach a cap; name one of: {', '.join(PASSES)}", commit.directory) for name, _ in named if name not in PASSES]
if unknown or not named:
return unknown
earlier = earlier_titles(commit.directory, commit.amends)
earlier = [templates.summary_of(template, title) for title in earlier_titles(commit.directory, commit.amends)]
return [Breach("round-cap", refusal(name, message, earlier), commit.directory) for name, message in named if past_cap(message, earlier)]