Answer stability round 1: 0 🔴, 1 🟡 (0 misread); name every step a start could not take, and who else holds the issue

This commit is contained in:
Lilleman
2026-11-20 18:39:55 +01:00
parent 6bd146395c
commit ea58203b1a
2 changed files with 31 additions and 16 deletions
+13 -10
View File
@@ -1,4 +1,4 @@
"""How a Jira issue shows its team that its work is under way: assigned, moved by the team's start transition and in a board's active sprint. JiraEpic.start_issue calls `started` for an issue it found in its epic."""
"""How a Jira issue shows its team that its work is under way: assigned, moved by the team's start transition and in a board's active sprint."""
import dataclasses
import typing
@@ -6,7 +6,7 @@ from failure import Failure
from atlassian.client import Http
from atlassian.jira import offers_of, unshaped
# Three readers, seated as those who write and read do-epic's config, picked both spellings from four candidates each, 3-0. `jira-start-transition` pairs with `jira-finish-transition`. `jira-board` reads as the board do-epic takes its issues from.
# Three readers, seated as those who write and read do-epic's config, picked both spellings from four candidates each, 3-0. `jira-start-transition` pairs with `jira-finish-transition`. `jira-board`, a candidate they turned down, reads as the board do-epic takes its issues from.
START_TRANSITION = "jira-start-transition"
SPRINT_BOARD = "jira-sprint-board"
# The key of the category Jira gives each status at which an issue's work hasn't started.
@@ -22,22 +22,25 @@ class Start:
@dataclasses.dataclass(frozen=True)
class Held:
"""An issue as Jira holds it before it starts. holder is its assignee's account ID and display name; None where nobody is assigned."""
"""What Jira answers about an issue before it starts. holder is its assignee's account ID and display name; None where nobody is assigned."""
holder: tuple[str, str] | None
status: str
category: str
def started(site: str, key: str, sprint_key: str, start: Start, authorization: str, http: Http) -> str | None | Failure:
"""Starts the issue named key, where sprint_key is the issue a sprint takes for it: the issue itself, or the parent of a sub-task. The answer is the display name of someone else who holds the issue, else None; a Failure names the first step Jira did not take."""
"""Starts the issue named key, where sprint_key is the issue a sprint takes for it: the issue itself, or the parent of a sub-task. The answer is the display name of someone else who holds the issue, else None. A Failure names each step Jira did not take, and that someone else who holds the issue."""
held = held_of(site, key, authorization, http)
if isinstance(held, Failure):
return held
other = assigned(site, key, held, authorization, http)
# A status in any later category, such as Code Review, is past the start transition, so the issue keeps it.
moved = move_refusal(site, key, held.status, start.transition, authorization, http) if start.transition and held.category == NEW else None
moved = start_refusal(site, key, held.status, start.transition, authorization, http) if start.transition and held.category == NEW else None
joined = sprint_refusal(site, sprint_key, start.sprint_board, authorization, http) if start.sprint_board is not None else None
return next((step for step in (other, moved, joined) if isinstance(step, Failure)), other)
refused = [step.reason for step in (other, moved, joined) if isinstance(step, Failure)]
if not refused:
return other
return Failure("; ".join(refused) + (f"; {key} stays assigned to {other}" if isinstance(other, str) else ""))
def held_of(site: str, key: str, authorization: str, http: Http) -> Held | Failure:
@@ -65,7 +68,7 @@ def assigned(site: str, key: str, held: Held, authorization: str, http: Http) ->
return Failure(f"cannot assign {key}: {put.reason}") if isinstance(put, Failure) else None
def move_refusal(site: str, key: str, status: str, transition: str, authorization: str, http: Http) -> Failure | None:
def start_refusal(site: str, key: str, status: str, transition: str, authorization: str, http: Http) -> Failure | None:
"""Moves the issue named key, which has the status named status, by the transition named transition. Why Jira did not take the move; None where it did."""
offered = http("GET", f"{site}/rest/api/3/issue/{key}/transitions", authorization, None)
if isinstance(offered, Failure):
@@ -76,13 +79,13 @@ def move_refusal(site: str, key: str, status: str, transition: str, authorizatio
named = [id_ for id_, name, _, _ in offers if name == transition]
if not named:
others = " and ".join(f"{name!r} to {to!r}" for _, name, to, _ in offers)
return Failure(f"{key} has no transition {transition!r} from its status {status!r}, " + (f"only {others}: name in `{START_TRANSITION}` one that its statuses before work starts have" if offers else "nor any other the account may make"))
return Failure(f"{key} has no transition {transition!r} from its status {status!r}, " + (f"only {others}: set `{START_TRANSITION}` to a transition the issue has before its work starts" if offers else "nor any other the account may make"))
moved = http("POST", f"{site}/rest/api/3/issue/{key}/transitions", authorization, {"transition": {"id": named[0]}})
return Failure(f"cannot move {key} by {transition!r}: {moved.reason}") if isinstance(moved, Failure) else None
def sprint_refusal(site: str, key: str, board: int, authorization: str, http: Http) -> Failure | None:
"""Adds the issue named key to the one active sprint of the board with the ID board. Why it joined none; None where it joined."""
"""Adds the issue named key to the one active sprint of the board with the ID board. Why it didn't join one; None where it joined."""
answered = http("GET", f"{site}/rest/agile/1.0/board/{board}/sprint?state=active", authorization, None)
if isinstance(answered, Failure):
return Failure(f"cannot read the active sprint of board {board}, which `{SPRINT_BOARD}` names: {answered.reason}")
@@ -91,6 +94,6 @@ def sprint_refusal(site: str, key: str, board: int, authorization: str, http: Ht
if not isinstance(values, list) or len(sprints) != len(values):
return Failure(f"Jira answered board {board}'s sprints in a shape other than the one it documents")
if len(sprints) != 1:
return Failure(f"board {board}, which `{SPRINT_BOARD}` names, has {f"{len(sprints)} active sprints" if sprints else "no active sprint"}, so {key} joins none")
return Failure(f"board {board}, which `{SPRINT_BOARD}` names, has {f"{len(sprints)} active sprints" if sprints else "no active sprint"}, so {key} doesn't join a sprint")
added = http("POST", f"{site}/rest/agile/1.0/sprint/{sprints[0]}/issue", authorization, {"issues": [key]})
return Failure(f"cannot add {key} to the active sprint of board {board}: {added.reason}") if isinstance(added, Failure) else None