Files

78 lines
2.6 KiB
Python

"""What the preflight gathers, which facts.render states."""
import dataclasses
import pathlib
from failure import Failure
from forge.commands import Forge
from release_plan.release_standing import LastCut
from release_plan.next_chunk import NextChunk, NoItem
@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 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: NextChunk
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 LeftWorktree:
"""A worktree on a branch whose pull request has merged."""
path: pathlib.Path
branch: str
# The merged pull request's number.
pull: str
@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
# The plan that was read, as release_plan.next_chunk.plan_name names it.
plan: str
# Each path the project's config sets, and the epic of a plan kept in Jira, by its setting: in the item's worktree where one was made or continued, else in the checkout.
places: dict[str, str]
# Whether the project's config puts the plan outside the checkout, where a release whose items are all done is not seen.
plan_outside: bool
# The language and the templates the project's config names, by their settings.
texts: dict[str, str]
# Why the pull requests that await a person's merge could not be read; None where they were read or not asked for.
merges_unread: Failure | None = None
# The worktrees `chunk-pr clean` is still to remove.
left: tuple[LeftWorktree, ...] = ()