"""What the preflight gathers, which facts.render states.""" import dataclasses import pathlib import typing from failure import Failure from release_plan.todo_table import Item from release_plan.release_standing import LastCut # The CLI that lists a forge's pull requests: gh for a github.com origin, tea for any other. Forge = typing.Literal["gh", "tea"] @dataclasses.dataclass(frozen=True) class Ran: """A command that ran to its end: its exit code and what it printed.""" code: int stdout: str stderr: str @dataclasses.dataclass(frozen=True) class Plan: """The default branch's todo.md items, and `first`: the item the next chunk takes first.""" items: list[Item] first: Item # first's tagline and detail. text: str @property def branch(self) -> str: """The branch first's worktree is on.""" return f"item-{self.first.id}" @dataclasses.dataclass(frozen=True) class NoItem: """Why the plan names no item for the next chunk, as a sentence the worker reads.""" why: str @dataclasses.dataclass(frozen=True) class Worktree: path: pathlib.Path # How it came to be, as the worker reads it. how: str @dataclasses.dataclass(frozen=True) class NamedPath: """A tracked file or folder the item names, with how many tracked files it holds.""" span: str files: int # A file's lines, or why they cannot be read; None for a folder. lines: int | Failure | None @dataclasses.dataclass(frozen=True) class ItemFacts: """What the preflight found or made for the plan's first item.""" plan: Plan worktree: Worktree | Failure # The forge whose CLI listed the open pull requests, and how it ran; None without an origin remote. pulls: tuple[Forge, Ran | Failure] | None named: list[NamedPath] | Failure # Each tool run in the worktree, by its command line, and how it ran; none without a worktree. tools: list[tuple[str, Ran | Failure]] @dataclasses.dataclass(frozen=True) class Gathered: """Everything the preflight read and ran, for facts.render to state.""" # The default branch's ref, such as origin/main. default: str # Why origin reads as last fetched; None after a fetch. note: str | None cut: LastCut # What was found or made for the plan's first item; else why the plan names none. item: ItemFacts | NoItem