Let do-epic's config name the statuses that unblock an issue and leave the moves to a team's automation

This commit is contained in:
Lilleman
2026-11-19 21:44:08 +01:00
parent 005a23f431
commit 111cb9248e
11 changed files with 132 additions and 36 deletions
+27 -14
View File
@@ -9,7 +9,8 @@ from do_epic.epic_record import CAP
from chunk_driver.claims import CHUNK_FLAG, epic_chunks, HANDED, loop_chunks, project_lock, starting
from do_epic.backend.protocol import EpicIssue
from failure import Failure
from do_epic.split import finished, is_split
from do_epic.split import finished, is_split, SPLIT_LABEL
from text_files.markdown_text import listed
from do_epic.repo_pick import HumanTask, LabelRepos, Pick, recorded, Repo
from project_config.settings import PARALLEL_CHUNKS
from do_epic.parked import parked_chunks
@@ -73,43 +74,54 @@ class Epic:
env: typing.Mapping[str, str]
# The team's own labels for its repos.
team: LabelRepos
# The statuses `jira-unblocking-statuses` names; `settled` says what they do.
unblocking: tuple[str, ...] = ()
@property
def folder(self) -> pathlib.Path:
return self.home / STATE / self.key
def open_blockers(issue: EpicIssue, by_key: dict[str, EpicIssue]) -> list[str]:
"""The keys of the issues that block issue, or its parent, that are not done. A blocker outside the epic counts, since its state is unknown."""
def settled(issue: EpicIssue, by_key: dict[str, EpicIssue], unblocking: tuple[str, ...]) -> bool:
"""Whether the issue's work has landed, so that it takes no chunk and unblocks what it blocks: the tracker counts it done, or its status is one of unblocking, such as one the team's automation gives an issue whose pull request merged. An item marked SPLIT_LABEL has landed once each of its sub-tasks has, since nobody moves it before they are done."""
tasks = [task for task in by_key.values() if task.parent == issue.key] if SPLIT_LABEL in issue.labels else []
return issue.done or issue.status in unblocking or bool(tasks) and all(settled(task, by_key, unblocking) for task in tasks)
def open_blockers(issue: EpicIssue, by_key: dict[str, EpicIssue], unblocking: tuple[str, ...] = ()) -> list[str]:
"""The keys of the issues that block issue, or its parent, that are not settled. A blocker outside the epic counts, since its state is unknown."""
parent = by_key.get(issue.parent)
return [key for key in (*issue.blockers, *(parent.blockers if parent else ())) if key not in by_key or not by_key[key].done]
return [key for key in (*issue.blockers, *(parent.blockers if parent else ())) if key not in by_key or not settled(by_key[key], by_key, unblocking)]
def held_up(issues: list[EpicIssue]) -> dict[str, list[str]]:
def held_up(issues: list[EpicIssue], unblocking: tuple[str, ...] = ()) -> dict[str, list[str]]:
"""Each blocker's key, mapped to the keys of the open issues it holds up, in the tracker's rank order. A split item's blocker holds up the item's sub-tasks."""
by_key = {issue.key: issue for issue in issues}
held: dict[str, list[str]] = {}
for issue in issues:
if not issue.done and not is_split(issue, issues):
for key in open_blockers(issue, by_key):
if not settled(issue, by_key, unblocking) and not is_split(issue, issues):
for key in open_blockers(issue, by_key, unblocking):
held.setdefault(key, []).append(issue.key)
return held
def chunks(issues: list[EpicIssue], team: LabelRepos) -> tuple[list[Chunk], list[Waits]]:
"""The open issues to work as chunks, in the tracker's rank order, and those that wait. A split item is worked through its sub-tasks, and what blocks it blocks them."""
def chunks(issues: list[EpicIssue], team: LabelRepos, unblocking: tuple[str, ...] = ()) -> tuple[list[Chunk], list[Waits]]:
"""The open issues to work as chunks, in the tracker's rank order, and those that wait. A split item is worked through its sub-tasks, and what blocks it blocks them. An issue in one of the unblocking statuses is worked already, and waits only to be done."""
by_key = {issue.key: issue for issue in issues}
holding = held_up(issues)
holding = held_up(issues, unblocking)
found: list[Chunk] = []
waits: list[Waits] = []
for issue in issues:
if issue.done:
continue
if issue.status in unblocking:
waits.append(Waits(issue.key, f"its work is merged: it is {issue.status}, and the epic's finishing waits until Jira counts it done"))
continue
if is_split(issue, issues):
if all(task.done for task in issues if task.parent == issue.key) and not finished(issues, issue.key):
waits.append(Waits(issue.key, "its sub-tasks are done; close it in Jira"))
continue
turn = turn_of(issue, recorded(issue, team), open_blockers(issue, by_key), by_key, issue.key in holding)
turn = turn_of(issue, recorded(issue, team), open_blockers(issue, by_key, unblocking), by_key, issue.key in holding, unblocking)
if isinstance(turn, Chunk):
found.append(turn)
else:
@@ -117,7 +129,7 @@ def chunks(issues: list[EpicIssue], team: LabelRepos) -> tuple[list[Chunk], list
return found, waits
def turn_of(issue: EpicIssue, pick: Pick | None | Failure, blocking: list[str], by_key: dict[str, EpicIssue], holds: bool) -> Chunk | Waits:
def turn_of(issue: EpicIssue, pick: Pick | None | Failure, blocking: list[str], by_key: dict[str, EpicIssue], holds: bool, unblocking: tuple[str, ...] = ()) -> Chunk | Waits:
"""The open issue's chunk, or why it waits. blocking are its open blockers, and holds says it holds up another open issue. A human's task gets a window only while it holds up another issue and nothing holds it up; that window waits for the human. A blocker outside the epic blocks until the human removes the link, since its state is unknown."""
if isinstance(pick, Failure):
return Waits(issue.key, pick.reason)
@@ -128,7 +140,8 @@ def turn_of(issue: EpicIssue, pick: Pick | None | Failure, blocking: list[str],
if blocking:
outside = [key for key in blocking if key not in by_key]
unseen = f"; do-epic cannot see {' and '.join(outside)}, outside the epic, finish: remove such a link in Jira once its issue is done" if outside else ""
return Waits(issue.key, f"{' and '.join(blocking)} block{'s' if len(blocking) == 1 else ''} it{unseen}")
until = f", until {'it' if len(blocking) == 1 else 'each'} is {listed(unblocking, 'or')}" if unblocking else ""
return Waits(issue.key, f"{' and '.join(blocking)} block{'s' if len(blocking) == 1 else ''} it{until}{unseen}")
return Chunk(issue.key, pick.name if isinstance(pick, Repo) else None)
@@ -144,7 +157,7 @@ def refusal(repo: str, room: RepoRoom) -> str | None:
def start_chunks(epic: Epic, issues: list[EpicIssue], finishing: bool, own: str | None, run: tmux.Tmux) -> Started | Failure:
"""Starts a do-epic in a new window for each of the epic's chunks that may start now. Where finishing is set, no issue is open, and the one chunk to start is the epic's finishing (finish.py), in a window named for the epic's key. own is the key of the chunk that asks, which has finished or parked: it counts as running nowhere, and no stopped chunk starts again. Where own is None, the human's `do-epic <EPIC-KEY>` asks, and each stopped chunk starts again. A parked chunk waits in its window; one without a live window, as after a reboot, starts again as a stopped chunk does, whatever the limits, since it goes on parked. A Failure says why a window could not start; those before it run."""
session = tmux.session_name(tmux.EPIC, epic.key)
found, waits = chunks(issues, epic.team)
found, waits = chunks(issues, epic.team, epic.unblocking)
if finishing:
found.append(Chunk(epic.key, None))
started: list[str] = []