27 lines
1.8 KiB
Python
27 lines
1.8 KiB
Python
from failure import Failure
|
|
from todo_table import Item
|
|
|
|
|
|
def scoring_run_due(before: list[Item], after: list[Item], ships: list[int], landed: bool) -> list[str] | Failure:
|
|
"""Why the plan calls a scoring run, empty when it does not. before is the default branch's plan, after the chunk's, ships the IDs it ships, and landed whether the default branch holds a commit after its newest release tag.
|
|
|
|
A chunk that ships an item naming the floor is due one, so it can prove the floor met. So is a chunk that empties a release towards which work has landed, so no release ends unmeasured: it ships one of the release's items, or the release is the next one, the earliest before names, and landed holds. That covers a release whose last item moved to another release.
|
|
"""
|
|
plan = {item.id: item for item in before + after}
|
|
if unknown := sorted(set(ships) - set(plan)):
|
|
return Failure(f"neither plan holds item {', '.join(map(str, unknown))}")
|
|
shipped = [plan[id_] for id_ in ships]
|
|
reasons = [f"ships item {item.id}, which names the comprehension floor" for item in shipped if "comprehension floor" in item.tagline.lower()]
|
|
next_release = min((item.release for item in before), default=None)
|
|
for release in emptied(before, after, shipped):
|
|
if any(item.release == release for item in shipped) or (release == next_release and landed):
|
|
reasons.append(f"leaves release {'.'.join(map(str, release))} with no plan item")
|
|
return reasons
|
|
|
|
|
|
def emptied(before: list[Item], after: list[Item], shipped: list[Item]) -> list[tuple[int, int, int]]:
|
|
"""Each release the default branch's plan or a shipped item names that the chunk's plan, less the shipped items, names no longer."""
|
|
named = {item.release for item in before + shipped}
|
|
left = {item.release for item in after if item.id not in {ship.id for ship in shipped}}
|
|
return sorted(named - left)
|