Set an issue's scores through its property endpoint where an edit holds neither fields nor update

This commit is contained in:
Lilleman
2026-11-24 07:38:55 +01:00
parent b6a576187a
commit b3bb2dd3f5
6 changed files with 64 additions and 17 deletions
+3 -3
View File
@@ -13,7 +13,7 @@ from plan.todo_table import BLOCKED_BY, Item, item_fields, ItemFields, MOVES, SH
from plan_store.markdown_edits import bold_cell, plain, unfit_text
from plan_store.plans import cells, no_item, Plan, Written
from project_config.settings import DEFAULT_ISSUE_TYPE, Epic, Finish, JIRA_FINDING_TYPE, JIRA_FINISH_STATUS, JIRA_FINISH_TRANSITION
from atlassian.jira import entry_of, finishing_transition, ISSUE_KEY, issue_type_refusal, Link, MAX_PAGES, move_refusal, PERHAPS_FILED, PERHAPS_MOVED, project_of, rank_refusal, searched, unshaped
from atlassian.jira import edit_issue, entry_of, finishing_transition, ISSUE_KEY, issue_type_refusal, Link, MAX_PAGES, move_refusal, PERHAPS_FILED, PERHAPS_MOVED, project_of, rank_refusal, searched, unshaped
from failure import Failure
from plan.release import parsed, Release, tagged
from plan import ranking
@@ -198,7 +198,7 @@ class JiraPlan:
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 those or none, then changes the issue's links one request at a time, and then posts comment on the issue. `revision_of` says what an edit may set.
"""Sets the fields, the detail and the scores in one request, so Jira takes all of those or none, or sets the scores alone as `edit_issue` says, then changes the issue's links one request at a time, and then posts comment on the issue. `revision_of` says what an edit may set.
A link change or a comment Jira refuses leaves the edit made, so the write counts as landed, and a note says what to do by hand."""
authorization = basic_auth(self.env_file)
@@ -237,7 +237,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) if body else None
edited = edit_issue(self.epic.site, key, body, authorization, self.http) if body else None
if isinstance(edited, Failure):
return Failure(f"cannot edit {key}: {edited.reason}; {PERHAPS_EDITED.format(key=key)}")
notes = self.relinked(issue, revision.blockers, open_keys, authorization)
+8 -6
View File
@@ -540,7 +540,8 @@ class Editing(unittest.TestCase):
def test_sends_only_what_the_edit_names(self):
self.edit(34, {"Tagline": "Count every run."})
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}}]}])
self.assertEqual([body for _, _, body in self.writes()], [{"fields": {"summary": "Count every run."}}, PROPERTY | {"E": 3}])
self.assertEqual(self.writes()[1][1], f"{ISSUES}/ABC-34/properties/plan-item")
def test_a_detail_unchanged_since_the_read_leaves_the_description_as_jira_holds_it(self):
# Jira's own spacing paragraph and localIds, which a description converted back from markdown would lose.
@@ -548,7 +549,7 @@ class Editing(unittest.TestCase):
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}}]})])
self.assertEqual(self.writes(), [("PUT", f"{ISSUES}/ABC-34/properties/plan-item", PROPERTY | {"L": 2})])
def test_an_edited_detail_replaces_the_description(self):
self.open = [issue("ABC-34", scores=PROPERTY, description=adf("Why it counts."))]
@@ -586,17 +587,18 @@ class Editing(unittest.TestCase):
def test_scores_an_issue_a_person_filed_and_comments_why(self):
self.assertEqual(self.edit(35, {"L": "2", "E": "2", "I": "3", "S": "3", "Moves": "1 by 4"}, None, COMMENT), Written(35))
self.assertEqual(self.writes(), [
("PUT", f"{ISSUES}/ABC-35", {"properties": [{"key": "plan-item", "value": {"L": 2, "E": 2, "I": 3, "S": 3, "Moves": "1 by 4", "Exempt": ""}}]}),
("PUT", f"{ISSUES}/ABC-35/properties/plan-item", {"L": 2, "E": 2, "I": 3, "S": 3, "Moves": "1 by 4", "Exempt": ""}),
("POST", f"{ISSUES}/ABC-35/comment", {"body": adf(COMMENT)}),
])
def test_rescores_a_persons_issue_that_holds_scores_keeping_the_rest(self):
self.edit(36, {"L": "2"}, None, COMMENT)
self.assertEqual(self.writes()[0][2], {"properties": [{"key": "plan-item", "value": {"L": 2, "E": 1, "I": 1, "S": 2, "Moves": "", "Exempt": ""}}]})
self.assertEqual(self.writes()[0][1:], (f"{ISSUES}/ABC-36/properties/plan-item", {"L": 2, "E": 1, "I": 1, "S": 2, "Moves": "", "Exempt": ""}))
def test_a_persons_issue_is_never_labelled(self):
self.edit(36, {"Exempt": "security"}, None, COMMENT)
self.assertNotIn("update", self.writes()[0][2]) # type: ignore[operator]
# Labelling would take an edit of the issue itself; scores alone go to its property.
self.assertEqual([url for _, url, _ in self.writes()], [f"{ISSUES}/ABC-36/properties/plan-item", f"{ISSUES}/ABC-36/comment"])
def test_scoring_a_persons_issue_without_a_comment_fails_before_any_write(self):
for comment in (None, "", " \n"):
@@ -663,7 +665,7 @@ class Editing(unittest.TestCase):
def test_changes_the_links_after_the_edit_and_before_the_comment(self):
self.assertEqual(self.edit(34, {"L": "2", "Blocked by": "35"}, None, COMMENT), Written(34))
self.assertEqual([(method, url) for method, url, _ in self.writes()], [("PUT", f"{ISSUES}/ABC-34"), ("POST", LINKS), ("POST", f"{ISSUES}/ABC-34/comment")])
self.assertEqual([(method, url) for method, url, _ in self.writes()], [("PUT", f"{ISSUES}/ABC-34/properties/plan-item"), ("POST", LINKS), ("POST", f"{ISSUES}/ABC-34/comment")])
def test_a_failed_edit_makes_no_link(self):
self.edited = Failure("HTTP 400")