Re-rank Jira's backlog to match an epic's ranking, moving only the issues the loop filed
This commit is contained in:
@@ -7,7 +7,7 @@ from failure import Failure
|
||||
|
||||
@dataclasses.dataclass
|
||||
class MemoryEpic:
|
||||
"""An epic whose issues rank in the order filed. Where fails is set, every read and filing fails with it as the reason."""
|
||||
"""An epic whose issues rank in the order filed, until one is ranked. Where fails is set, every call fails with it as the reason."""
|
||||
epic_key: str
|
||||
issues: list[EpicIssue] = dataclasses.field(default_factory=list)
|
||||
fails: str | None = None
|
||||
@@ -39,6 +39,16 @@ class MemoryEpic:
|
||||
self.change(key, labels=tuple(sorted({*child.labels, label})))
|
||||
return None
|
||||
|
||||
def rank(self, key: str, other: str, after: bool = False) -> None | Failure:
|
||||
if self.fails:
|
||||
return Failure(self.fails)
|
||||
children = {issue.key: issue for issue in self.issues if issue.parent == self.epic_key}
|
||||
if stray := next((each for each in (key, other) if each not in children), None):
|
||||
return Failure(f"{stray} is not one of the child issues of the epic {self.epic_key}, so it cannot be ranked")
|
||||
self.issues.remove(children[key])
|
||||
self.issues.insert(self.issues.index(children[other]) + after, children[key])
|
||||
return 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]
|
||||
|
||||
Reference in New Issue
Block a user