Answer architecture round 1: 1 🔴, 2 🟡 (0 misread); read the branch's round titles and default branch one way for rule-hook and round-count
This commit is contained in:
+11
-12
@@ -1,25 +1,24 @@
|
||||
from failure import Failure
|
||||
from git_command import Commit
|
||||
from round_titles import CAP, past_cap, ROUND
|
||||
from rule_hook.git import git, local_default_branch
|
||||
from rule_hook.rules import Breach
|
||||
from round_titles import CAP, past_cap, ROUND
|
||||
from git_command import Commit
|
||||
from failure import Failure
|
||||
import git_repo
|
||||
|
||||
|
||||
def round_cap_breaches(commit: Commit) -> list[Breach]:
|
||||
"""A breach where the commit's title takes its pass past the cap, counted with the branch's earlier round commits."""
|
||||
if not any(ROUND.match(message) for message in commit.messages):
|
||||
return []
|
||||
earlier = branch_titles(commit.directory, commit.amends)
|
||||
earlier = earlier_titles(commit.directory, commit.amends)
|
||||
return [Breach("round-cap", f"the pass has had its {CAP} rounds; merge once the gate passes, with no round after them", commit.directory)] if any(past_cap(message, earlier) for message in commit.messages) else []
|
||||
|
||||
|
||||
def branch_titles(directory: str, amends: bool) -> list[str]:
|
||||
"""The titles of the branch's own commits, newest first, less the one an --amend replaces; none where git cannot tell in time, so the title's own number still counts.
|
||||
def earlier_titles(directory: str, amends: bool) -> list[str]:
|
||||
"""The branch's titles, less the one an --amend replaces; none where git cannot tell in time, so the title's own number still counts.
|
||||
|
||||
--first-parent leaves out the default branch's commits merged into the branch, which a stale local default branch would otherwise count as this chunk's rounds."""
|
||||
default = local_default_branch(directory)
|
||||
titles = git(directory, "log", "--first-parent", "--format=%s", f"{default}..HEAD", timeout=5) if default else Failure("no default branch")
|
||||
Run guarded, as the hook runs git, which neither fetches nor asks origin: the default branch is as last fetched."""
|
||||
default = git_repo.default_ref(directory, guarded=True)
|
||||
titles = default if isinstance(default, Failure) else git_repo.branch_titles(default, directory, timeout=5, guarded=True)
|
||||
if isinstance(titles, Failure):
|
||||
return []
|
||||
listed = titles.splitlines()
|
||||
return listed[1:] if amends else listed
|
||||
return titles[1:] if amends else titles
|
||||
|
||||
Reference in New Issue
Block a user