Answer principles round 1: 1 🔴, 7 🟡 (0 misread); every effect is handed in as an argument, no test patches a global, and the traces principle scopes tools that run on their user's machine
CI / tests (pull_request) Successful in 3m43s
CI / tests (pull_request) Successful in 3m43s
This commit is contained in:
+38
-15
@@ -16,7 +16,8 @@ DONE = "done"
|
||||
# What a failed create ends with: a request Jira never answered, or answered brokenly, may still have filed the issue.
|
||||
PERHAPS_FILED = "unless Jira refused the request, the issue may exist: look under {under} before filing it again"
|
||||
# What a failed move ends with, for the same reason.
|
||||
PERHAPS_MOVED = "unless Jira refused the request, the issue may have moved: look at {key} before finishing the item again"
|
||||
SHAPE = "is not in the shape Jira Cloud's REST API version 3 documents"
|
||||
PERHAPS_MOVED ="unless Jira refused the request, the issue may have moved: look at {key} before finishing the item again"
|
||||
|
||||
|
||||
@dataclasses.dataclass(frozen=True)
|
||||
@@ -44,17 +45,21 @@ def entry_of(raw: object, property_: str) -> Entry | Failure:
|
||||
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, as a Failure, so no later step meets it.
|
||||
try:
|
||||
fields = raw["fields"]
|
||||
return Entry(key, fields, blocked_by_links(fields), raw.get("properties", {}).get(property_, {}))
|
||||
except (AttributeError, KeyError, TypeError) as failure:
|
||||
return Failure(unshaped(key, failure))
|
||||
# Each nested field is checked as Jira documents it; one missing or of another type ends the read here, as a Failure, so no later step meets it.
|
||||
fields, properties = raw.get("fields"), raw.get("properties", {})
|
||||
if not isinstance(fields, dict):
|
||||
return Failure(f"{key} {SHAPE}: its fields are no object")
|
||||
if not isinstance(properties, dict):
|
||||
return Failure(f"{key} {SHAPE}: its properties are no object")
|
||||
links = blocked_by_links(fields)
|
||||
if isinstance(links, Failure):
|
||||
return Failure(f"{key} {SHAPE}: {links.reason}")
|
||||
return Entry(key, fields, links, properties.get(property_, {}))
|
||||
|
||||
|
||||
def unshaped(key: str, failure: Exception) -> str:
|
||||
"""Why the issue named key cannot be read, for a field that is missing or of another type than Jira documents."""
|
||||
return f"{key} is not in the shape Jira Cloud's REST API version 3 documents: {failure!r}"
|
||||
return f"{key} {SHAPE}: {failure!r}"
|
||||
|
||||
|
||||
def offer_of(raw: object) -> tuple[str, str, str, str] | None:
|
||||
@@ -115,11 +120,11 @@ def rank_refusal(site: str, key: str, before: str, authorization: str, http: Htt
|
||||
return "; ".join(str(error) for entry in refused for error in entry.get("errors") or [f"Jira answered {entry.get('status')}"]) or None
|
||||
|
||||
|
||||
def searched(site: str, what: str, jql: str, asked: dict[str, object], authorization: str, http: Http) -> list[object] | Failure:
|
||||
"""Every issue a JQL search on site finds, page by page. The dict asked holds the request's `fields` and `properties` lists. The text what names the issues sought, in the Failure of a search that doesn't end."""
|
||||
def searched(site: str, what: str, jql: str, asked: dict[str, object], authorization: str, http: Http, max_pages: int = MAX_PAGES) -> list[object] | Failure:
|
||||
"""Every issue a JQL search on site finds, page by page, up to max_pages pages. The dict asked holds the request's `fields` and `properties` lists. The text what names the issues sought, in the Failure of a search that doesn't end."""
|
||||
body: dict[str, object] = {"jql": jql, "maxResults": PAGE} | asked
|
||||
found: list[object] = []
|
||||
for _ in range(MAX_PAGES):
|
||||
for _ in range(max_pages):
|
||||
page = http("POST", f"{site}/rest/api/3/search/jql", authorization, body)
|
||||
if isinstance(page, Failure):
|
||||
return page
|
||||
@@ -129,9 +134,27 @@ def searched(site: str, what: str, jql: str, asked: dict[str, object], authoriza
|
||||
if not page.get("nextPageToken"):
|
||||
return found
|
||||
body = body | {"nextPageToken": page["nextPageToken"]}
|
||||
return Failure(f"the search for {what} did not end within {MAX_PAGES} pages")
|
||||
return Failure(f"the search for {what} did not end within {max_pages} pages")
|
||||
|
||||
|
||||
def blocked_by_links(fields: dict[str, typing.Any]) -> tuple[Link, ...]:
|
||||
"""The "is blocked by" links among an issue's `issuelinks` field. A field not in the shape Jira documents raises a KeyError or TypeError, which the caller turns into a Failure."""
|
||||
return tuple(Link(link["inwardIssue"]["key"], link["id"]) for link in fields["issuelinks"] if "inwardIssue" in link and link["type"]["inward"] == "is blocked by")
|
||||
def blocked_by_links(fields: dict[str, typing.Any]) -> tuple[Link, ...] | Failure:
|
||||
"""The "is blocked by" links among an issue's `issuelinks` field, or how that field is not in the shape Jira documents."""
|
||||
listed = fields.get("issuelinks")
|
||||
if not isinstance(listed, list):
|
||||
return Failure("its issuelinks are no list")
|
||||
found = []
|
||||
for link in listed:
|
||||
if not isinstance(link, dict):
|
||||
return Failure("its issuelinks hold a link that is no object")
|
||||
if "inwardIssue" not in link:
|
||||
continue
|
||||
kind = link.get("type")
|
||||
if not isinstance(kind, dict) or not isinstance(kind.get("inward"), str):
|
||||
return Failure("its issuelinks hold a link whose type names no inward text")
|
||||
if kind["inward"] != "is blocked by":
|
||||
continue
|
||||
blocker, id_ = link["inwardIssue"], link.get("id")
|
||||
if not isinstance(blocker, dict) or not isinstance(blocker.get("key"), str) or not isinstance(id_, str):
|
||||
return Failure("its issuelinks hold a link whose id or whose linked issue's key is no text")
|
||||
found.append(Link(blocker["key"], id_))
|
||||
return tuple(found)
|
||||
|
||||
Reference in New Issue
Block a user