File a finding and record a decision in a do-epic epic, and give the judge the epic's records beside the repo's
CI / tests (pull_request) Failing after 4m22s
CI / tests (pull_request) Failing after 4m22s
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
"""What a chunk's worker writes into its epic: a finding, filed as an issue, and a decision, appended to the description.
|
||||
|
||||
A finding about one of the epic's goals is filed in the epic, and one about a repo's goals by that repo's rules (docs/decisions.md → `do-epic: drives one Jira epic …` → "Findings"). A decision that governs the epic goes under the description's ## Decisions, where the judge of each later chunk reads it."""
|
||||
import typing
|
||||
|
||||
from do_epic.backend.protocol import EpicStore
|
||||
from do_epic.epic_record import EpicRecord
|
||||
from failure import Failure
|
||||
from text_files.piped_text import piped
|
||||
|
||||
# Three readers, seated as the human and as a chunk's worker, ranked four spellings of each flag: `<EPIC-KEY> --file` came first, second and second, ahead of `--file <EPIC-KEY>`, `add` and `--finding`; `--record-decision` won 2-1 over `--decision`, since `--decide` reads as do-epic deciding.
|
||||
FILE = "--file"
|
||||
LABEL = "--label"
|
||||
RECORD_DECISION = "--record-decision"
|
||||
USAGE = f"""do-epic <EPIC-KEY> {FILE} <summary> [{LABEL} <label>] [<<'EOF' detail EOF]
|
||||
do-epic <EPIC-KEY> {RECORD_DECISION} <title> <<'EOF' entry EOF"""
|
||||
HELP = f"""{FILE} files a finding about one of the epic's goals as an open issue of the epic, with the markdown piped in as its description.
|
||||
{LABEL} names its repo, or says the work changes no repo; without one the issue waits.
|
||||
A finding about a repo's own goals goes into that repo's plan instead.
|
||||
{RECORD_DECISION} appends a decision that governs the epic to its description's ## Decisions, under the title, with the markdown piped in as its text."""
|
||||
|
||||
|
||||
def instructions(epic: str) -> str:
|
||||
"""What a chunk's first prompt says about filing a finding and recording a decision in the epic with the key epic."""
|
||||
return (
|
||||
f"File a finding about one of the epic's goals in the epic, with `do-epic {epic} {FILE} \"<summary>\" [{LABEL} <label>]` and its detail on stdin. "
|
||||
"File one about a repo's goals by that repo's rules. Where unsure which, ask the human. "
|
||||
f"Record a decision that governs the epic, such as an answer the human typed, with `do-epic {epic} {RECORD_DECISION} \"<title>\"` and its text on stdin."
|
||||
)
|
||||
|
||||
|
||||
def parsed(words: list[str]) -> tuple[str, str, str | None] | None:
|
||||
"""The flag, its one value and the label of the words after the epic's key; None where they aren't a filing or a decision spelt as USAGE has them. A word that opens with `--` is no summary, title or label."""
|
||||
if not words or words[0] not in (FILE, RECORD_DECISION):
|
||||
return None
|
||||
label: str | None = None
|
||||
rest = words[1:]
|
||||
if words[0] == FILE and LABEL in rest:
|
||||
at = rest.index(LABEL)
|
||||
if at + 1 >= len(rest):
|
||||
return None
|
||||
label, rest = rest[at + 1], rest[:at] + rest[at + 2:]
|
||||
if len(rest) != 1 or any(word.startswith("--") for word in (*rest, label or "")):
|
||||
return None
|
||||
return words[0], rest[0], label
|
||||
|
||||
|
||||
def written(epic: str, flag: str, value: str, label: str | None, store: EpicStore, record: EpicRecord, stdin: typing.TextIO) -> str | Failure:
|
||||
"""Files the finding or records the decision, as flag says, and answers the line to print."""
|
||||
text = piped(stdin)
|
||||
if flag == FILE:
|
||||
key = store.file(epic, value, text, (label,) if label else ())
|
||||
if isinstance(key, Failure):
|
||||
return Failure(f"cannot file the finding in the epic {epic}: {key.reason}")
|
||||
return f"Filed {key} in the epic {epic}." + ("" if label else " It waits until a label names its repo.")
|
||||
recorded = record.append_decision(value, text)
|
||||
if isinstance(recorded, Failure):
|
||||
return Failure(f"cannot record the decision in the epic {epic}'s description: {recorded.reason}")
|
||||
return f"Recorded the decision in the epic {epic}'s description."
|
||||
Reference in New Issue
Block a user