46 lines
2.1 KiB
Python
46 lines
2.1 KiB
Python
import pathlib
|
|
|
|
from larv_review.plan import EMPTIED_WORDS, plan_reasons
|
|
from review_rules.comprehension_history import entries, HISTORY
|
|
from failure import Failure
|
|
from git_cli.git_repo import file_at, top
|
|
from larv_review.history_commands import history_file
|
|
from release_plan.ranking import OPTED_OUT
|
|
|
|
|
|
def owed_scoring_run(default: str) -> Failure | None:
|
|
"""A Failure saying which scoring runs the chunk owes and has not recorded; None where it owes none.
|
|
|
|
The chunk owes the runs the plan calls (`plan_reasons`, which takes the chunk's shipped items as the plan's removed ones): two where it empties a release, else one. The branch records a run when its history holds a scoring run the default branch's lacks. A project that opts out of the comprehension check, or has no todo.md, owes none. Run at merge time, it reads the plan as it stands then, so a due line that preflight printed from an older plan can't stand in for it.
|
|
"""
|
|
checkout = top()
|
|
if isinstance(checkout, Failure):
|
|
return checkout
|
|
if not pathlib.Path(checkout, "todo.md").exists():
|
|
return None
|
|
decisions = file_at(default, "docs/decisions.md", checkout)
|
|
if isinstance(decisions, Failure):
|
|
return decisions
|
|
if OPTED_OUT.search(decisions):
|
|
return None
|
|
reasons = plan_reasons(default, None)
|
|
if isinstance(reasons, Failure):
|
|
return reasons
|
|
if not reasons:
|
|
return None
|
|
base = file_at(default, HISTORY, checkout)
|
|
if isinstance(base, Failure):
|
|
return base
|
|
head = history_file()
|
|
if isinstance(head, Failure):
|
|
return head
|
|
recorded = len(scoring_runs(head[1])) - len(scoring_runs(base))
|
|
needed = 2 if any(reason.endswith(EMPTIED_WORDS) for reason in reasons) else 1
|
|
if recorded >= needed:
|
|
return None
|
|
return Failure(f"the chunk owes {needed} scoring run{'s' if needed > 1 else ''}, since it {' and '.join(reasons)}, and the branch records {max(recorded, 0)} of {needed}: launch the four seats on the head and record each run with `larv-review record-scoring`, as larv-review's SKILL.md → 'Scoring run' says")
|
|
|
|
|
|
def scoring_runs(history: str) -> list[str]:
|
|
return [entry.heading for entry in entries(history) if not entry.paired]
|