Answer stability round 1: 0 🔴, 3 🟡 (0 misread); read the issue types in one place, skip the epic type, and say what todo-item add files
This commit is contained in:
+19
-6
@@ -14,6 +14,8 @@ PAGE = 100
|
||||
MAX_PAGES = 100
|
||||
# The key of the status category Jira Cloud gives every done status.
|
||||
DONE = "done"
|
||||
# The hierarchyLevel of the epic issue type in the issue types Jira lists.
|
||||
EPIC_LEVEL = 1
|
||||
# How a Failure names an answer in which a field is missing or of another type.
|
||||
SHAPE = "is not in the shape Jira Cloud's REST API version 3 documents"
|
||||
# What a failed create ends with: a request Jira never answered, or answered brokenly, may still have filed the issue.
|
||||
@@ -116,16 +118,27 @@ 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."""
|
||||
def issue_types_of(site: str, project: str, authorization: str, http: Http) -> list[dict[str, typing.Any]] | Failure:
|
||||
"""The issue types Jira lists for the project, each with a name, or why it listed none."""
|
||||
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}"
|
||||
return Failure(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'}"
|
||||
return Failure(f"Jira answered {project}'s issue types in a shape its REST API version 3 doesn't document")
|
||||
return types
|
||||
|
||||
|
||||
def issue_type_refusal(site: str, project: str, kind: str, setting: str, authorization: str, http: Http) -> str | None:
|
||||
"""Why the project can't file a new issue under an epic as the type named kind, which the setting `setting` names; None where it can."""
|
||||
types = issue_types_of(site, project, authorization, http)
|
||||
if isinstance(types, Failure):
|
||||
return types.reason
|
||||
# An issue under an epic is a standard one: Jira refuses a sub-task there, and an epic under an epic.
|
||||
names: list[str] = [each["name"] for each in types if each.get("subtask") is not True and each.get("hierarchyLevel") != EPIC_LEVEL]
|
||||
if kind in names:
|
||||
return None
|
||||
return f"{project} has no issue type {kind!r} for an issue under an epic; " + (f"it has {listed(names, 'and')}: name one in `{setting}`" if names else "it has no other type for one")
|
||||
|
||||
|
||||
def project_of(key: str) -> str:
|
||||
|
||||
@@ -71,7 +71,7 @@ class TheCategoryOfAnIssuesStatus(unittest.TestCase):
|
||||
|
||||
|
||||
class TheRefusalOfAnIssueType(unittest.TestCase):
|
||||
TYPES = {"issueTypes": [{"name": "Feature", "subtask": False}, {"name": "Bug", "subtask": False}, {"name": "Subtask", "subtask": True}]}
|
||||
TYPES = {"issueTypes": [{"name": "Feature", "subtask": False, "hierarchyLevel": 0}, {"name": "Bug", "subtask": False, "hierarchyLevel": 0}, {"name": "Epic", "subtask": False, "hierarchyLevel": 1}, {"name": "Subtask", "subtask": True, "hierarchyLevel": -1}]}
|
||||
|
||||
def refusal(self, kind: str, answer: object) -> str | None:
|
||||
asked: list[tuple[str, str, object]] = []
|
||||
@@ -80,24 +80,28 @@ class TheRefusalOfAnIssueType(unittest.TestCase):
|
||||
asked.append((method, url, body))
|
||||
return answer
|
||||
|
||||
refused = jira.issue_type_refusal("https://acme.atlassian.net", "ABC", kind, "Basic x", http)
|
||||
refused = jira.issue_type_refusal("https://acme.atlassian.net", "ABC", kind, "jira-finding-type", "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_names_the_types_the_project_has_and_the_setting_where_it_lacks_the_type(self):
|
||||
self.assertEqual(self.refusal("Task", self.TYPES), "ABC has no issue type 'Task' for an issue under an epic; it has Feature and Bug: name one in `jira-finding-type`")
|
||||
|
||||
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_a_sub_task_type_and_the_epic_type_are_not_ones_for_an_issue_under_an_epic(self):
|
||||
for kind in ("Subtask", "Epic"):
|
||||
with self.subTest(kind=kind):
|
||||
self.assertEqual(self.refusal(kind, self.TYPES), f"ABC has no issue type {kind!r} for an issue under an epic; it has Feature and Bug: name one in `jira-finding-type`")
|
||||
|
||||
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_the_project_has_no_other_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' for an issue under an epic; it has no other type for one")
|
||||
|
||||
def test_says_why_where_jira_fails_or_answers_in_another_shape(self):
|
||||
def test_says_why_where_jira_fails(self):
|
||||
self.assertEqual(self.refusal("Bug", Failure("Jira answered 403")), "cannot read ABC's issue types: Jira answered 403")
|
||||
|
||||
def test_says_so_where_jira_answers_in_another_shape(self):
|
||||
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")
|
||||
|
||||
@@ -6,8 +6,8 @@ import typing
|
||||
from adf_codec.convert import adfs_to_markdown, markdown_to_adf, Refused
|
||||
from atlassian.client import basic_auth, Http, jira_json, ToAdf, ToMarkdown
|
||||
from plan_store.jira_epic import BLOCKS, FILED_BY, PROPERTY, scores
|
||||
from project_config.settings import DEFAULT_ISSUE_TYPE, Epic, Finish, JIRA_FINISH_STATUS, JIRA_FINISH_TRANSITION
|
||||
from atlassian.jira import DONE, entry_of, finishing_transition, ISSUE_KEY, issue_type_refusal, MAX_PAGES, move_refusal, PERHAPS_FILED, PERHAPS_MOVED, project_of, rank_refusal, searched, SHAPE, status_category, unshaped
|
||||
from project_config.settings import DEFAULT_ISSUE_TYPE, Epic, Finish, JIRA_FINDING_TYPE, JIRA_FINISH_STATUS, JIRA_FINISH_TRANSITION, JIRA_REVIEW_TYPE
|
||||
from atlassian.jira import DONE, entry_of, finishing_transition, ISSUE_KEY, issue_type_refusal, issue_types_of, MAX_PAGES, move_refusal, PERHAPS_FILED, PERHAPS_MOVED, project_of, rank_refusal, searched, SHAPE, status_category, unshaped
|
||||
from do_epic.backend.protocol import EpicIssue, no_blocker, no_child, no_parent, no_words, unfit, unfit_label
|
||||
from failure import Failure
|
||||
from do_epic.repo_pick import REVIEW_LABEL
|
||||
@@ -36,7 +36,7 @@ class JiraEpic:
|
||||
finish: Finish | None = None
|
||||
# The pages a search may take before the read fails.
|
||||
max_pages: int = MAX_PAGES
|
||||
# The issue types a finding and a release review (an issue labelled REVIEW_LABEL) are filed as under the epic.
|
||||
# The issue types that a finding, and a release review (an issue labelled REVIEW_LABEL), are filed as.
|
||||
finding_type: str = DEFAULT_ISSUE_TYPE
|
||||
review_type: str = DEFAULT_ISSUE_TYPE
|
||||
|
||||
@@ -249,20 +249,17 @@ class JiraEpic:
|
||||
return next((each for each in found if isinstance(each, Failure)), None) or [each for each in found if isinstance(each, Found)]
|
||||
|
||||
def child_type(self, project: str, review: bool, authorization: str) -> dict[str, str] | Failure:
|
||||
"""The issue type of a new child of the epic: the type of a release review where review, else of a finding, if the project has it."""
|
||||
"""The issue type of a new child of the epic, which is the type of a release review where review is true, else of a finding; or why the project can't file that type."""
|
||||
name = self.review_type if review else self.finding_type
|
||||
refused = issue_type_refusal(self.epic.site, project, name, authorization, self.http)
|
||||
refused = issue_type_refusal(self.epic.site, project, name, JIRA_REVIEW_TYPE if review else JIRA_FINDING_TYPE, authorization, self.http)
|
||||
return Failure(refused) if refused else {"name": name}
|
||||
|
||||
def sub_task_type(self, project: str, authorization: str) -> dict[str, str] | Failure:
|
||||
"""The project's sub-task issue type, by id, since sites name it differently, such as Subtask or Sub-task."""
|
||||
answered = self.http("GET", f"{self.epic.site}/rest/api/3/issue/createmeta/{project}/issuetypes", authorization, None)
|
||||
if isinstance(answered, Failure):
|
||||
return Failure(f"cannot read {project}'s issue types: {answered.reason}")
|
||||
types = answered.get("issueTypes") if isinstance(answered, dict) else None
|
||||
if not isinstance(types, list):
|
||||
return Failure(f"Jira answered {project}'s issue types in a shape its REST API version 3 doesn't document")
|
||||
found = next((kind["id"] for kind in types if isinstance(kind, dict) and kind.get("subtask") is True and isinstance(kind.get("id"), str)), None)
|
||||
types = issue_types_of(self.epic.site, project, authorization, self.http)
|
||||
if isinstance(types, Failure):
|
||||
return types
|
||||
found = next((kind["id"] for kind in types if kind.get("subtask") is True and isinstance(kind.get("id"), str)), None)
|
||||
return Failure(f"{project} has no sub-task issue type; turn sub-tasks on in Jira") if found is None else {"id": found}
|
||||
|
||||
|
||||
|
||||
@@ -310,9 +310,9 @@ class Jira(Case):
|
||||
store.file("ABC-12", "Review api.", "", ("repo:api", REVIEW_LABEL))
|
||||
self.assertEqual(self.jira.filed_as, [{"name": "Feature"}, {"name": "Chore"}])
|
||||
|
||||
def test_files_nothing_where_the_project_lacks_the_type_and_names_the_types_it_has(self) -> None:
|
||||
def test_does_not_file_anything_where_the_project_lacks_the_type_and_names_the_types_it_has(self) -> None:
|
||||
store = JiraEpic(EPIC, self.env_file, self.jira, to_markdown, to_adf, finding_type="Feature", review_type="Investigation")
|
||||
self.assertEqual(store.file("ABC-12", "Review api.", "", (REVIEW_LABEL,)), Failure("ABC has no issue type 'Investigation' to file an issue under an epic as; its types are Task, Feature and Chore"))
|
||||
self.assertEqual(store.file("ABC-12", "Review api.", "", (REVIEW_LABEL,)), Failure("ABC has no issue type 'Investigation' for an issue under an epic; it has Task, Feature and Chore: name one in `jira-review-type`"))
|
||||
self.assertEqual(self.jira.issues, [])
|
||||
|
||||
def test_a_filing_jira_fails_or_answers_without_a_key_says_the_issue_may_exist(self) -> None:
|
||||
@@ -329,7 +329,7 @@ class Jira(Case):
|
||||
def test_files_no_sub_task_where_the_project_has_no_sub_task_type_or_its_types_cannot_be_read(self) -> None:
|
||||
store = self.new_store()
|
||||
child = store.file("ABC-12", "Count the runs.", "", ())
|
||||
for answer, reason in ((Failure("Jira answered 403"), "cannot read ABC's issue types: Jira answered 403"), ({"issueTypes": [{"id": "10001", "subtask": False}]}, "ABC has no sub-task issue type; turn sub-tasks on in Jira"), ({}, "Jira answered ABC's issue types in a shape its REST API version 3 doesn't document"), ([], "Jira answered ABC's issue types in a shape its REST API version 3 doesn't document")):
|
||||
for answer, reason in ((Failure("Jira answered 403"), "cannot read ABC's issue types: Jira answered 403"), ({"issueTypes": [{"id": "10001", "name": "Task", "subtask": False}]}, "ABC has no sub-task issue type; turn sub-tasks on in Jira"), ({}, "Jira answered ABC's issue types in a shape its REST API version 3 doesn't document"), ([], "Jira answered ABC's issue types in a shape its REST API version 3 doesn't document")):
|
||||
with self.subTest(answer=answer):
|
||||
self.jira.answers[("GET", ISSUE_TYPES)] = answer
|
||||
self.assertEqual(store.file(str(child), "A task.", "", ()), Failure(reason))
|
||||
|
||||
@@ -12,7 +12,7 @@ from atlassian.client import basic_auth, Http, jira_json, ToAdf, ToMarkdown
|
||||
from plan.todo_table import BLOCKED_BY, Item, item_fields, ItemFields, MOVES, SHAPE
|
||||
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_FINISH_STATUS, JIRA_FINISH_TRANSITION
|
||||
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 failure import Failure
|
||||
from plan.release import parsed, Release, tagged
|
||||
@@ -22,7 +22,6 @@ from plan import ranking
|
||||
PROPERTY = "plan-item"
|
||||
# The key in PROPERTY's value that marks an issue the loop filed, and its value. An edit of an issue without it, which a person filed, writes only PROPERTY and a comment.
|
||||
FILED_BY = ("Filed by", "loop")
|
||||
# The issue type of an issue the loop files, which Jira Software's project templates all have; a project without it refuses the issue, saying so.
|
||||
# The name of the link type whose inward side reads "is blocked by", as Jira Cloud ships it.
|
||||
BLOCKS = "Blocks"
|
||||
SECURITY = "security"
|
||||
@@ -114,7 +113,7 @@ class JiraPlan:
|
||||
description = self.description_of(detail)
|
||||
if isinstance(description, Failure):
|
||||
return description
|
||||
if refused := issue_type_refusal(self.epic.site, project_of(self.epic.key), self.finding_type, authorization, self.http):
|
||||
if refused := issue_type_refusal(self.epic.site, project_of(self.epic.key), self.finding_type, JIRA_FINDING_TYPE, authorization, self.http):
|
||||
return Failure(refused)
|
||||
issue_fields = filing.fields | ({"description": description} if description else {})
|
||||
version = self.fix_version(filing.release, authorization)
|
||||
|
||||
@@ -291,8 +291,8 @@ class Filing(unittest.TestCase):
|
||||
self.assertEqual(self.add(finding_type="Feature"), Written(40))
|
||||
self.assertEqual(self.sent(ISSUES)[0]["fields"]["issuetype"], {"name": "Feature"}) # type: ignore[index]
|
||||
|
||||
def test_files_nothing_where_the_project_lacks_the_issue_type_and_names_the_types_it_has(self):
|
||||
self.assertEqual(self.add(finding_type="Chore"), Failure("ABC has no issue type 'Chore' to file an issue under an epic as; its types are Task and Feature"))
|
||||
def test_does_not_file_anything_where_the_project_lacks_the_issue_type_and_names_the_types_it_has(self):
|
||||
self.assertEqual(self.add(finding_type="Chore"), Failure("ABC has no issue type 'Chore' for an issue under an epic; it has Task and Feature: name one in `jira-finding-type`"))
|
||||
self.assertEqual(self.sent(ISSUES), [])
|
||||
|
||||
def test_a_bold_tagline_is_filed_plain(self):
|
||||
|
||||
@@ -29,8 +29,9 @@ add files the item under the next free ID, with the tagline in bold, and the det
|
||||
stdin, if any. The detail may hold no ## or ### heading.
|
||||
It prints `Filed item <ID> in <plan>.` It doesn't write anything where ranking fails or scores the item under the bar,
|
||||
or where the detail holds a `Touches:` list not spelt as `touch-predictions --help` shows.
|
||||
In a Jira epic, add files a Task under the epic, and <ID> is the new issue's number. The release
|
||||
must be one of the Jira project's Fix Versions, named as 1.2.0 or v1.2.0 there, and --exempt
|
||||
In a Jira epic, add files the item under the epic as a Task, or as the type the config's
|
||||
`jira-finding-type` names, and refuses before filing where the Jira project lacks that type. <ID> is
|
||||
the new issue's number. The release must be one of the Jira project's Fix Versions, named as 1.2.0 or v1.2.0 there, and --exempt
|
||||
security also labels the issue `security`. The item scores by the config's `jira-score-formula`, and
|
||||
add refuses it under `jira-score-bar` unless it is exempt. add then asks Jira to rank the new issue
|
||||
just before the first issue the loop filed that ranks after it: a question before any other, then a
|
||||
|
||||
Reference in New Issue
Block a user