Leave a Jira description or a Confluence page as it is where a save hands back the text a read showed
CI / tests (pull_request) Successful in 3m1s
CI / tests (pull_request) Successful in 3m1s
This commit is contained in:
@@ -185,6 +185,13 @@ class JiraPlan:
|
||||
description = self.to_adf(detail)
|
||||
return Failure(f"cannot convert the item's detail to a Jira description: {description.reason}") if isinstance(description, Failure) else description
|
||||
|
||||
def shows(self, issue: Issue, detail: str) -> bool:
|
||||
"""Whether detail is the issue's description as a read shows it. An edit leaves such a description as Jira holds it: converting the markdown back would drop the localIds and spacing paragraphs that the markdown a read shows leaves out."""
|
||||
if issue.description is None:
|
||||
return not detail.strip()
|
||||
texts = self.to_markdown([issue.description])
|
||||
return isinstance(texts, list) and texts[0].strip() == detail.strip()
|
||||
|
||||
def edit(self, id_: int, fields: dict[str, str], detail: str | None, comment: str | None = None) -> Written | Failure:
|
||||
"""Sets the fields and the detail in one request, so Jira takes all of the edit or none, and then posts comment on the issue. `revision_of` says what an edit may set.
|
||||
|
||||
@@ -203,7 +210,7 @@ class JiraPlan:
|
||||
if isinstance(revision, Failure):
|
||||
return revision
|
||||
body = revision.body
|
||||
if detail is not None:
|
||||
if detail is not None and not self.shows(issue, detail):
|
||||
description = self.description_of(detail)
|
||||
if isinstance(description, Failure):
|
||||
return description
|
||||
@@ -217,7 +224,7 @@ class JiraPlan:
|
||||
return version
|
||||
body = body | {"fields": body.get("fields", {}) | {"fixVersions": [{"name": version}]}}
|
||||
url = f"{self.epic.site}/rest/api/3/issue/{key}"
|
||||
edited = self.http("PUT", url, authorization, body)
|
||||
edited = self.http("PUT", url, authorization, body) if body else None
|
||||
if isinstance(edited, Failure):
|
||||
return Failure(f"cannot edit {key}: {edited.reason}; {PERHAPS_EDITED.format(key=key)}")
|
||||
if said is None:
|
||||
|
||||
@@ -500,7 +500,7 @@ class Editing(unittest.TestCase):
|
||||
return adf(markdown)
|
||||
|
||||
def edit(self, id_: int, fields: dict[str, str], detail: str | None = None, comment: str | None = None):
|
||||
return jira_epic.JiraPlan(EPIC, self.env, self.http, text_of, self.to_adf, scoring=Stated()).edit(id_, fields, detail, comment)
|
||||
return jira_epic.JiraPlan(EPIC, self.env, self.http, lambda documents: [text_of(document) for document in documents], self.to_adf, scoring=Stated()).edit(id_, fields, detail, comment)
|
||||
|
||||
def writes(self) -> list[tuple[str, str, object]]:
|
||||
"""Each request that changes Jira, in order."""
|
||||
@@ -518,7 +518,21 @@ class Editing(unittest.TestCase):
|
||||
self.edit(34, {"E": "3"})
|
||||
self.assertEqual([body for _, _, body in self.writes()], [{"fields": {"summary": "Count every run."}}, {"properties": [{"key": "plan-item", "value": PROPERTY | {"E": 3}}]}])
|
||||
|
||||
def test_a_detail_as_the_description_reads_leaves_the_description_as_jira_holds_it(self):
|
||||
# Jira's own spacing paragraph and localIds, which a description converted back from markdown would lose.
|
||||
held = {"type": "doc", "version": 1, "content": [{"type": "paragraph", "attrs": {"localId": "p-1"}, "content": [{"type": "text", "text": "Why it counts."}]}, {"type": "paragraph", "attrs": {"localId": "p-2"}}]}
|
||||
self.open = [issue("ABC-34", scores=PROPERTY, description=held)]
|
||||
self.assertEqual(self.edit(34, {"L": "2"}, "Why it counts.\n"), Written(34))
|
||||
self.assertEqual(self.edit(34, {}, "Why it counts."), Written(34))
|
||||
self.assertEqual(self.writes(), [("PUT", f"{ISSUES}/ABC-34", {"properties": [{"key": "plan-item", "value": PROPERTY | {"L": 2}}]})])
|
||||
|
||||
def test_an_edited_detail_replaces_the_description(self):
|
||||
self.open = [issue("ABC-34", scores=PROPERTY, description=adf("Why it counts."))]
|
||||
self.edit(34, {}, "Why it counts twice.")
|
||||
self.assertEqual(self.writes(), [("PUT", f"{ISSUES}/ABC-34", {"fields": {"description": adf("Why it counts twice.")}})])
|
||||
|
||||
def test_an_empty_detail_removes_the_description(self):
|
||||
self.open = [issue("ABC-34", scores=PROPERTY, description=adf("Why it counts."))]
|
||||
self.edit(34, {}, " \n")
|
||||
self.assertEqual(self.writes(), [("PUT", f"{ISSUES}/ABC-34", {"fields": {"description": None}})])
|
||||
|
||||
|
||||
Reference in New Issue
Block a user