diff --git a/.gitignore b/.gitignore index 9f3ba4ff..17f7f58b 100644 --- a/.gitignore +++ b/.gitignore @@ -53,6 +53,10 @@ !bin/deploy-release !bin/deploy_release/ !bin/deploy_release/*.py +!bin/do_epic/ +!bin/do_epic/*.py +!bin/do_epic/backend/ +!bin/do_epic/backend/*.py !bin/failure.py !bin/forge/ !bin/forge/*.py diff --git a/bin/do_epic/__init__.py b/bin/do_epic/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/bin/do_epic/backend/__init__.py b/bin/do_epic/backend/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/bin/do_epic/backend/contract.py b/bin/do_epic/backend/contract.py new file mode 100644 index 00000000..dfaec6af --- /dev/null +++ b/bin/do_epic/backend/contract.py @@ -0,0 +1,78 @@ +"""What every backend of an epic's plan must hold, as tests. A backend's test case inherits EpicStoreContract and unittest.TestCase, builds an epic with no issues in new_store, and changes an issue as a person would in the tracker in assign and close.""" +import typing + +from do_epic.backend.protocol import EpicIssue, EpicStore +from failure import Failure + + +class EpicStoreContract: + assertEqual: typing.Callable[..., None] + subTest: typing.Callable[..., typing.ContextManager[None]] + + def new_store(self) -> EpicStore: + raise NotImplementedError + + def assign(self, store: EpicStore, key: str, name: str) -> None: + """Assigns the issue named key to the person whose display name is name.""" + raise NotImplementedError + + def close(self, store: EpicStore, key: str, status: str) -> None: + """Moves the issue named key to the done status named status.""" + raise NotImplementedError + + def filed(self, store: EpicStore, parent: str, summary: str, detail: str = "", labels: tuple[str, ...] = ()) -> str: + key = store.file(parent, summary, detail, labels) + assert isinstance(key, str), key + return key + + def issues(self, store: EpicStore) -> list[EpicIssue]: + read = store.read() + assert isinstance(read, list), read + return read + + def test_an_epic_with_no_issues_reads_empty(self) -> None: + self.assertEqual(self.new_store().read(), []) + + def test_reads_back_a_child_issue_it_filed(self) -> None: + store = self.new_store() + key = self.filed(store, store.epic, "Count the runs.", "Why it counts.\n\nA second paragraph.", ("api", "security")) + self.assertEqual(self.issues(store), [EpicIssue(key, "Count the runs.", "Why it counts.\n\nA second paragraph.", ("api", "security"), None, "To Do", False, store.epic)]) + + def test_reads_back_a_sub_task_it_filed_after_its_parent(self) -> None: + store = self.new_store() + first = self.filed(store, store.epic, "Count the runs.") + second = self.filed(store, store.epic, "Ship the later thing.") + task = self.filed(store, first, "Count them in the api.", labels=("api",)) + read = self.issues(store) + self.assertEqual([(issue.key, issue.parent) for issue in read], [(first, store.epic), (task, first), (second, store.epic)]) + self.assertEqual((read[1].summary, read[1].labels, read[1].detail), ("Count them in the api.", ("api",), "")) + + def test_files_each_issue_under_its_own_key(self) -> None: + store = self.new_store() + keys = {self.filed(store, store.epic, "Count the runs."), self.filed(store, store.epic, "Count the runs.")} + self.assertEqual(len(keys), 2) + + def test_reads_the_assignee_and_a_done_status(self) -> None: + store = self.new_store() + first = self.filed(store, store.epic, "Count the runs.") + second = self.filed(store, store.epic, "Ship the later thing.") + self.assign(store, first, "Ada Lovelace") + self.close(store, second, "Done") + read = {issue.key: issue for issue in self.issues(store)} + self.assertEqual((read[first].assignee, read[first].status, read[first].done), ("Ada Lovelace", "To Do", False)) + self.assertEqual((read[second].assignee, read[second].status, read[second].done), (None, "Done", True)) + + def test_refuses_to_file_under_an_issue_outside_the_epic_or_under_a_sub_task(self) -> None: + store = self.new_store() + child = self.filed(store, store.epic, "Count the runs.") + task = self.filed(store, child, "Count them in the api.") + for parent in (task, "ZZZ-1"): + with self.subTest(parent=parent): + self.assertEqual(store.file(parent, "Count more.", "", ()), Failure(f"{parent} is neither the epic {store.epic} nor one of its child issues, so nothing can be filed under it")) + self.assertEqual(len(self.issues(store)), 2) + + def test_refuses_a_label_with_white_space_and_a_summary_of_two_lines(self) -> None: + store = self.new_store() + self.assertEqual(store.file(store.epic, "Count the runs.", "", ("two words",)), Failure("the label 'two words' is empty or holds white space")) + self.assertEqual(store.file(store.epic, "Count\nthe runs.", "", ()), Failure("the summary must be one line of text")) + self.assertEqual(self.issues(store), []) diff --git a/bin/do_epic/backend/fake.py b/bin/do_epic/backend/fake.py new file mode 100644 index 00000000..f93e7f6d --- /dev/null +++ b/bin/do_epic/backend/fake.py @@ -0,0 +1,31 @@ +"""An epic held in memory, for do-epic's tests, held to contract.py like every backend.""" +import dataclasses + +from do_epic.backend.protocol import EpicIssue, unfit +from failure import Failure + + +@dataclasses.dataclass +class MemoryEpic: + """An epic whose issues rank in the order filed. Where fails is set, every read and filing fails with it as the reason.""" + epic: str + issues: list[EpicIssue] = dataclasses.field(default_factory=list) + fails: str | None = None + + def read(self) -> list[EpicIssue] | Failure: + if self.fails: + return Failure(self.fails) + return [issue for child in self.issues if child.parent == self.epic for issue in (child, *(task for task in self.issues if task.parent == child.key))] + + def file(self, parent: str, summary: str, detail: str, labels: tuple[str, ...]) -> str | Failure: + if self.fails: + return Failure(self.fails) + if refused := unfit(self.epic, {issue.key for issue in self.issues if issue.parent == self.epic}, parent, summary, labels): + return refused + key = f"{self.epic.rpartition('-')[0]}-{len(self.issues) + 100}" + self.issues.append(EpicIssue(key, summary, detail.strip(), labels, None, "To Do", False, parent)) + return key + + def change(self, key: str, **fields: object) -> None: + """Changes the issue named key as a person would in the tracker, such as assignee="Ada Lovelace".""" + self.issues = [dataclasses.replace(issue, **fields) if issue.key == key else issue for issue in self.issues] # type: ignore[arg-type] diff --git a/bin/do_epic/backend/jira.py b/bin/do_epic/backend/jira.py new file mode 100644 index 00000000..654b219b --- /dev/null +++ b/bin/do_epic/backend/jira.py @@ -0,0 +1,134 @@ +"""An epic's plan kept as a Jira Cloud epic's child issues and their sub-tasks, read and filed over Jira's REST API version 3.""" +import dataclasses +import pathlib +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 do_epic.backend.protocol import EpicIssue, unfit +from failure import Failure +from plan_store.jira_epic import ISSUE_KEY, ISSUE_TYPE, project_of, searched +from project_config.settings import Epic + +FIELDS = ["summary", "description", "labels", "assignee", "status", "parent"] +# How many child issues one search for sub-tasks names, which keeps its JQL well inside the length Jira takes. +PARENTS_PER_SEARCH = 50 +PERHAPS_FILED = "unless Jira refused the request, the issue may exist: look under {parent} before filing it again" + + +@dataclasses.dataclass(frozen=True) +class Found: + """An issue as Jira answered it, its description still in Jira's document format.""" + issue: EpicIssue + description: dict[str, typing.Any] | None + + +@dataclasses.dataclass(frozen=True) +class JiraEpic: + """The issues of the epic on, read and filed with the credentials env_file holds.""" + on: Epic + env_file: pathlib.Path + http: Http = jira_json + to_markdown: ToMarkdown = adfs_to_markdown + to_adf: ToAdf = markdown_to_adf + + @property + def epic(self) -> str: + return self.on.key + + def read(self) -> list[EpicIssue] | Failure: + authorization = basic_auth(self.env_file) + if isinstance(authorization, Failure): + return authorization + found = self.found(authorization) + if isinstance(found, Failure): + return found + # The descriptions convert in one container run, after every other check, which a read that fails doesn't need. + described = [each for each in found if each.description is not None] + texts = self.to_markdown([each.description for each in described if each.description is not None]) + if isinstance(texts, Refused): + return Failure(f"{described[texts.index].issue.key}'s description: {texts.failure.reason}") + if isinstance(texts, Failure): + return Failure(f"cannot convert the descriptions of {self.epic}'s issues to markdown: {texts.reason}") + details = {each.issue.key: text.strip() for each, text in zip(described, texts)} + return [dataclasses.replace(each.issue, detail=details.get(each.issue.key, "")) for each in found] + + def file(self, parent: str, summary: str, detail: str, labels: tuple[str, ...]) -> str | Failure: + authorization = basic_auth(self.env_file) + if isinstance(authorization, Failure): + return authorization + children = self.searched(f"{self.epic}'s child issues", (self.epic,), authorization) + if isinstance(children, Failure): + return children + if refused := unfit(self.epic, {each.issue.key for each in children}, parent, summary, labels): + return refused + fields: dict[str, typing.Any] = {"project": {"key": project_of(parent)}, "parent": {"key": parent}, "summary": summary, "labels": list(labels)} + kind = {"name": ISSUE_TYPE} if parent == self.epic else self.sub_task_type(project_of(parent), authorization) + if isinstance(kind, Failure): + return kind + if detail.strip(): + description = self.to_adf(detail) + if isinstance(description, Failure): + return Failure(f"cannot convert the detail to a Jira description: {description.reason}") + fields["description"] = description + created = self.http("POST", f"{self.on.site}/rest/api/3/issue", authorization, {"fields": fields | {"issuetype": kind}}) + if isinstance(created, Failure): + return Failure(f"cannot file the issue under {parent}: {created.reason}; {PERHAPS_FILED.format(parent=parent)}") + key = created.get("key") if isinstance(created, dict) else None + if not isinstance(key, str) or not ISSUE_KEY.fullmatch(key): + return Failure(f"Jira answered the new issue without an issue key; {PERHAPS_FILED.format(parent=parent)}") + return key + + def found(self, authorization: str) -> list[Found] | Failure: + """Each child issue, each followed by its sub-tasks.""" + # The search answers no issues for an epic the account cannot see; asking for the epic itself tells that from an epic without children. + seen = self.http("GET", f"{self.on.site}/rest/api/3/issue/{self.epic}?fields=summary", authorization, None) + if isinstance(seen, Failure): + return Failure(f"cannot read the epic {self.epic}: {seen.reason}") + children = self.searched(f"{self.epic}'s child issues", (self.epic,), authorization) + if isinstance(children, Failure): + return children + keys = [each.issue.key for each in children] + tasks: list[Found] = [] + for start in range(0, len(keys), PARENTS_PER_SEARCH): + batch = self.searched(f"the sub-tasks of {self.epic}'s child issues", tuple(keys[start:start + PARENTS_PER_SEARCH]), authorization) + if isinstance(batch, Failure): + return batch + tasks += batch + return [each for child in children for each in (child, *(task for task in tasks if task.issue.parent == child.issue.key))] + + def searched(self, what: str, parents: tuple[str, ...], authorization: str) -> list[Found] | Failure: + """The issues whose parent is one of parents, in rank order.""" + named = ", ".join(f'"{key}"' for key in parents) + answered = searched(self.on.site, what, f"parent in ({named}) ORDER BY Rank ASC", {"fields": FIELDS}, authorization, self.http) + if isinstance(answered, Failure): + return answered + found = [found_of(raw) for raw in answered] + return next((each for each in found if isinstance(each, Failure)), None) or [each for each in found if isinstance(each, Found)] + + 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.on.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 + 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) if isinstance(types, list) else None + return Failure(f"{project} has no sub-task issue type; turn sub-tasks on in Jira") if found is None else {"id": found} + + +def found_of(raw: object) -> Found | Failure: + """The issue in one entry of a search's answer, or which issue is not in the shape Jira documents.""" + key = raw.get("key") if isinstance(raw, dict) else None + if not isinstance(raw, dict) or not isinstance(key, str) or not ISSUE_KEY.fullmatch(key): + return Failure("the search answered an issue without an issue key") + # The answer's nested fields are read as Jira documents them; one missing or of another type ends the read here. + try: + fields = raw["fields"] + assignee = fields["assignee"]["displayName"] if fields["assignee"] is not None else None + issue = EpicIssue(key, fields["summary"].strip(), "", tuple(fields["labels"]), assignee, fields["status"]["name"], fields["status"]["statusCategory"]["key"] == "done", fields["parent"]["key"]) + description = fields["description"] + except (AttributeError, KeyError, TypeError) as failure: + return Failure(f"{key} is not in the shape Jira Cloud's REST API version 3 documents: {failure!r}") + if not all(isinstance(text, str) for text in (*issue.labels, issue.assignee or "", issue.status, issue.parent)) or not isinstance(description, dict | None): + return Failure(f"{key} is not in the shape Jira Cloud's REST API version 3 documents: a label, its assignee, status, parent or description holds another kind of value") + return Found(issue, description) diff --git a/bin/do_epic/backend/protocol.py b/bin/do_epic/backend/protocol.py new file mode 100644 index 00000000..fab53e16 --- /dev/null +++ b/bin/do_epic/backend/protocol.py @@ -0,0 +1,54 @@ +"""What every backend of an epic's plan reads and files: an EpicIssue, and the EpicStore protocol they all meet. do-epic reads an epic only through EpicStore, so another tracker can stand behind it; contract.py holds the tests every backend passes. + +It stands apart from plan_store's PlanStore, whose every item names a release, since an epic item has none (`docs/decisions.md` → `do-epic: drives one Jira epic …`) and may be a sub-task.""" +import dataclasses +import re +import typing + +from failure import Failure + +# What a tracker accepts as a label: Jira refuses a label holding white space. +LABEL = re.compile(r"\S+") + + +@dataclasses.dataclass(frozen=True) +class EpicIssue: + """One of an epic's child issues, or a sub-task of one, as a read found it.""" + key: str + summary: str + # The description, as markdown; empty where the issue has none. + detail: str + labels: tuple[str, ...] + # The assignee's display name; None where nobody is assigned. + assignee: str | None + # The status's name, such as "In Progress". + status: str + # Whether the status is one the tracker counts as done. + done: bool + # The epic's key for a child issue, the child's key for a sub-task. + parent: str + + +class EpicStore(typing.Protocol): + """The issues of one epic. A write that fails files nothing, except where its Failure says the tracker may have taken it all the same.""" + + @property + def epic(self) -> str: + """The epic's key, the parent of each child issue.""" + + def read(self) -> list[EpicIssue] | Failure: + """Each child issue, open or done, in the tracker's rank order, each followed by its sub-tasks in theirs.""" + + def file(self, parent: str, summary: str, detail: str, labels: tuple[str, ...]) -> str | Failure: + """Files an open issue under parent and answers its key: a child issue where parent is the epic, a sub-task where parent is one of its child issues. detail is markdown, and may be empty.""" + + +def unfit(epic: str, children: set[str], parent: str, summary: str, labels: tuple[str, ...]) -> Failure | None: + """Why an issue with this summary and these labels cannot be filed under parent, where children are the keys of the child issues of the epic named epic; None where it can. Every backend refuses the same filings.""" + if not summary.strip() or "\n" in summary: + return Failure("the summary must be one line of text") + if bad := next((label for label in labels if not LABEL.fullmatch(label)), None): + return Failure(f"the label {bad!r} is empty or holds white space") + if parent != epic and parent not in children: + return Failure(f"{parent} is neither the epic {epic} nor one of its child issues, so nothing can be filed under it") + return None diff --git a/bin/do_epic/backend/test_fake.py b/bin/do_epic/backend/test_fake.py new file mode 100644 index 00000000..1d59979e --- /dev/null +++ b/bin/do_epic/backend/test_fake.py @@ -0,0 +1,30 @@ +import pathlib +import sys +import unittest + +sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[2])) + +from do_epic.backend.contract import EpicStoreContract +from do_epic.backend.fake import MemoryEpic +from failure import Failure + + +class MemoryEpicContract(EpicStoreContract, unittest.TestCase): + def new_store(self) -> MemoryEpic: + return MemoryEpic("ABC-12") + + def assign(self, store: MemoryEpic, key: str, name: str) -> None: # type: ignore[override] + store.change(key, assignee=name) + + def close(self, store: MemoryEpic, key: str, status: str) -> None: # type: ignore[override] + store.change(key, status=status, done=True) + + +class Failing(unittest.TestCase): + def test_every_read_and_filing_fails_with_the_reason_given(self) -> None: + store = MemoryEpic("ABC-12", fails="Jira is down") + self.assertEqual((store.read(), store.file("ABC-12", "Count the runs.", "", ())), (Failure("Jira is down"), Failure("Jira is down"))) + + +if __name__ == "__main__": + unittest.main() diff --git a/bin/do_epic/backend/test_jira.py b/bin/do_epic/backend/test_jira.py new file mode 100644 index 00000000..5de4d6a2 --- /dev/null +++ b/bin/do_epic/backend/test_jira.py @@ -0,0 +1,124 @@ +import dataclasses +import pathlib +import re +import sys +import tempfile +import unittest + +sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[2])) + +from do_epic.backend.contract import EpicStoreContract +from do_epic.backend.jira import JiraEpic +from failure import Failure +from project_config.settings import Epic + +SITE = "https://acme.atlassian.net" +EPIC = Epic(SITE, "ABC-12") +TO_DO = {"name": "To Do", "statusCategory": {"key": "new"}} +TYPES = {"issueTypes": [{"id": "10001", "name": "Task", "subtask": False}, {"id": "10003", "name": "Subtask", "subtask": True}]} + + +def to_adf(markdown: str) -> dict[str, object]: + """Stands in for the adf-codec shim: one paragraph holding the markdown.""" + return {"type": "doc", "version": 1, "content": [{"type": "paragraph", "content": [{"type": "text", "text": markdown}]}]} + + +def to_markdown(documents: list[dict[str, object]]) -> list[str]: + return [document["content"][0]["content"][0]["text"] + "\n" for document in documents] # type: ignore[index] + + +@dataclasses.dataclass +class FakeJira: + """Jira Cloud's REST API as JiraEpic calls it, holding issues as Jira answers them, in rank order, and answering a search two issues a page.""" + issues: list[dict[str, object]] = dataclasses.field(default_factory=list) + refuses: str | None = None + calls: list[tuple[str, str]] = dataclasses.field(default_factory=list) + + def __call__(self, method: str, url: str, authorization: str, body: object) -> object: + self.calls.append((method, url)) + if self.refuses and method == "POST" and url.endswith("/issue"): + return Failure(self.refuses) + if method == "GET" and url == f"{SITE}/rest/api/3/issue/ABC-12?fields=summary": + return {"key": "ABC-12"} + if method == "GET" and url == f"{SITE}/rest/api/3/issue/createmeta/ABC/issuetypes": + return TYPES + if method == "POST" and url == f"{SITE}/rest/api/3/search/jql": + return self.page(body) + if method == "POST" and url == f"{SITE}/rest/api/3/issue": + return self.created(body) + return Failure(f"Jira answered 404 for {method} {url}") + + def page(self, body: object) -> object: + assert isinstance(body, dict) + parents = re.findall(r'"([A-Z]+-[0-9]+)"', body["jql"]) + found = [issue for issue in self.issues if issue["fields"]["parent"]["key"] in parents] # type: ignore[index] + start = int(body.get("nextPageToken", 0)) + return {"issues": found[start:start + 2]} | ({"nextPageToken": str(start + 2)} if start + 2 < len(found) else {}) + + def created(self, body: object) -> object: + assert isinstance(body, dict) + fields = body["fields"] + parent = next((issue for issue in self.issues if issue["key"] == fields["parent"]["key"]), None) + subtask = fields["issuetype"] == {"id": "10003"} + if fields["parent"]["key"] != "ABC-12" and (parent is None or not subtask): + return Failure("Jira answered 400: the parent cannot hold this issue type") + key = f"ABC-{len(self.issues) + 100}" + self.issues.append({"key": key, "fields": {"summary": fields["summary"], "description": fields.get("description"), "labels": fields["labels"], "assignee": None, "status": TO_DO, "parent": {"key": fields["parent"]["key"]}}}) + return {"id": "1", "key": key} + + def change(self, key: str, **fields: object) -> None: + next(issue for issue in self.issues if issue["key"] == key)["fields"].update(fields) # type: ignore[union-attr] + + +class Case(unittest.TestCase): + def setUp(self) -> None: + folder = tempfile.TemporaryDirectory() + self.addCleanup(folder.cleanup) + self.env_file = pathlib.Path(folder.name) / "jira.env" + self.env_file.write_text("ATLASSIAN_EMAIL=me@example.com\nATLASSIAN_API_TOKEN=s3cret\n") + self.env_file.chmod(0o600) + self.jira = FakeJira() + + def new_store(self) -> JiraEpic: + return JiraEpic(EPIC, self.env_file, self.jira, to_markdown, to_adf) + + +class JiraEpicContract(Case, EpicStoreContract): + def assign(self, store: JiraEpic, key: str, name: str) -> None: # type: ignore[override] + self.jira.change(key, assignee={"accountId": "5b10a2844c20165700ede21g", "displayName": name}) + + def close(self, store: JiraEpic, key: str, status: str) -> None: # type: ignore[override] + self.jira.change(key, status={"name": status, "statusCategory": {"key": "done"}}) + + +class Jira(Case): + def test_reads_the_sub_tasks_of_more_children_than_one_search_names(self) -> None: + store = self.new_store() + children = [store.file("ABC-12", f"Item {n}.", "", ()) for n in range(60)] + tasks = [store.file(child, "A task.", "", ()) for child in children] + read = store.read() + assert isinstance(read, list), read + self.assertEqual([issue.key for issue in read], [key for pair in zip(children, tasks) for key in pair]) + + def test_files_a_child_without_asking_for_issue_types(self) -> None: + self.new_store().file("ABC-12", "Count the runs.", "", ()) + self.assertNotIn(("GET", f"{SITE}/rest/api/3/issue/createmeta/ABC/issuetypes"), self.jira.calls) + + def test_a_refused_filing_says_the_issue_may_exist(self) -> None: + self.jira.refuses = "Jira answered 503" + self.assertEqual(self.new_store().file("ABC-12", "Count the runs.", "", ()), Failure("cannot file the issue under ABC-12: Jira answered 503; unless Jira refused the request, the issue may exist: look under ABC-12 before filing it again")) + + def test_an_issue_in_another_shape_fails_the_read(self) -> None: + self.jira.issues.append({"key": "ABC-34", "fields": {"summary": "Count the runs.", "parent": {"key": "ABC-12"}}}) + read = self.new_store().read() + self.assertIsInstance(read, Failure) + assert isinstance(read, Failure) + self.assertTrue(read.reason.startswith("ABC-34 is not in the shape Jira Cloud's REST API version 3 documents"), read.reason) + + def test_an_epic_the_account_cannot_see_fails_the_read(self) -> None: + store = JiraEpic(Epic(SITE, "ABC-99"), self.env_file, self.jira, to_markdown, to_adf) + self.assertEqual(store.read(), Failure(f"cannot read the epic ABC-99: Jira answered 404 for GET {SITE}/rest/api/3/issue/ABC-99?fields=summary")) + + +if __name__ == "__main__": + unittest.main() diff --git a/bin/plan_store/jira_epic.py b/bin/plan_store/jira_epic.py index f964bac9..aeb0f56a 100644 --- a/bin/plan_store/jira_epic.py +++ b/bin/plan_store/jira_epic.py @@ -448,15 +448,15 @@ def children(epic: Epic, authorization: str, http: Http) -> list[object] | Failu seen = http("GET", f"{epic.site}/rest/api/3/issue/{epic.key}?fields=summary", authorization, None) if isinstance(seen, Failure): return Failure(f"cannot read the epic {epic.key}: {seen.reason}") - body: dict[str, object] = { - "jql": f'parent = "{epic.key}" AND statusCategory != Done ORDER BY Rank ASC', - "fields": ["summary", "description", "fixVersions", "issuelinks"], - "properties": [PROPERTY], - "maxResults": PAGE, - } + return searched(epic.site, f"{epic.key}'s children", f'parent = "{epic.key}" AND statusCategory != Done ORDER BY Rank ASC', {"fields": ["summary", "description", "fixVersions", "issuelinks"], "properties": [PROPERTY]}, authorization, http) + + +def searched(site: str, what: str, jql: str, asked: dict[str, object], authorization: str, http: Http) -> list[object] | Failure: + """Every issue the JQL search finds on site, page by page, each with the fields and properties asked names. what names the issues sought, for a message.""" + body: dict[str, object] = {"jql": jql, "maxResults": PAGE} | asked found: list[object] = [] for _ in range(MAX_PAGES): - page = http("POST", f"{epic.site}/rest/api/3/search/jql", authorization, body) + page = http("POST", f"{site}/rest/api/3/search/jql", authorization, body) if isinstance(page, Failure): return page if not isinstance(page, dict) or not isinstance(page.get("issues"), list): @@ -465,7 +465,7 @@ def children(epic: Epic, authorization: str, http: Http) -> list[object] | Failu if not page.get("nextPageToken"): return found body = body | {"nextPageToken": page["nextPageToken"]} - return Failure(f"the search for {epic.key}'s children did not end within {MAX_PAGES} pages") + return Failure(f"the search for {what} did not end within {MAX_PAGES} pages") def issue_of(raw: object) -> Issue | Failure: diff --git a/docs/reading-cost.md b/docs/reading-cost.md index 62d3cdb1..731c705c 100644 --- a/docs/reading-cost.md +++ b/docs/reading-cost.md @@ -2570,3 +2570,20 @@ Read most (opens and searches): - `bin/failure.py` 1 - `bin/markdown_section/test_markdown_section.py` 1 - `bin/run-tests` 1 + +## Reading cost, chunk 4655673a30a9, finished 2026-11-17T11:46:22Z + +111449 new input tokens before the first commit. + +Read most (opens and searches): + +- `bin/review_replay/test_review_replay.py` 6 +- `README.md` 2 +- `bin/review_replay/main.py` 2 +- `bin/review_replay/replay.py` 2 +- `docs/decisions.md` 2 +- `CHANGELOG.md` 1 +- `bin/review_replay/omit_comparison.py` 1 +- `bin/rung_replay/archive.py` 1 +- `bin/rung_replay/search.py` 1 +- `bin/rung_replay/test_rung_replay.py` 1