Merge origin/main into item-441
This commit is contained in:
@@ -131,21 +131,21 @@ class EpicStoreContract:
|
||||
other = self.filed(store, store.epic_key, "Ship the later thing.")
|
||||
closed = self.filed(store, store.epic_key, "Close the old thing.")
|
||||
self.close(store, closed, "Done")
|
||||
self.assertEqual([store.finish(key), store.finish(closed)], [None, None])
|
||||
self.assertEqual([store.finish_issue(key), store.finish_issue(closed)], [None, None])
|
||||
self.assertEqual({issue.key: issue.done for issue in self.issues(store)}, {key: True, other: False, closed: True})
|
||||
|
||||
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.")
|
||||
task = self.filed(store, child, "Count them in the api.")
|
||||
self.assertIsNone(store.finish(task))
|
||||
self.assertIsNone(store.finish_issue(task))
|
||||
self.assertEqual({issue.key: issue.done for issue in self.issues(store)}, {child: False, task: True})
|
||||
|
||||
def test_refuses_to_finish_an_issue_outside_the_epic(self) -> None:
|
||||
store = self.new_store()
|
||||
child = self.filed(store, store.epic_key, "Count the runs.")
|
||||
self.assertIsInstance(store.finish("ZZZ-1"), Failure)
|
||||
self.assertIsInstance(store.finish("not a key"), Failure)
|
||||
self.assertIsInstance(store.finish_issue("ZZZ-1"), Failure)
|
||||
self.assertIsInstance(store.finish_issue("not a key"), Failure)
|
||||
self.assertEqual([issue.done for issue in self.issues(store)], [False])
|
||||
|
||||
def test_posts_comments_on_a_child_issue_in_order(self) -> None:
|
||||
@@ -164,6 +164,14 @@ class EpicStoreContract:
|
||||
self.assertIsInstance(store.comment("ZZZ-1", "Hello."), Failure)
|
||||
self.assertEqual([self.comments_on(store, key) for key in (child, task)], [[], []])
|
||||
|
||||
def test_closes_the_epic_once_its_summary_is_posted_and_refuses_a_blank_one(self) -> None:
|
||||
store = self.new_store()
|
||||
self.assertEqual(store.closed(), False)
|
||||
self.assertIsInstance(store.close(" \n"), Failure)
|
||||
self.assertEqual((store.closed(), self.comments_on(store, "ABC-12")), (False, []))
|
||||
self.assertEqual(store.close("## Shipped\n\nThe import.\n"), None)
|
||||
self.assertEqual((store.closed(), self.comments_on(store, "ABC-12")), (True, ["## Shipped\n\nThe import."]))
|
||||
|
||||
def test_reads_an_issue_without_scores_or_blockers_as_one_with_none(self) -> None:
|
||||
store = self.new_store()
|
||||
key = self.filed(store, store.epic_key, "Count the runs.")
|
||||
|
||||
@@ -7,11 +7,12 @@ 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 and finish fails with it as the reason. comments holds each issue's comments, by key."""
|
||||
"""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."""
|
||||
epic_key: str
|
||||
issues: list[EpicIssue] = dataclasses.field(default_factory=list)
|
||||
comments: dict[str, list[str]] = dataclasses.field(default_factory=dict)
|
||||
fails: str | None = None
|
||||
done: bool = False
|
||||
|
||||
def read(self) -> list[EpicIssue] | Failure:
|
||||
if self.fails:
|
||||
@@ -60,7 +61,19 @@ class MemoryEpic:
|
||||
self.comments.setdefault(key, []).append(text.strip())
|
||||
return None
|
||||
|
||||
def finish(self, key: str) -> None | Failure:
|
||||
def closed(self) -> bool | Failure:
|
||||
return Failure(self.fails) if self.fails else self.done
|
||||
|
||||
def close(self, summary: str) -> None | Failure:
|
||||
if self.fails:
|
||||
return Failure(self.fails)
|
||||
if refused := no_words(summary):
|
||||
return refused
|
||||
self.comments.setdefault(self.epic_key, []).append(summary.strip())
|
||||
self.done = True
|
||||
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}
|
||||
|
||||
+45
-33
@@ -5,15 +5,15 @@ import typing
|
||||
|
||||
from adf_codec.convert import adfs_to_markdown, markdown_to_adf, Refused
|
||||
from atlassian.client import basic_auth, Http, jira_json, ToAdf, ToMarkdown
|
||||
from plan_store.jira_epic import blocked_by_links, DONE, FILED_BY, ISSUE_KEY, ISSUE_TYPE, offer_of, project_of, PROPERTY, rank_refusal, scores, searched
|
||||
from project_config.settings import Epic, JIRA_FINISH_TRANSITION
|
||||
from plan_store.jira_epic import blocked_by_links, DONE, FILED_BY, finishing_transition, ISSUE_KEY, ISSUE_TYPE, move_refusal, PERHAPS_MOVED, project_of, PROPERTY, rank_refusal, scores, searched
|
||||
from project_config.settings import Epic, Finish, JIRA_FINISH_STATUS, JIRA_FINISH_TRANSITION
|
||||
from do_epic.backend.protocol import EpicIssue, no_child, no_parent, no_words, unfit, unfit_label
|
||||
from failure import Failure
|
||||
|
||||
FIELDS = ["summary", "description", "labels", "assignee", "status", "parent", "issuelinks"]
|
||||
# How many child issues one search for sub-tasks names, which keeps its JQL well inside the length Jira takes.
|
||||
PARENTS_PER_SEARCH = 50
|
||||
PERHAPS_MOVED = "unless Jira refused the request, {key} may be done: read it in Jira before moving it again"
|
||||
NO_FINISH = "do-epic's settings name no transition to {to} by: set `{transition}` and `{status}` in ~/.claude-projects/do-epic/config.toml, to the names Jira shows, such as \"Mark as done\" and \"Done\""
|
||||
PERHAPS_FILED = "unless Jira refused the request, the issue may exist: look under {parent} before filing it again"
|
||||
|
||||
|
||||
@@ -26,14 +26,13 @@ class Found:
|
||||
|
||||
@dataclasses.dataclass(frozen=True)
|
||||
class JiraEpic:
|
||||
"""The issues of a Jira epic, read and filed with the credentials env_file holds."""
|
||||
"""The issues of a Jira epic, read and filed with the credentials env_file holds. finish says how the epic itself closes; None where the machine's settings don't say."""
|
||||
epic: Epic
|
||||
env_file: pathlib.Path
|
||||
http: Http = jira_json
|
||||
to_markdown: ToMarkdown = adfs_to_markdown
|
||||
to_adf: ToAdf = markdown_to_adf
|
||||
# The name of the transition to finish an issue by, where its status offers several to a done status.
|
||||
finish_by: str | None = None
|
||||
finish: Finish | None = None
|
||||
|
||||
@property
|
||||
def epic_key(self) -> str:
|
||||
@@ -119,7 +118,41 @@ class JiraEpic:
|
||||
posted = self.http("POST", f"{self.epic.site}/rest/api/3/issue/{key}/comment", authorization, {"body": body})
|
||||
return Failure(f"cannot comment on {key}: {posted.reason}") if isinstance(posted, Failure) else None
|
||||
|
||||
def finish(self, key: str) -> None | Failure:
|
||||
def closed(self) -> bool | Failure:
|
||||
authorization = basic_auth(self.env_file)
|
||||
if isinstance(authorization, Failure):
|
||||
return authorization
|
||||
answered = self.http("GET", f"{self.epic.site}/rest/api/3/issue/{self.epic_key}?fields=status", authorization, None)
|
||||
if isinstance(answered, Failure):
|
||||
return Failure(f"cannot read {self.epic_key}'s status: {answered.reason}")
|
||||
try:
|
||||
category = answered["fields"]["status"]["statusCategory"]["key"] # type: ignore[index]
|
||||
except (KeyError, TypeError) as failure:
|
||||
return Failure(f"{self.epic_key}'s status is not in the shape Jira Cloud's REST API version 3 documents: {failure!r}")
|
||||
return bool(category == "done")
|
||||
|
||||
def close(self, summary: str) -> None | Failure:
|
||||
if self.finish is None:
|
||||
return Failure(NO_FINISH.format(to="close an epic", transition=JIRA_FINISH_TRANSITION, status=JIRA_FINISH_STATUS))
|
||||
authorization = basic_auth(self.env_file)
|
||||
if isinstance(authorization, Failure):
|
||||
return authorization
|
||||
if refused := no_words(summary):
|
||||
return refused
|
||||
body = self.to_adf(summary)
|
||||
if isinstance(body, Failure):
|
||||
return Failure(f"cannot convert the summary to a Jira comment: {body.reason}")
|
||||
# The transition is read before the comment is posted, so an epic that cannot move gets no summary.
|
||||
transition = finishing_transition(self.epic.site, self.epic_key, self.finish, authorization, self.http)
|
||||
if isinstance(transition, Failure):
|
||||
return transition
|
||||
posted = self.http("POST", f"{self.epic.site}/rest/api/3/issue/{self.epic_key}/comment", authorization, {"body": body})
|
||||
if isinstance(posted, Failure):
|
||||
return Failure(f"cannot comment on {self.epic_key}: {posted.reason}")
|
||||
refused_move = move_refusal(self.epic.site, self.epic_key, transition, self.finish, authorization, self.http)
|
||||
return Failure(f"posted the summary on {self.epic_key}, but {refused_move}; close the epic in Jira rather than posting the summary again") if refused_move else None
|
||||
|
||||
def finish_issue(self, key: str) -> None | Failure:
|
||||
authorization = basic_auth(self.env_file)
|
||||
if isinstance(authorization, Failure):
|
||||
return authorization
|
||||
@@ -135,15 +168,13 @@ class JiraEpic:
|
||||
return no_child(self.epic_key, key, "finished")
|
||||
if done:
|
||||
return None
|
||||
url = f"{self.epic.site}/rest/api/3/issue/{key}/transitions"
|
||||
offered = self.http("GET", url, authorization, None)
|
||||
if isinstance(offered, Failure):
|
||||
return Failure(f"cannot read {key}'s transitions: {offered.reason}")
|
||||
transition = done_transition(offered, key, self.finish_by)
|
||||
if self.finish is None:
|
||||
return Failure(NO_FINISH.format(to="finish an issue", transition=JIRA_FINISH_TRANSITION, status=JIRA_FINISH_STATUS))
|
||||
transition = finishing_transition(self.epic.site, key, self.finish, authorization, self.http)
|
||||
if isinstance(transition, Failure):
|
||||
return transition
|
||||
moved = self.http("POST", url, authorization, {"transition": {"id": transition}})
|
||||
return Failure(f"cannot move {key} to done: {moved.reason}; {PERHAPS_MOVED.format(key=key)}") if isinstance(moved, Failure) else None
|
||||
refused = move_refusal(self.epic.site, key, transition, self.finish, authorization, self.http)
|
||||
return Failure(f"{refused}; {PERHAPS_MOVED.format(key=key)}") if refused else None
|
||||
|
||||
def not_a_parent(self, parent: str, authorization: str) -> Failure | None:
|
||||
"""Why nothing can be filed under parent; None where it is the epic or one of its child issues."""
|
||||
@@ -210,25 +241,6 @@ class JiraEpic:
|
||||
return Failure(f"{project} has no sub-task issue type; turn sub-tasks on in Jira") if found is None else {"id": found}
|
||||
|
||||
|
||||
def done_transition(offered: object, key: str, named: str | None) -> str | Failure:
|
||||
"""The ID of the transition that finishes the issue named key, among those Jira offered, which are the ones its status has and the account may make. It is the one that leads to a done status, or where there are several, the one called named; or why Jira offered no such move. Which of several finishes an issue is the team's workflow, so none is picked without a name."""
|
||||
raw = offered.get("transitions") if isinstance(offered, dict) else None
|
||||
found = [offer for each in raw if (offer := offer_of(each))] if isinstance(raw, list) else []
|
||||
if not isinstance(raw, list) or len(found) != len(raw):
|
||||
return Failure(f"Jira answered {key}'s transitions in a shape other than the one it documents")
|
||||
closing = [(id_, name, status) for id_, name, status, category in found if category == DONE]
|
||||
chosen = closing if len(closing) == 1 else [move for move in closing if move[1] == named]
|
||||
if len(chosen) == 1:
|
||||
return chosen[0][0]
|
||||
listed = " and ".join(f"{name!r} to {status!r}" for _, name, status in closing)
|
||||
if closing and not named:
|
||||
return Failure(f"{key}'s status has more than one transition to a done status, {listed}: name the one to use in `{JIRA_FINISH_TRANSITION}`, in ~/.claude-projects/do-epic/config.toml")
|
||||
if closing:
|
||||
return Failure(f"{key}'s status has no transition called {named!r} to a done status, only {listed}: correct `{JIRA_FINISH_TRANSITION}`, in ~/.claude-projects/do-epic/config.toml")
|
||||
others = " and ".join(f"{name!r} to {status!r}" for _, name, status, _ in found)
|
||||
return Failure(f"{key}'s status has no transition to a done status" + (f", only {others}" if others else "") + ": Jira lists only the transitions the account may make, so move the issue in Jira, or let the account transition issues")
|
||||
|
||||
|
||||
def found_of(raw: object) -> Found | Failure:
|
||||
"""The issue in one entry of a search's answer, or which issue is not in the shape Jira documents."""
|
||||
key = raw.get("key") if isinstance(raw, dict) else None
|
||||
|
||||
@@ -63,10 +63,17 @@ class EpicStore(typing.Protocol):
|
||||
def comment(self, key: str, text: str) -> None | Failure:
|
||||
"""Posts text, markdown, as a comment on the epic's child issue named key, for the people who work the epic to read. A sub-task, an issue outside the epic, or an empty or blank text is refused."""
|
||||
|
||||
def finish(self, key: str) -> None | Failure:
|
||||
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."""
|
||||
|
||||
|
||||
def closed(self) -> bool | Failure:
|
||||
"""Whether the epic itself is in a status the tracker counts as done."""
|
||||
|
||||
def close(self, summary: str) -> None | Failure:
|
||||
"""Posts summary, markdown, as a comment on the epic, then moves the epic to a status the tracker counts as done. Before anything is posted, it refuses a blank summary, and an epic the tracker cannot move to such a status. Where the move fails after the comment is posted, the Failure says so."""
|
||||
|
||||
|
||||
def unfit(summary: str, labels: tuple[str, ...]) -> Failure | None:
|
||||
"""Why no tracker can file an issue with this summary and these labels; None where a tracker can file it."""
|
||||
if not summary.strip() or "\n" in summary:
|
||||
|
||||
@@ -55,14 +55,14 @@ class Finishing(unittest.TestCase):
|
||||
def test_finishes_an_issue_to_the_status_done(self) -> None:
|
||||
store = MemoryEpic("ABC-12")
|
||||
key = store.file("ABC-12", "Count the runs.", "", ())
|
||||
self.assertIsNone(store.finish(str(key)))
|
||||
self.assertIsNone(store.finish_issue(str(key)))
|
||||
self.assertEqual([(issue.status, issue.done) for issue in store.issues], [("Done", True)])
|
||||
|
||||
def test_refuses_to_finish_an_issue_outside_the_epic_saying_so(self) -> None:
|
||||
self.assertEqual(MemoryEpic("ABC-12").finish("ZZZ-1"), Failure("ZZZ-1 is not one of the child issues of the epic ABC-12, so it cannot be finished"))
|
||||
self.assertEqual(MemoryEpic("ABC-12").finish_issue("ZZZ-1"), Failure("ZZZ-1 is not one of the child issues of the epic ABC-12, so it cannot be finished"))
|
||||
|
||||
def test_fails_to_finish_with_the_reason_given(self) -> None:
|
||||
self.assertEqual(MemoryEpic("ABC-12", fails="Jira is down").finish("ABC-100"), Failure("Jira is down"))
|
||||
self.assertEqual(MemoryEpic("ABC-12", fails="Jira is down").finish_issue("ABC-100"), Failure("Jira is down"))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
@@ -9,7 +9,7 @@ import unittest.mock
|
||||
|
||||
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[2]))
|
||||
|
||||
from project_config.settings import Epic
|
||||
from project_config.settings import Epic, Finish
|
||||
from do_epic.backend.contract import EpicStoreContract
|
||||
from failure import Failure
|
||||
from plan_store import jira_epic
|
||||
@@ -24,8 +24,11 @@ ISSUE_TYPES = f"{SITE}/rest/api/3/issue/createmeta/ABC/issuetypes"
|
||||
SEARCH = f"{SITE}/rest/api/3/search/jql"
|
||||
ISSUES = f"{SITE}/rest/api/3/issue"
|
||||
RANK = f"{SITE}/rest/agile/1.0/issue/rank"
|
||||
DONE = {"name": "Done", "statusCategory": {"key": "done"}}
|
||||
TO_DO = {"name": "To Do", "statusCategory": {"key": "new"}}
|
||||
DONE = {"name": "Done", "statusCategory": {"key": "done"}}
|
||||
TRANSITIONS = f"{ISSUES}/ABC-12/transitions"
|
||||
EPIC_COMMENT = f"{ISSUES}/ABC-12/comment"
|
||||
EPIC_STATUS = f"{ISSUES}/ABC-12?fields=status"
|
||||
TYPES = {"issueTypes": [{"id": "10001", "name": "Task", "subtask": False}, {"id": "10003", "name": "Subtask", "subtask": True}]}
|
||||
|
||||
|
||||
@@ -49,6 +52,8 @@ class FakeJira:
|
||||
transitioned: list[str] = dataclasses.field(default_factory=list)
|
||||
# The transitions Jira offers an issue that isn't done.
|
||||
workflow: list[dict[str, object]] = dataclasses.field(default_factory=lambda: [{"id": "31", "name": "Mark as done", "to": DONE}])
|
||||
# The epic's own status, which the transition "Mark as done" moves to DONE.
|
||||
epic_status: dict[str, object] = dataclasses.field(default_factory=lambda: dict(TO_DO))
|
||||
|
||||
def __call__(self, method: str, url: str, authorization: str, body: object) -> object:
|
||||
self.calls.append((method, url))
|
||||
@@ -58,6 +63,18 @@ class FakeJira:
|
||||
return self.answers[method, url]
|
||||
if method == "GET" and url == EPIC_URL:
|
||||
return {"key": "ABC-12"}
|
||||
if method == "GET" and url == EPIC_STATUS:
|
||||
return {"key": "ABC-12", "fields": {"status": self.epic_status}}
|
||||
if method == "GET" and url == TRANSITIONS:
|
||||
return {"transitions": [] if self.epic_status == DONE else [{"id": "31", "name": "Mark as done", "to": DONE}, {"id": "21", "name": "Start", "to": {"name": "In Progress", "statusCategory": {"key": "indeterminate"}}}]}
|
||||
if method == "POST" and url == TRANSITIONS:
|
||||
assert body == {"transition": {"id": "31"}}, body
|
||||
self.epic_status = DONE
|
||||
return None
|
||||
if method == "POST" and url == EPIC_COMMENT:
|
||||
assert isinstance(body, dict)
|
||||
self.comments.setdefault("ABC-12", []).append(body["body"])
|
||||
return {"id": "1"}
|
||||
if method == "GET" and url == ISSUE_TYPES:
|
||||
return TYPES
|
||||
if method == "POST" and url == SEARCH:
|
||||
@@ -140,7 +157,7 @@ class Case(unittest.TestCase):
|
||||
self.jira = FakeJira()
|
||||
|
||||
def new_store(self) -> JiraEpic:
|
||||
return JiraEpic(EPIC, self.env_file, self.jira, to_markdown, to_adf)
|
||||
return JiraEpic(EPIC, self.env_file, self.jira, to_markdown, to_adf, Finish("Mark as done", "Done"))
|
||||
|
||||
|
||||
class JiraEpicContract(Case, EpicStoreContract):
|
||||
@@ -166,52 +183,73 @@ class JiraEpicContract(Case, EpicStoreContract):
|
||||
|
||||
|
||||
class Jira(Case):
|
||||
def test_finishes_an_issue_by_the_one_transition_that_leads_to_a_done_status(self) -> None:
|
||||
def test_closes_the_epic_by_the_transition_the_settings_name_after_the_summary(self) -> None:
|
||||
self.assertEqual(self.new_store().close("Shipped."), None)
|
||||
self.assertEqual(self.jira.calls[-3:], [("GET", TRANSITIONS), ("POST", EPIC_COMMENT), ("POST", TRANSITIONS)])
|
||||
|
||||
def test_posts_no_summary_on_an_epic_it_cannot_close(self) -> None:
|
||||
unnamed = JiraEpic(EPIC, self.env_file, self.jira, to_markdown, to_adf)
|
||||
wrong_status = JiraEpic(EPIC, self.env_file, self.jira, to_markdown, to_adf, Finish("Start", "Done"))
|
||||
no_such = JiraEpic(EPIC, self.env_file, self.jira, to_markdown, to_adf, Finish("Close", "Done"))
|
||||
unconverted = JiraEpic(EPIC, self.env_file, self.jira, to_markdown, lambda markdown: Failure("adf-codec refused it"), Finish("Mark as done", "Done"))
|
||||
for store, reason in (
|
||||
(unnamed, "do-epic's settings name no transition to close an epic by: set `jira-finish-transition` and `jira-finish-status` in ~/.claude-projects/do-epic/config.toml, to the names Jira shows, such as \"Mark as done\" and \"Done\""),
|
||||
(wrong_status, "ABC-12's transition 'Start' leads to the status 'In Progress', not to 'Done', which `jira-finish-status` names"),
|
||||
(unconverted, "cannot convert the summary to a Jira comment: adf-codec refused it"),
|
||||
):
|
||||
self.assertEqual(store.close("Shipped."), Failure(reason))
|
||||
refused = no_such.close("Shipped.")
|
||||
assert isinstance(refused, Failure)
|
||||
self.assertIn("ABC-12 has no transition 'Close' from its status", refused.reason)
|
||||
self.jira.answers[("GET", TRANSITIONS)] = Failure("Jira answered 503")
|
||||
self.assertEqual(self.new_store().close("Shipped."), Failure("cannot read ABC-12's transitions: Jira answered 503"))
|
||||
self.assertEqual((self.jira.comments, self.jira.epic_status), ({}, TO_DO))
|
||||
|
||||
def test_says_what_was_posted_where_the_comment_or_the_move_fails(self) -> None:
|
||||
self.jira.answers[("POST", EPIC_COMMENT)] = Failure("Jira answered 503")
|
||||
self.assertEqual(self.new_store().close("Shipped."), Failure("cannot comment on ABC-12: Jira answered 503"))
|
||||
self.assertEqual(self.jira.epic_status, TO_DO)
|
||||
del self.jira.answers[("POST", EPIC_COMMENT)]
|
||||
self.jira.answers[("POST", TRANSITIONS)] = Failure("Jira answered 503")
|
||||
self.assertEqual(self.new_store().close("Shipped."), Failure("posted the summary on ABC-12, but cannot move ABC-12 by 'Mark as done': Jira answered 503; close the epic in Jira rather than posting the summary again"))
|
||||
|
||||
def test_says_why_the_epics_status_cannot_be_read(self) -> None:
|
||||
for answer, reason in ((Failure("Jira answered 503"), "cannot read ABC-12's status: Jira answered 503"), ({"fields": {}}, "ABC-12's status is not in the shape Jira Cloud's REST API version 3 documents: KeyError('status')"), (["ABC-12"], "ABC-12's status is not in the shape Jira Cloud's REST API version 3 documents: TypeError('list indices must be integers or slices, not str')")):
|
||||
self.jira.answers[("GET", EPIC_STATUS)] = answer
|
||||
self.assertEqual(self.new_store().closed(), Failure(reason))
|
||||
|
||||
def test_finishes_an_issue_by_the_transition_the_settings_name(self) -> None:
|
||||
store = self.new_store()
|
||||
key = store.file("ABC-12", "Count the runs.", "", ())
|
||||
self.jira.workflow = [{"id": "11", "name": "Start", "to": {"name": "In Progress", "statusCategory": {"key": "indeterminate"}}}, {"id": "31", "name": "Mark as done", "to": DONE}]
|
||||
self.assertIsNone(store.finish(key))
|
||||
self.assertIsNone(store.finish_issue(key))
|
||||
self.assertEqual(self.jira.calls[-1], ("POST", f"{ISSUES}/{key}/transitions"))
|
||||
self.assertEqual(self.jira.issues[0]["fields"]["status"], DONE) # type: ignore[index]
|
||||
self.assertEqual((self.jira.transitioned, self.jira.issues[0]["fields"]["status"]), (["31"], DONE)) # type: ignore[index]
|
||||
|
||||
def test_leaves_an_issue_that_is_done_without_asking_for_its_transitions(self) -> None:
|
||||
store = self.new_store()
|
||||
key = store.file("ABC-12", "Count the runs.", "", ())
|
||||
self.jira.change(key, status=DONE)
|
||||
self.assertIsNone(store.finish(key))
|
||||
self.assertNotIn(("GET", f"{ISSUES}/{key}/transitions"), self.jira.calls)
|
||||
|
||||
def test_a_finish_names_why_no_move_closes_the_issue(self) -> None:
|
||||
key = self.new_store().file("ABC-12", "Count the runs.", "", ())
|
||||
closed = {"name": "Closed", "statusCategory": {"key": "done"}}
|
||||
start = {"id": "11", "name": "Start", "to": {"name": "In Progress", "statusCategory": {"key": "indeterminate"}}}
|
||||
both = [{"id": "31", "name": "Mark as done", "to": DONE}, {"id": "41", "name": "Close", "to": closed}]
|
||||
config = " in `jira-finish-transition`, in ~/.claude-projects/do-epic/config.toml"
|
||||
for workflow, named, reason in (
|
||||
([start, {"id": "12", "name": "Pause", "to": {"name": "On Hold", "statusCategory": {"key": "indeterminate"}}}], None, f"{key}'s status has no transition to a done status, only 'Start' to 'In Progress' and 'Pause' to 'On Hold': Jira lists only the transitions the account may make, so move the issue in Jira, or let the account transition issues"),
|
||||
([start], None, f"{key}'s status has no transition to a done status, only 'Start' to 'In Progress': Jira lists only the transitions the account may make, so move the issue in Jira, or let the account transition issues"),
|
||||
([], None, f"{key}'s status has no transition to a done status: Jira lists only the transitions the account may make, so move the issue in Jira, or let the account transition issues"),
|
||||
(both, None, f"{key}'s status has more than one transition to a done status, 'Mark as done' to 'Done' and 'Close' to 'Closed': name the one to use{config}"),
|
||||
(both, "Resolve", f"{key}'s status has no transition called 'Resolve' to a done status, only 'Mark as done' to 'Done' and 'Close' to 'Closed': correct `jira-finish-transition`, in ~/.claude-projects/do-epic/config.toml"),
|
||||
([start], "Close", f"{key}'s status has no transition to a done status, only 'Start' to 'In Progress': Jira lists only the transitions the account may make, so move the issue in Jira, or let the account transition issues"),
|
||||
):
|
||||
with self.subTest(workflow=workflow, named=named):
|
||||
self.jira.workflow = workflow # type: ignore[assignment]
|
||||
self.assertEqual(JiraEpic(EPIC, self.env_file, self.jira, to_markdown, to_adf, named).finish(key), Failure(reason))
|
||||
self.assertEqual(self.jira.issues[0]["fields"]["status"], TO_DO) # type: ignore[index]
|
||||
|
||||
def test_finishes_by_the_transition_the_config_names_where_several_lead_to_a_done_status(self) -> None:
|
||||
def test_finishes_by_the_named_transition_where_several_lead_to_a_done_status(self) -> None:
|
||||
key = self.new_store().file("ABC-12", "Count the runs.", "", ())
|
||||
self.jira.workflow = [{"id": "31", "name": "Resolve", "to": DONE}, {"id": "41", "name": "Close", "to": {"name": "Closed", "statusCategory": {"key": "done"}}}]
|
||||
self.assertIsNone(JiraEpic(EPIC, self.env_file, self.jira, to_markdown, to_adf, "Close").finish(key))
|
||||
self.assertEqual(self.jira.calls[-1], ("POST", f"{ISSUES}/{key}/transitions"))
|
||||
self.assertIsNone(JiraEpic(EPIC, self.env_file, self.jira, to_markdown, to_adf, Finish("Close", "Closed")).finish_issue(key))
|
||||
self.assertEqual(self.jira.transitioned, ["41"])
|
||||
|
||||
def test_finishes_by_the_one_transition_to_a_done_status_whatever_name_the_config_gives(self) -> None:
|
||||
def test_leaves_an_issue_that_is_done_without_asking_for_its_transitions(self) -> None:
|
||||
store = JiraEpic(EPIC, self.env_file, self.jira, to_markdown, to_adf)
|
||||
key = self.new_store().file("ABC-12", "Count the runs.", "", ())
|
||||
self.jira.workflow = [{"id": "31", "name": "Resolve", "to": DONE}]
|
||||
self.assertIsNone(JiraEpic(EPIC, self.env_file, self.jira, to_markdown, to_adf, "Close").finish(key))
|
||||
self.assertEqual(self.jira.transitioned, ["31"])
|
||||
self.jira.change(key, status=DONE)
|
||||
self.assertIsNone(store.finish_issue(key))
|
||||
self.assertNotIn(("GET", f"{ISSUES}/{key}/transitions"), self.jira.calls)
|
||||
|
||||
def test_a_finish_names_why_no_move_finishes_the_issue(self) -> None:
|
||||
key = self.new_store().file("ABC-12", "Count the runs.", "", ())
|
||||
unnamed = JiraEpic(EPIC, self.env_file, self.jira, to_markdown, to_adf)
|
||||
wrong_status = JiraEpic(EPIC, self.env_file, self.jira, to_markdown, to_adf, Finish("Mark as done", "Closed"))
|
||||
no_such = JiraEpic(EPIC, self.env_file, self.jira, to_markdown, to_adf, Finish("Close", "Done"))
|
||||
self.assertEqual(unnamed.finish_issue(key), Failure("do-epic's settings name no transition to finish an issue by: set `jira-finish-transition` and `jira-finish-status` in ~/.claude-projects/do-epic/config.toml, to the names Jira shows, such as \"Mark as done\" and \"Done\""))
|
||||
self.assertEqual(wrong_status.finish_issue(key), Failure(f"{key}'s transition 'Mark as done' leads to the status 'Done', not to 'Closed', which `jira-finish-status` names"))
|
||||
refused = no_such.finish_issue(key)
|
||||
assert isinstance(refused, Failure)
|
||||
self.assertIn(f"{key} has no transition 'Close' from its status", refused.reason)
|
||||
self.assertEqual((self.jira.transitioned, self.jira.issues[0]["fields"]["status"]), ([], TO_DO)) # type: ignore[index]
|
||||
|
||||
def test_refuses_to_finish_a_sub_task_of_an_issue_that_is_no_child_of_the_epic_or_an_issue_without_a_parent(self) -> None:
|
||||
store = self.new_store()
|
||||
@@ -220,35 +258,35 @@ class Jira(Case):
|
||||
self.jira.issues.append({"key": key, "fields": fields})
|
||||
for key in ("ABC-50", "ABC-61"):
|
||||
with self.subTest(key=key):
|
||||
self.assertEqual(store.finish(key), Failure(f"{key} is not one of the child issues of the epic ABC-12, so it cannot be finished"))
|
||||
self.assertEqual(store.finish_issue(key), Failure(f"{key} is not one of the child issues of the epic ABC-12, so it cannot be finished"))
|
||||
self.assertNotIn("POST", [method for method, _ in self.jira.calls])
|
||||
|
||||
def test_a_finish_jira_refuses_says_so_and_that_the_issue_may_have_moved(self) -> None:
|
||||
store = self.new_store()
|
||||
key = store.file("ABC-12", "Count the runs.", "", ())
|
||||
self.jira.answers[("POST", f"{ISSUES}/{key}/transitions")] = Failure("Jira answered 400: Resolution is required")
|
||||
self.assertEqual(store.finish(key), Failure(f"cannot move {key} to done: Jira answered 400: Resolution is required; unless Jira refused the request, {key} may be done: read it in Jira before moving it again"))
|
||||
self.assertEqual(store.finish_issue(key), Failure(f"cannot move {key} by 'Mark as done': Jira answered 400: Resolution is required; unless Jira refused the request, the issue may have moved: look at {key} before finishing the item again"))
|
||||
|
||||
def test_a_finish_whose_transitions_jira_cannot_give_or_gives_in_another_shape_fails(self) -> None:
|
||||
store = self.new_store()
|
||||
key = store.file("ABC-12", "Count the runs.", "", ())
|
||||
url = ("GET", f"{ISSUES}/{key}/transitions")
|
||||
self.jira.answers[url] = Failure("Jira answered 503")
|
||||
self.assertEqual(store.finish(key), Failure(f"cannot read {key}'s transitions: Jira answered 503"))
|
||||
self.assertEqual(store.finish_issue(key), Failure(f"cannot read {key}'s transitions: Jira answered 503"))
|
||||
for answer in ({"transitions": [{"id": 31}]}, ["Mark as done"], {"transitions": 5}):
|
||||
with self.subTest(answer=answer):
|
||||
self.jira.answers[url] = answer
|
||||
self.assertEqual(store.finish(key), Failure(f"Jira answered {key}'s transitions in a shape other than the one it documents"))
|
||||
self.assertEqual(store.finish_issue(key), Failure(f"Jira answered {key}'s transitions in a shape other than the one it documents"))
|
||||
|
||||
def test_a_finish_whose_issue_or_parent_jira_cannot_read_says_which(self) -> None:
|
||||
store = self.new_store()
|
||||
child = store.file("ABC-12", "Count the runs.", "", ())
|
||||
task = store.file(child, "Count them in the api.", "", ())
|
||||
self.jira.answers[("GET", f"{ISSUES}/{task}?fields=parent,status")] = Failure("Jira answered 503")
|
||||
self.assertEqual(store.finish(task), Failure(f"cannot read {task} to finish it: Jira answered 503"))
|
||||
self.assertEqual(store.finish_issue(task), Failure(f"cannot read {task} to finish it: Jira answered 503"))
|
||||
del self.jira.answers[("GET", f"{ISSUES}/{task}?fields=parent,status")]
|
||||
self.jira.answers[("GET", f"{ISSUES}/{child}?fields=parent,status")] = Failure("Jira answered 503")
|
||||
self.assertEqual(store.finish(task), Failure(f"cannot read {child} to finish its sub-task: Jira answered 503"))
|
||||
self.assertEqual(store.finish_issue(task), Failure(f"cannot read {child} to finish its sub-task: Jira answered 503"))
|
||||
|
||||
def test_reads_the_sub_tasks_of_more_children_than_one_search_names(self) -> None:
|
||||
store = self.new_store()
|
||||
|
||||
Reference in New Issue
Block a user