Start an epic's issues in order of score, scoring each that holds none

This commit is contained in:
Lilleman
2026-11-20 14:30:30 +01:00
parent abaf54bc46
commit 5f2a4b6385
19 changed files with 615 additions and 83 deletions
+24 -4
View File
@@ -1,13 +1,13 @@
"""An epic held in memory, for do-epic's tests and its `--dry-run`, held to contract.py like every backend."""
import dataclasses
from do_epic.backend.protocol import EpicIssue, no_blocker, no_child, no_parent, no_words, unfit, unfit_label
from do_epic.backend.protocol import EpicIssue, no_blocker, no_child, no_parent, no_scores, no_words, unfit, unfit_label
from failure import Failure
@dataclasses.dataclass
class MemoryEpic:
"""An epic whose issues rank in the order filed, until one is ranked. Where fails is set, every read, filing, label, comment, rank, issue finish and closing fails with it as the reason. comments holds each issue's comments, and the epic's, by key. done says whether the epic is closed. writes says each write that succeeded, in order."""
"""An epic whose issues rank in the order filed, until one is ranked. Where fails is set, every read, filing, label, comment, rank, scoring, issue finish and closing fails with it as the reason. comments holds each issue's comments, and the epic's, by key. done says whether the epic is closed. writes says each write that succeeded, in order."""
epic_key: str
issues: list[EpicIssue] = dataclasses.field(default_factory=list)
comments: dict[str, list[str]] = dataclasses.field(default_factory=dict)
@@ -86,11 +86,26 @@ class MemoryEpic:
self.writes.append(f"close the epic: {summary.strip()}")
return None
def set_scores(self, key: str, scores: dict[str, int], moves: str, comment: str) -> None | Failure:
if self.fails:
return Failure(self.fails)
if refused := no_words(comment):
return refused
child = self.within(key)
if child is None:
return no_child(self.epic_key, key, "scored")
fields = no_scores(key, scores, moves, child.scores)
if isinstance(fields, Failure):
return fields
self.change(key, scores=fields.scores, moves=fields.moves)
self.comments.setdefault(key, []).append(comment.strip())
self.writes.append(f"score {key} {', '.join(f'{name} {value}' for name, value in scores.items())}, Moves {moves or 'none'}, with the comment: {comment.strip()}")
return None
def finish_issue(self, key: str) -> None | Failure:
if self.fails:
return Failure(self.fails)
children = {issue.key for issue in self.issues if issue.parent == self.epic_key}
child = next((issue for issue in self.issues if issue.key == key and (issue.parent == self.epic_key or issue.parent in children)), None)
child = self.within(key)
if child is None:
return no_child(self.epic_key, key, "finished")
if not child.done:
@@ -98,6 +113,11 @@ class MemoryEpic:
self.writes.append(f"finish {key}")
return None
def within(self, key: str) -> EpicIssue | None:
"""The epic's child issue named key, or the sub-task of one; None where the epic holds neither."""
children = {issue.key for issue in self.issues if issue.parent == self.epic_key}
return next((issue for issue in self.issues if issue.key == key and (issue.parent == self.epic_key or issue.parent in children)), None)
def change(self, key: str, **fields: object) -> None:
"""Changes the issue named key as a person would in the tracker, such as assignee="Ada Lovelace"."""
self.issues = [dataclasses.replace(issue, **fields) if issue.key == key else issue for issue in self.issues] # type: ignore[arg-type]