Re-rank Jira's backlog to match an epic's ranking, moving only the issues the loop filed
This commit is contained in:
@@ -23,6 +23,7 @@ EPIC_URL = f"{SITE}/rest/api/3/issue/ABC-12?fields=summary"
|
||||
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"
|
||||
TO_DO = {"name": "To Do", "statusCategory": {"key": "new"}}
|
||||
TYPES = {"issueTypes": [{"id": "10001", "name": "Task", "subtask": False}, {"id": "10003", "name": "Subtask", "subtask": True}]}
|
||||
|
||||
@@ -59,6 +60,8 @@ class FakeJira:
|
||||
return {"key": held["key"], "fields": {"parent": held["fields"]["parent"]}} # type: ignore[index]
|
||||
if method == "POST" and url == ISSUES:
|
||||
return self.created(body)
|
||||
if method == "PUT" and url == RANK:
|
||||
return self.ranked(body)
|
||||
if method == "PUT" and (held := next((issue for issue in self.issues if url == f"{ISSUES}/{issue['key']}"), None)):
|
||||
assert isinstance(body, dict)
|
||||
added = [change["add"] for change in body["update"]["labels"]]
|
||||
@@ -87,6 +90,15 @@ class FakeJira:
|
||||
self.issues.append({"key": key, "fields": {"summary": fields["summary"], "description": fields.get("description"), "labels": fields["labels"], "assignee": None, "status": TO_DO, "parent": {"key": parent}, "issuelinks": []}, "properties": {entry["key"]: entry["value"] for entry in body["properties"]}})
|
||||
return {"id": "1", "key": key}
|
||||
|
||||
def ranked(self, body: object) -> object:
|
||||
"""Moves the one issue named just before or just after another, and answers no body, as Jira does for a rank it made."""
|
||||
assert isinstance(body, dict)
|
||||
[key], other = body["issues"], body.get("rankBeforeIssue") or body["rankAfterIssue"]
|
||||
moved = next(issue for issue in self.issues if issue["key"] == key)
|
||||
self.issues.remove(moved)
|
||||
self.issues.insert(next(place for place, issue in enumerate(self.issues) if issue["key"] == other) + ("rankAfterIssue" in body), moved)
|
||||
return None
|
||||
|
||||
def change(self, key: str, **fields: object) -> None:
|
||||
next(issue for issue in self.issues if issue["key"] == key)["fields"].update(fields) # type: ignore[union-attr]
|
||||
|
||||
@@ -231,6 +243,20 @@ class Jira(Case):
|
||||
store = JiraEpic(Epic(SITE, "ABC-99"), self.env_file, self.jira, to_markdown, to_adf)
|
||||
self.assertEqual(store.read(), Failure(f"cannot read the epic ABC-99: Jira answered 404 for GET {SITE}/rest/api/3/issue/ABC-99?fields=summary"))
|
||||
|
||||
def test_a_rank_jira_refuses_fails_with_its_reason_and_ranks_nothing(self) -> None:
|
||||
store = self.new_store()
|
||||
first, second = (store.file("ABC-12", f"Item {n}.", "", ()) for n in range(2))
|
||||
for answer, reason in (
|
||||
(Failure("Jira answered 403"), "Jira answered 403"),
|
||||
({"entries": [{"issueKey": second, "status": 400, "errors": ["Rank is not configured"]}]}, "Rank is not configured"),
|
||||
):
|
||||
with self.subTest(answer=answer):
|
||||
self.jira.answers[("PUT", RANK)] = answer
|
||||
self.assertEqual(store.rank(str(second), str(first)), Failure(reason))
|
||||
read = store.read()
|
||||
assert isinstance(read, list), read
|
||||
self.assertEqual([issue.key for issue in read], [first, second])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user