File findings, release reviews and added items as the issue types the settings name, and refuse a type the Jira project lacks

This commit is contained in:
Lilleman
2026-11-20 11:31:44 +01:00
parent 88fee92dcb
commit 34328b11b9
15 changed files with 179 additions and 30 deletions
+13
View File
@@ -6,6 +6,7 @@ import typing
from failure import Failure
from project_config.settings import Finish, JIRA_FINISH_STATUS, JIRA_FINISH_TRANSITION
from atlassian.client import Http
from text_files.markdown_text import listed
ISSUE_KEY = re.compile(r"([A-Z][A-Z0-9_]*)-([0-9]+)")
PAGE = 100
@@ -115,6 +116,18 @@ def transition_of(offered: object, key: str, finish: Finish) -> str | Failure:
return id_
def issue_type_refusal(site: str, project: str, kind: str, authorization: str, http: Http) -> str | None:
"""Why a new issue under an epic of the Jira project may not be of the type named kind: Jira didn't say which types the project has, or none of its types besides sub-task types has that name. None where one has."""
answered = http("GET", f"{site}/rest/api/3/issue/createmeta/{project}/issuetypes", authorization, None)
if isinstance(answered, Failure):
return f"cannot read {project}'s issue types: {answered.reason}"
types = answered.get("issueTypes") if isinstance(answered, dict) else None
if not isinstance(types, list) or not all(isinstance(each, dict) and isinstance(each.get("name"), str) for each in types):
return f"Jira answered {project}'s issue types in a shape its REST API version 3 doesn't document"
names = [each["name"] for each in types if each.get("subtask") is not True]
return None if kind in names else f"{project} has no issue type {kind!r} to file an issue under an epic as; its types are {listed(names, 'and') if names else 'none'}"
def project_of(key: str) -> str:
"""The key of the Jira project an issue key lies in."""
return key.rpartition("-")[0]
+33
View File
@@ -70,5 +70,38 @@ class TheCategoryOfAnIssuesStatus(unittest.TestCase):
self.assertEqual(jira.status_category(wrong), Failure("its status category has no key that is text"))
class TheRefusalOfAnIssueType(unittest.TestCase):
TYPES = {"issueTypes": [{"name": "Feature", "subtask": False}, {"name": "Bug", "subtask": False}, {"name": "Subtask", "subtask": True}]}
def refusal(self, kind: str, answer: object) -> str | None:
asked: list[tuple[str, str, object]] = []
def http(method: str, url: str, authorization: str, body: object) -> object:
asked.append((method, url, body))
return answer
refused = jira.issue_type_refusal("https://acme.atlassian.net", "ABC", kind, "Basic x", http)
self.assertEqual(asked, [("GET", "https://acme.atlassian.net/rest/api/3/issue/createmeta/ABC/issuetypes", None)])
return refused
def test_is_none_where_the_project_has_the_type(self):
self.assertIsNone(self.refusal("Bug", self.TYPES))
def test_names_the_types_the_project_has_other_than_sub_tasks_where_it_lacks_the_type(self):
self.assertEqual(self.refusal("Task", self.TYPES), "ABC has no issue type 'Task' to file an issue under an epic as; its types are Feature and Bug")
def test_a_sub_task_type_is_not_one_to_file_under_an_epic(self):
self.assertEqual(self.refusal("Subtask", self.TYPES), "ABC has no issue type 'Subtask' to file an issue under an epic as; its types are Feature and Bug")
def test_says_the_project_has_no_type_where_it_has_only_sub_task_types(self):
self.assertEqual(self.refusal("Bug", {"issueTypes": [{"name": "Subtask", "subtask": True}]}), "ABC has no issue type 'Bug' to file an issue under an epic as; its types are none")
def test_says_why_where_jira_fails_or_answers_in_another_shape(self):
self.assertEqual(self.refusal("Bug", Failure("Jira answered 403")), "cannot read ABC's issue types: Jira answered 403")
for wrong in ([], {}, {"issueTypes": "Bug"}, {"issueTypes": [{"subtask": False}]}):
with self.subTest(wrong=wrong):
self.assertEqual(self.refusal("Bug", wrong), "Jira answered ABC's issue types in a shape its REST API version 3 doesn't document")
if __name__ == "__main__":
unittest.main()