Move a parent whose sub-tasks a person filed once they have landed or are done
CI / tests (pull_request) Failing after 2m53s

This commit is contained in:
2026-11-20 23:54:08 +01:00
parent 49964b5d64
commit 0281c78d14
16 changed files with 275 additions and 14 deletions
+16
View File
@@ -16,6 +16,9 @@ class EpicStoreContract:
assertIsNone: typing.Callable[..., None]
subTest: typing.Callable[..., typing.ContextManager[None]]
# The name of a transition the tracker offers an open issue, which leads to the done status "Done".
transition = "Done"
def new_store(self) -> EpicStore:
raise NotImplementedError
@@ -193,6 +196,19 @@ class EpicStoreContract:
self.assertIsInstance(store.move_issue("ZZZ-1", "Done"), Failure)
self.assertEqual([issue.status for issue in self.issues(store)], ["To Do"])
def test_moves_a_child_issue_or_a_sub_task_by_the_transition_named_and_answers_the_status_it_leads_to(self) -> None:
store = self.new_store()
child = self.filed(store, store.epic_key, "Count the runs.")
task = self.filed(store, child, "Count them in the api.")
self.assertEqual([store.move_issue_by(task, self.transition), store.move_issue_by(child, self.transition)], ["Done", "Done"])
self.assertEqual({issue.key: (issue.status, issue.done) for issue in self.issues(store)}, {child: ("Done", True), task: ("Done", True)})
def test_refuses_to_move_an_issue_outside_the_epic_by_a_transition(self) -> None:
store = self.new_store()
self.filed(store, store.epic_key, "Count the runs.")
self.assertIsInstance(store.move_issue_by("ZZZ-1", self.transition), Failure)
self.assertEqual([issue.status for issue in self.issues(store)], ["To Do"])
def test_finishes_a_sub_task_of_a_child_issue_and_leaves_its_parent_open(self) -> None:
store = self.new_store()
child = self.filed(store, store.epic_key, "Count the runs.")
+10
View File
@@ -126,6 +126,16 @@ class MemoryEpic:
self.writes.append(f"move {key} to {status}")
return None
def move_issue_by(self, key: str, transition: str) -> str | Failure:
# The fake holds no workflow: a transition leads to the status of its own name.
if self.fails:
return Failure(self.fails)
if self.within(key) is None:
return no_child(self.epic_key, key, "moved")
self.change(key, status=transition, done=transition.casefold() == "done")
self.writes.append(f"move {key} by {transition}")
return transition
def finish_issue(self, key: str) -> None | Failure:
if self.fails:
return Failure(self.fails)
+8 -1
View File
@@ -10,7 +10,7 @@ from project_config.settings import DEFAULT_ISSUE_TYPE, Epic, Finish, JIRA_FINDI
from atlassian.jira import DONE, entry_of, finishing_transition, ISSUE_KEY, issue_type_refusal, issue_types_of, MAX_PAGES, move_refusal, PERHAPS_FILED, PERHAPS_MOVED, project_of, rank_refusal, searched, SHAPE, status_category, unshaped
from do_epic.backend.protocol import EpicIssue, no_blocker, no_child, no_parent, no_scores, no_words, unfit, unfit_label
from failure import Failure
from do_epic.backend.jira_status import moved_to
from do_epic.backend.jira_status import moved_by, moved_to
from plan.todo_table import MOVES
from do_epic.repo_pick import REVIEW_LABEL
from do_epic.backend.jira_start import Start, started
@@ -215,6 +215,13 @@ class JiraEpic:
within = self.within(key, authorization, "move", "moved")
return within if isinstance(within, Failure) else moved_to(self.epic.site, key, status, authorization, self.http)
def move_issue_by(self, key: str, transition: str) -> str | Failure:
authorization = basic_auth(self.env_file)
if isinstance(authorization, Failure):
return authorization
within = self.within(key, authorization, "move", "moved")
return within if isinstance(within, Failure) else moved_by(self.epic.site, key, transition, authorization, self.http)
def finish_issue(self, key: str) -> None | Failure:
authorization = basic_auth(self.env_file)
if isinstance(authorization, Failure):
+17 -1
View File
@@ -1,4 +1,4 @@
"""Moves a Jira issue to a status by name, for a team whose own automation doesn't see the move's cause, such as a pull request into an epic's working branch."""
"""Moves a Jira issue to a status by name, or by a transition by name, for a team whose own automation doesn't see the move's cause, such as a pull request into an epic's working branch."""
import typing
from failure import Failure
@@ -29,3 +29,19 @@ def moved_to(site: str, key: str, status: str, authorization: str, http: Http) -
return Failure(f"{key} has no transition to the status {status!r} from its status {now!r}, " + (f"only {others}" if offers else "nor any other the account may make"))
moved = http("POST", f"{site}/rest/api/3/issue/{key}/transitions", authorization, {"transition": {"id": leading[0]}})
return Failure(f"cannot move {key} to {status!r}: {moved.reason}") if isinstance(moved, Failure) else None
def moved_by(site: str, key: str, transition: str, authorization: str, http: Http) -> str | Failure:
"""Moves the issue named key by the transition named transition, in upper or lower case. The name of the status the transition leads to; why Jira did not take the move."""
offered = http("GET", f"{site}/rest/api/3/issue/{key}/transitions", authorization, None)
if isinstance(offered, Failure):
return Failure(f"cannot read {key}'s transitions: {offered.reason}")
offers = offers_of(offered, key)
if isinstance(offers, Failure):
return offers
named = [(id_, to) for id_, name, to, _ in offers if name.casefold() == transition.casefold()]
if not named:
others = " and ".join(f"{name!r} to {to!r}" for _, name, to, _ in offers)
return Failure(f"{key} has no transition {transition!r} from its status, " + (f"only {others}" if offers else "nor any other the account may make"))
moved = http("POST", f"{site}/rest/api/3/issue/{key}/transitions", authorization, {"transition": {"id": named[0][0]}})
return Failure(f"cannot move {key} by {transition!r}: {moved.reason}") if isinstance(moved, Failure) else named[0][1]
+3
View File
@@ -73,6 +73,9 @@ class EpicStore(typing.Protocol):
def move_issue(self, key: str, status: str) -> None | Failure:
"""Moves the epic's child issue named key, or a sub-task of one, to the status named status, in upper or lower case; one already there stays as it is. An issue outside the epic is refused. A Failure says why the move could not be made, such as a workflow that gives no way from the issue's status to that one."""
def move_issue_by(self, key: str, transition: str) -> str | Failure:
"""Moves the epic's child issue named key, or a sub-task of one, by the workflow transition named transition, and answers the name of the status it leads to. An issue outside the epic is refused. A Failure says why the move could not be made, such as a workflow that offers the issue no transition of that name from its status."""
def finish_issue(self, key: str) -> None | Failure:
"""Moves the epic's child issue named key, or a sub-task of one, to a done status, so that read answers it as done; one already done stays as it is. An issue outside the epic is refused. A Failure says why the move could not be made: the issue's workflow gives no way to a done status, gives several the backend cannot choose between, or refuses the move."""
+31
View File
@@ -190,6 +190,8 @@ class Case(unittest.TestCase):
class JiraEpicContract(Case, EpicStoreContract):
transition = "Mark as done"
def assign(self, store: JiraEpic, key: str, name: str) -> None: # type: ignore[override]
self.jira.change(key, assignee={"accountId": "5b10a2844c20165700ede21g", "displayName": name})
@@ -407,6 +409,35 @@ class Jira(Case):
self.assertIsNone(store.move_issue(key, "Code Review"))
self.assertEqual(self.jira.transitioned, ["51"])
def test_moves_an_issue_by_the_transition_named_in_any_case_and_answers_the_status_it_leads_to(self) -> None:
store = self.new_store()
key = store.file("ABC-12", "Count the runs.", "", ())
ready = {"name": "Release Ready", "statusCategory": {"key": "indeterminate"}}
self.jira.workflow = [{"id": "31", "name": "Mark as done", "to": DONE}, {"id": "61", "name": "Ready for release", "to": ready}]
self.assertEqual(store.move_issue_by(key, "ready for release"), "Release Ready")
self.assertEqual((self.jira.transitioned, self.jira.issues[0]["fields"]["status"]), (["61"], ready)) # type: ignore[index]
def test_a_transition_the_workflow_does_not_offer_fails_naming_what_it_offers(self) -> None:
store = self.new_store()
key = store.file("ABC-12", "Count the runs.", "", ())
self.assertEqual(store.move_issue_by(key, "Release Ready"), Failure(f"{key} has no transition 'Release Ready' from its status, only 'Mark as done' to 'Done'"))
self.jira.workflow = []
self.assertEqual(store.move_issue_by(key, "Release Ready"), Failure(f"{key} has no transition 'Release Ready' from its status, nor any other the account may make"))
self.assertEqual(self.jira.transitioned, [])
def test_a_move_by_a_transition_that_jira_refuses_or_cannot_be_read_fails_with_the_reason(self) -> None:
store = self.new_store()
key = store.file("ABC-12", "Count the runs.", "", ())
self.jira.issues.append({"key": "ABC-61", "fields": {"summary": "Other.", "description": None, "labels": [], "assignee": None, "status": TO_DO, "parent": None, "issuelinks": []}})
self.assertEqual(store.move_issue_by("ABC-61", "Mark as done"), Failure("ABC-61 is not one of the child issues of the epic ABC-12, so it cannot be moved"))
transitions = f"{ISSUES}/{key}/transitions"
self.jira.answers = {("POST", transitions): Failure("Jira answered 400")}
self.assertEqual(store.move_issue_by(key, "Mark as done"), Failure(f"cannot move {key} by 'Mark as done': Jira answered 400"))
self.jira.answers = {("GET", transitions): Failure("Jira answered 503")}
self.assertEqual(store.move_issue_by(key, "Mark as done"), Failure(f"cannot read {key}'s transitions: Jira answered 503"))
self.jira.answers = {("GET", transitions): {"transitions": [{"id": "31"}]}}
self.assertEqual(store.move_issue_by(key, "Mark as done"), Failure(f"Jira answered {key}'s transitions in a shape other than the one it documents"))
def test_a_move_the_workflow_does_not_offer_fails_naming_what_it_offers(self) -> None:
store = self.new_store()
key = store.file("ABC-12", "Count the runs.", "", ())