Answer principles round 1: 2 🔴, 9 🟡 (0 misread); explicit record versions in place of the Confluence store's hidden state, the routing ruling filed as item 393 for 0.12.0, rule-hook catching heavy runs through uv, poetry, sudo and doas, one unreleased heading, one owner of the no-item message, typed Jira issues, a turn that gives its failure as a value, outcome tests for the Atlassian client, an Emptied reason type, an injected clock and git in touch-predictions, and paired record names
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
import dataclasses
|
||||
|
||||
from plan_store.markdown_edits import bold_cell, plain
|
||||
from plan_store.plans import cells, Plan, Written
|
||||
from plan_store.plans import cells, no_item, Plan, Written
|
||||
from failure import Failure
|
||||
from plan.todo_table import Item, parse_row, SHAPE, Table
|
||||
|
||||
@@ -30,7 +30,7 @@ class MemoryPlan:
|
||||
|
||||
def edit(self, id_: int, fields: dict[str, str], detail: str | None, comment: str | None = None) -> Written | Failure:
|
||||
if id_ not in self.rows:
|
||||
return Failure(f"{self.label} holds no item {id_}")
|
||||
return Failure(no_item(self.label, id_))
|
||||
written = self.put(id_, self.rows[id_] | cells(fields), self.details.get(id_, "") if detail is None else detail)
|
||||
if comment is not None and isinstance(written, Written):
|
||||
self.comments.setdefault(id_, []).append(comment)
|
||||
@@ -38,7 +38,7 @@ class MemoryPlan:
|
||||
|
||||
def finish(self, id_: int) -> Written | Failure:
|
||||
if self.fails or id_ not in self.rows:
|
||||
return Failure(self.fails or f"{self.label} holds no item {id_}")
|
||||
return Failure(self.fails or no_item(self.label, id_))
|
||||
del self.rows[id_]
|
||||
self.details.pop(id_, None)
|
||||
return Written(id_)
|
||||
|
||||
+41
-31
@@ -12,7 +12,7 @@ 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.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, Plan, Written
|
||||
from plan_store.plans import cells, no_item, Plan, Written
|
||||
from project_config.settings import Epic, Finish, JIRA_FINISH_STATUS, JIRA_FINISH_TRANSITION
|
||||
from failure import Failure
|
||||
from plan.release import parsed, Release, tagged
|
||||
@@ -60,7 +60,7 @@ class Issue:
|
||||
# The key of each issue this one "is blocked by".
|
||||
blockers: tuple[str, ...]
|
||||
# PROPERTY's value; an empty object where the issue holds none.
|
||||
scores: object
|
||||
scores: dict[str, typing.Any]
|
||||
|
||||
@property
|
||||
def number(self) -> int:
|
||||
@@ -114,12 +114,10 @@ class JiraPlan:
|
||||
authorization = basic_auth(self.env_file)
|
||||
if isinstance(authorization, Failure):
|
||||
return authorization
|
||||
issue_fields = filing.fields
|
||||
if detail.strip():
|
||||
description = self.to_adf(detail)
|
||||
if isinstance(description, Failure):
|
||||
return Failure(f"cannot convert the item's detail to a Jira description: {description.reason}")
|
||||
issue_fields = issue_fields | {"description": description}
|
||||
description = self.description_of(detail)
|
||||
if isinstance(description, Failure):
|
||||
return description
|
||||
issue_fields = filing.fields | ({"description": description} if description else {})
|
||||
version = self.fix_version(filing.release, authorization)
|
||||
if isinstance(version, Failure):
|
||||
return version
|
||||
@@ -171,6 +169,22 @@ class JiraPlan:
|
||||
names = {name for version in versions if isinstance(version, dict) and isinstance(name := version.get("name"), str)} if isinstance(versions, list) else set()
|
||||
return next((name for name in (release, f"v{release}") if name in names), None) or Failure(f"the Jira project {project} has no Fix Version {release} or v{release}; create it in Jira, or name a release it has")
|
||||
|
||||
def child(self, id_: int, authorization: str) -> dict[str, typing.Any] | Failure:
|
||||
"""Item id_'s issue, as the epic's open children answer it; a Failure where none of them is item id_."""
|
||||
answered = children(self.epic, authorization, self.http)
|
||||
if isinstance(answered, Failure):
|
||||
return answered
|
||||
key = f"{project_of(self.epic.key)}-{id_}"
|
||||
found = next((raw for raw in answered if isinstance(raw, dict) and raw.get("key") == key), None)
|
||||
return Failure(no_item(self.label, id_)) if found is None else found
|
||||
|
||||
def description_of(self, detail: str) -> dict[str, typing.Any] | None | Failure:
|
||||
"""The Jira description that holds detail, as ADF; None for a blank detail, which leaves an issue without one."""
|
||||
if not detail.strip():
|
||||
return None
|
||||
description = self.to_adf(detail)
|
||||
return Failure(f"cannot convert the item's detail to a Jira description: {description.reason}") if isinstance(description, Failure) else description
|
||||
|
||||
def edit(self, id_: int, fields: dict[str, str], detail: str | None, comment: str | None = None) -> Written | Failure:
|
||||
"""Sets the fields and the detail in one request, so Jira takes all of the edit or none, and then posts comment on the issue. `revision_of` says what an edit may set.
|
||||
|
||||
@@ -178,24 +192,21 @@ class JiraPlan:
|
||||
authorization = basic_auth(self.env_file)
|
||||
if isinstance(authorization, Failure):
|
||||
return authorization
|
||||
answered = children(self.epic, authorization, self.http)
|
||||
if isinstance(answered, Failure):
|
||||
return answered
|
||||
key = f"{project_of(self.epic.key)}-{id_}"
|
||||
raw = next((raw for raw in answered if isinstance(raw, dict) and raw.get("key") == key), None)
|
||||
if raw is None:
|
||||
return Failure(f"{self.label} holds no item {id_}")
|
||||
raw = self.child(id_, authorization)
|
||||
if isinstance(raw, Failure):
|
||||
return raw
|
||||
issue = issue_of(raw)
|
||||
if isinstance(issue, Failure):
|
||||
return issue
|
||||
key = issue.key
|
||||
revision = revision_of(issue, cells(fields), detail, comment)
|
||||
if isinstance(revision, Failure):
|
||||
return revision
|
||||
body = revision.body
|
||||
if detail is not None:
|
||||
description = self.to_adf(detail) if detail.strip() else None
|
||||
description = self.description_of(detail)
|
||||
if isinstance(description, Failure):
|
||||
return Failure(f"cannot convert the item's detail to a Jira description: {description.reason}")
|
||||
return description
|
||||
body = body | {"fields": body.get("fields", {}) | {"description": description}}
|
||||
said = self.to_adf(comment) if comment and comment.strip() else None
|
||||
if isinstance(said, Failure):
|
||||
@@ -221,12 +232,10 @@ class JiraPlan:
|
||||
authorization = basic_auth(self.env_file)
|
||||
if isinstance(authorization, Failure):
|
||||
return authorization
|
||||
answered = children(self.epic, authorization, self.http)
|
||||
if isinstance(answered, Failure):
|
||||
return answered
|
||||
raw = self.child(id_, authorization)
|
||||
if isinstance(raw, Failure):
|
||||
return raw
|
||||
key = f"{project_of(self.epic.key)}-{id_}"
|
||||
if not any(isinstance(raw, dict) and raw.get("key") == key for raw in answered):
|
||||
return Failure(f"{self.label} holds no item {id_}")
|
||||
url = f"{self.epic.site}/rest/api/3/issue/{key}/transitions"
|
||||
offered = self.http("GET", url, authorization, None)
|
||||
if isinstance(offered, Failure):
|
||||
@@ -292,7 +301,7 @@ def placing(answered: list[object], new: Item, value: float, scoring: ranking.Sc
|
||||
issue = issue_of(raw)
|
||||
if isinstance(issue, Failure):
|
||||
return issue
|
||||
if not isinstance(issue.scores, dict) or issue.scores.get(FILED_BY[0]) != FILED_BY[1]:
|
||||
if issue.scores.get(FILED_BY[0]) != FILED_BY[1]:
|
||||
continue
|
||||
scored = scores(issue.key, issue.scores)
|
||||
if isinstance(scored, Failure):
|
||||
@@ -322,8 +331,6 @@ def revision_of(issue: Issue, named: dict[str, str], detail: str | None, comment
|
||||
|
||||
The summary, description and Fix Version of an issue a person filed are the team's, so there an edit may set only SCORED. Jira's screens don't show PROPERTY, so such an edit needs a comment, which tells the team. L, E, I and S are set together, so no issue is left partly scored. An issue the loop filed also keeps the label SECURITY in step with its Exempt. No edit changes a link."""
|
||||
held = issue.scores
|
||||
if not isinstance(held, dict):
|
||||
return Failure(f"{issue.key}'s issue property {PROPERTY} is not a JSON object")
|
||||
if BLOCKED_BY in named:
|
||||
return Failure(f"the loop doesn't change an issue's links: link {issue.key} in Jira")
|
||||
own = held.get(FILED_BY[0]) == FILED_BY[1]
|
||||
@@ -419,14 +426,19 @@ def children(epic: Epic, authorization: str, http: Http) -> list[object] | Failu
|
||||
def issue_of(raw: object) -> Issue | Failure:
|
||||
"""The issue in one entry of the search's answer, or which issue is not in the shape Jira documents, and how."""
|
||||
key = raw.get("key") if isinstance(raw, dict) else None
|
||||
if not isinstance(key, str) or not ISSUE_KEY.fullmatch(key):
|
||||
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 = typing.cast(dict[str, typing.Any], raw)["fields"]
|
||||
fields = raw["fields"]
|
||||
blockers = tuple(link["inwardIssue"]["key"] for link in fields["issuelinks"] if "inwardIssue" in link and link["type"]["inward"] == "is blocked by")
|
||||
issue = Issue(key, fields["summary"].strip(), fields["description"], tuple(version["name"] for version in fields["fixVersions"]), blockers, typing.cast(dict[str, typing.Any], raw).get("properties", {}).get(PROPERTY, {}))
|
||||
held = raw.get("properties", {}).get(PROPERTY, {})
|
||||
summary, description, versions = fields["summary"].strip(), fields["description"], tuple(version["name"] for version in fields["fixVersions"])
|
||||
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 isinstance(held, dict):
|
||||
return Failure(f"{key}'s issue property {PROPERTY} is not a JSON object")
|
||||
issue = Issue(key, summary, description, versions, blockers, held)
|
||||
if not isinstance(issue.description, dict | None) or not all(isinstance(name, str) for name in issue.fix_versions + issue.blockers) or not all(ISSUE_KEY.fullmatch(blocker) for blocker in issue.blockers):
|
||||
return Failure(f"{key} is not in the shape Jira Cloud's REST API version 3 documents: its description, a Fix Version's name or a linked issue's key holds another kind of value")
|
||||
return issue
|
||||
@@ -481,9 +493,7 @@ def earliest_release(names: tuple[str, ...]) -> Release | None:
|
||||
return min(releases, default=None)
|
||||
|
||||
|
||||
def scores(key: str, held: object) -> ItemFields | Failure:
|
||||
def scores(key: str, held: dict[str, typing.Any]) -> ItemFields | Failure:
|
||||
"""The scores, Moves and Exempt that an issue's PROPERTY value holds, each in the format the items table of a todo.md takes."""
|
||||
if not isinstance(held, dict):
|
||||
return Failure(f"{key}'s issue property {PROPERTY} is not a JSON object")
|
||||
named = {name: str(value) for name, value in held.items() if name in (*SHAPE.score_columns, MOVES, "Exempt")}
|
||||
return item_fields(named, f"item {key}")
|
||||
|
||||
@@ -3,6 +3,7 @@ import re
|
||||
|
||||
from plan.todo_table import cells, detail_heading, DETAILS, item_details, items_table, Table, tagline_text
|
||||
from failure import Failure
|
||||
from plan_store.plans import no_item
|
||||
from plan.ranking import stated
|
||||
|
||||
# A line that would end ## Details (##) or could open another item's detail (###).
|
||||
@@ -113,7 +114,7 @@ def row_index(table: Table, id_: int, label: str) -> int | Failure:
|
||||
return found
|
||||
if found[0] == str(id_):
|
||||
return at
|
||||
return Failure(f"{label} holds no item {id_}")
|
||||
return Failure(no_item(label, id_))
|
||||
|
||||
|
||||
def held_table(lines: list[str], label: str) -> Table | Failure:
|
||||
|
||||
@@ -54,6 +54,16 @@ class PlanStore(typing.Protocol):
|
||||
"""Removes item id_ with its detail."""
|
||||
|
||||
|
||||
def no_item(label: str, id_: int | str) -> str:
|
||||
"""What every store says of an item id_ that the plan label names doesn't hold. `chunk-pr merge` reads `todo-item show`'s answer by it, through says_no_item."""
|
||||
return f"{label} holds no item {id_}"
|
||||
|
||||
|
||||
def says_no_item(reason: str, id_: int | str) -> bool:
|
||||
"""Whether a failure's reason, such as `todo-item show`'s, says the plan doesn't hold item id_, as no_item words it."""
|
||||
return no_item("", id_) in reason
|
||||
|
||||
|
||||
def cells(fields: dict[str, str]) -> dict[str, str]:
|
||||
"""fields by the items table's column names."""
|
||||
unknown = set(fields) - set(FIELDS)
|
||||
|
||||
Reference in New Issue
Block a user