Let do-epic --file take --blocked-by and --parent, so a change a repo ships as two pull requests gets an issue for each
CI / tests (pull_request) Failing after 3m45s

This commit is contained in:
Lilleman
2026-11-19 15:52:49 +01:00
parent 017cf33611
commit b2630b8148
10 changed files with 123 additions and 29 deletions
+19 -4
View File
@@ -7,9 +7,9 @@ from adf_codec.convert import adfs_to_markdown, markdown_to_adf, Refused
from atlassian.client import basic_auth, Http, jira_json, ToAdf, ToMarkdown
from atlassian.jira import DONE, entry_of, finishing_transition, ISSUE_KEY, MAX_PAGES, move_refusal, PERHAPS_FILED, PERHAPS_MOVED, project_of, rank_refusal, searched, SHAPE, status_category, unshaped
from project_config.settings import Epic, Finish, JIRA_FINISH_STATUS, JIRA_FINISH_TRANSITION
from do_epic.backend.protocol import EpicIssue, no_child, no_parent, no_words, unfit, unfit_label
from do_epic.backend.protocol import EpicIssue, no_blocker, no_child, no_parent, no_words, unfit, unfit_label
from failure import Failure
from plan_store.jira_epic import FILED_BY, ISSUE_TYPE, PROPERTY, scores
from plan_store.jira_epic import BLOCKS, FILED_BY, ISSUE_TYPE, PROPERTY, scores
FIELDS = ["summary", "description", "labels", "assignee", "status", "parent", "issuelinks"]
# How many child issues one search for sub-tasks names, which keeps its JQL well inside the length Jira takes.
@@ -57,11 +57,11 @@ class JiraEpic:
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:
def file(self, parent: str, summary: str, detail: str, labels: tuple[str, ...], blocked_by: str | None = None) -> str | Failure:
authorization = basic_auth(self.env_file)
if isinstance(authorization, Failure):
return authorization
if refused := unfit(summary, labels) or self.not_a_parent(parent, authorization):
if refused := unfit(summary, labels) or self.not_a_parent(parent, authorization) or (blocked_by and self.not_a_blocker(blocked_by, authorization)):
return refused
fields: dict[str, typing.Any] = {"project": {"key": project_of(parent)}, "parent": {"key": parent}, "summary": summary, "labels": list(labels)}
# Marks the issue as the loop's, as plan_store marks the items it files.
@@ -80,6 +80,11 @@ class JiraEpic:
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(under=parent)}")
if blocked_by:
# Jira names the two ends by the link type's sides: the inward issue blocks the outward one, which then reads "is blocked by" it.
linked = self.http("POST", f"{self.epic.site}/rest/api/3/issueLink", authorization, {"type": {"name": BLOCKS}, "inwardIssue": {"key": blocked_by}, "outwardIssue": {"key": key}})
if isinstance(linked, Failure):
return Failure(f"filed {key} under {parent}, but cannot link it as blocked by {blocked_by}: {linked.reason}; link it in Jira")
return key
def add_label(self, key: str, label: str) -> None | Failure:
@@ -184,6 +189,16 @@ class JiraEpic:
above = self.parent_of(parent, authorization, "to file under it")
return above if isinstance(above, Failure) else None if above == self.epic_key else no_parent(self.epic_key, parent)
def not_a_blocker(self, blocker: str, authorization: str) -> Failure | None:
"""Why nothing can be filed blocked by blocker; None where it is a child issue of the epic or a sub-task of one."""
above = self.parent_of(blocker, authorization, "to file blocked by it")
if isinstance(above, Failure):
return above
if above == self.epic_key:
return None
grand = None if above is None else self.parent_of(above, authorization, "to file blocked by it")
return grand if isinstance(grand, Failure) else None if grand == self.epic_key else no_blocker(self.epic_key, blocker)
def parent_of(self, key: str, authorization: str, why: str) -> str | None | Failure:
"""The key of key's parent issue; None where key isn't an issue key or has no parent. A failed read says "cannot read <key> <why>"."""
placed = self.placed(key, authorization, why)