Answer architecture round 3: 0 🔴, 1 🟡; pick the next chunk's item in one function, todo_table.chunk_item, which routing and the preflight both call, so routing names no item where the release after the last cut has none

This commit is contained in:
2026-10-17 02:19:11 +02:00
parent 45004e1b0b
commit 4cf3c2bd8c
9 changed files with 130 additions and 95 deletions
+3 -22
View File
@@ -4,16 +4,13 @@ import pathlib
import re
import typing
from todo_table import chunk_item, Item, item_details, items
from failure import Failure
from todo_table import Item, item_details, items, next_item
# The CLI that lists a forge's pull requests: gh for a github.com origin, tea for any other.
Forge = typing.Literal["gh", "tea"]
# The command each forge's CLI lists pull requests with; pulls_command adds the flags that pick their rows and fields.
PULLS_LIST: dict[Forge, tuple[str, ...]] = {"gh": ("gh", "pr", "list"), "tea": ("tea", "pulls", "list")}
# How the plan's earliest release stands to the version x.y.z the newest tag names. "next": it is x.y.z+1, x.y+1.0 or x+1.0.0, or no tag names a version. "cut": it is x.y.z or earlier.
# Else the release after the tag holds no item: "finished" where commits followed the tag, "unplanned" where none did, and "unknown" where they cannot be counted.
Standing = typing.Literal["next", "cut", "finished", "unplanned", "unknown"]
@dataclasses.dataclass(frozen=True)
@@ -94,7 +91,7 @@ class Gathered:
def planned(todo: str | Failure, release: Release, default: str) -> Plan | NoItem:
"""The plan in todo, the default branch's todo.md, with the item the next chunk takes first, todo_table.next_item's pick, where standing finds the plan's earliest release next; else why there is none."""
"""The plan in todo, the default branch's todo.md, with the item the next chunk takes first, todo_table.chunk_item's pick, which routing makes too; else why there is none."""
where = f"{default}'s todo.md"
if isinstance(todo, Failure):
return NoItem(f"{where} cannot be read: {todo.reason}.")
@@ -104,7 +101,7 @@ def planned(todo: str | Failure, release: Release, default: str) -> Plan | NoIte
if found is None:
return NoItem(f"{where} holds no items table.")
earliest = min((item.release for item in found), default=None)
stands = standing(release, earliest)
stands, first = chunk_item(found, release.tag, release.commits)
if earliest is not None and stands == "cut":
return NoItem(f"{where} files items under release {version(earliest)}, which is not after the last cut, {release.tag}.")
gap = f"{where} holds no item for the release after the last cut, {release.tag}, and"
@@ -114,7 +111,6 @@ def planned(todo: str | Failure, release: Release, default: str) -> Plan | NoIte
return NoItem(f"{gap} no commit has landed since, so that release is to be planned first.")
if stands == "unknown":
return NoItem(f"{gap} the commits since it cannot be counted.")
first = next_item(found)
if first is None:
return NoItem(f"every item of release {version(earliest)} in {where} waits." if earliest is not None else f"{where}'s items table holds no item.")
details = item_details(todo)
@@ -122,21 +118,6 @@ def planned(todo: str | Failure, release: Release, default: str) -> Plan | NoIte
return Plan(found, first, f"{first.tagline}\n\n{detail}".strip())
def standing(release: Release, earliest: tuple[int, int, int] | None) -> Standing:
"""How the plan's earliest release, None where the plan holds no item, stands to the version the release's tag names, as Standing says."""
cut = re.fullmatch(r"v([0-9]+)\.([0-9]+)\.([0-9]+)", release.tag) if isinstance(release.tag, str) else None
if cut is None:
return "next"
major, minor, patch = (int(part) for part in cut.groups())
if earliest in ((major, minor, patch + 1), (major, minor + 1, 0), (major + 1, 0, 0)):
return "next"
if earliest is not None and earliest <= (major, minor, patch):
return "cut"
if isinstance(release.commits, Failure):
return "unknown"
return "finished" if release.commits else "unplanned"
def version(release: tuple[int, int, int]) -> str:
return ".".join(map(str, release))