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
+12
View File
@@ -154,6 +154,18 @@ def project_of(key: str) -> str:
return key.rpartition("-")[0]
def edit_issue(site: str, key: str, body: dict[str, typing.Any], authorization: str, http: Http) -> None | Failure:
"""Sends an edit of the issue named key: its fields, its updates and its issue properties in one request, or the Failure Jira answered. Jira refuses an edit that holds neither fields nor update, so such an edit sets each property through the property's own endpoint, one request each, and stops at the first that fails."""
if "fields" in body or "update" in body:
answer = http("PUT", f"{site}/rest/api/3/issue/{key}", authorization, body)
return answer if isinstance(answer, Failure) else None
for entry in body.get("properties", []):
answer = http("PUT", f"{site}/rest/api/3/issue/{key}/properties/{entry['key']}", authorization, entry["value"])
if isinstance(answer, Failure):
return answer
return None
def rank_refusal(site: str, key: str, before: str, authorization: str, http: Http) -> str | None:
"""Ranks the issue named key just before the issue named before; why Jira refused, or None where it didn't. Jira answers a rank it made with no body, and one it refused with an error, or with an entry per issue that holds the errors."""
answer = http("PUT", f"{site}/rest/agile/1.0/issue/rank", authorization, {"issues": [key], "rankBeforeIssue": before})
+32
View File
@@ -109,3 +109,35 @@ class TheRefusalOfAnIssueType(unittest.TestCase):
if __name__ == "__main__":
unittest.main()
class AnIssueEdit(unittest.TestCase):
def setUp(self) -> None:
self.calls: list[tuple[str, str, object]] = []
self.answer: object = None
def http(self, method: str, url: str, authorization: str, body: object) -> object:
self.calls.append((method, url, body))
return self.answer
def edit(self, body: dict[str, object]) -> None | Failure:
return jira.edit_issue("https://acme.atlassian.net", "ABC-1", body, "Basic x", self.http)
def test_sends_fields_update_and_properties_in_one_request(self):
body = {"fields": {"summary": "Count."}, "update": {"labels": [{"add": "security"}]}, "properties": [{"key": "plan", "value": {"L": 2}}]}
self.assertIsNone(self.edit(body))
self.assertEqual(self.calls, [("PUT", "https://acme.atlassian.net/rest/api/3/issue/ABC-1", body)])
def test_sets_each_property_of_an_edit_without_fields_or_update_through_the_property_endpoint(self):
# Jira's edit refuses such a body: "one of 'fields' or 'update' required".
self.assertIsNone(self.edit({"properties": [{"key": "plan", "value": {"L": 2}}, {"key": "seen", "value": True}]}))
self.assertEqual(self.calls, [
("PUT", "https://acme.atlassian.net/rest/api/3/issue/ABC-1/properties/plan", {"L": 2}),
("PUT", "https://acme.atlassian.net/rest/api/3/issue/ABC-1/properties/seen", True),
])
def test_a_request_jira_refuses_is_its_failure_and_sets_no_later_property(self):
self.answer = Failure("Jira answered 503")
self.assertEqual(self.edit({"fields": {"summary": "Count."}}), Failure("Jira answered 503"))
self.assertEqual(self.edit({"properties": [{"key": "plan", "value": {}}, {"key": "seen", "value": True}]}), Failure("Jira answered 503"))
self.assertEqual(len(self.calls), 2)