"""How an epic ends (docs/decisions.md → `do-epic: drives one Jira epic …` → "Finishing"). Once the epic holds issues and none is open, its finishing chunk runs, in a window named for the epic's key. It has no issue: `task` is its task, which follows the epic's state. 1. While a repo the epic changed lacks a release review, the chunk files one issue per such repo, labelled REVIEW_LABEL, and ends. Each such issue runs as any issue's chunk does, and so does each issue its review files. 2. With each repo reviewed, the human confirms each goal. For a goal they don't confirm, the chunk files the set of items they approve, and ends. 3. With every goal confirmed, `do-epic --close-epic` posts the summary on the epic and closes it. The chunk starts again each time the epic holds no open issue, until the epic is closed. A repo is reviewed once per epic, as a release is: the issues filed after its review don't bring another.""" import pathlib import typing from do_epic.chunk_prompt import DRIVER from do_epic.backend.protocol import EpicIssue, EpicStore from failure import Failure from do_epic import findings from do_epic.split import finished from do_epic.repo_pick import label_of, LabelRepos, recorded, Repo, REVIEW_LABEL from text_files.markdown_text import listed from text_files.piped_text import piped # Not `--close`, which reads as closing the run or one issue: three readers, seated as the human, as a chunk's worker and as one of the client's team, picked this one from four, 2-1 over it. CLOSE = "--close-epic" USAGE = f"do-epic {CLOSE} <<'EOF' summary EOF" HELP = f"""Once every issue is done, the epic's finishing chunk runs, in a window named for the epic. It files a release review of each repo the epic changed, as an issue labelled `{REVIEW_LABEL}`, then asks you to confirm each goal. {CLOSE} posts the markdown piped in on the epic as its summary, then closes the epic. It refuses while an issue is open or a repo lacks its review. It closes the epic by the transition `jira-finish-transition` names, to the status `jira-finish-status` names.""" def due(issues: list[EpicIssue]) -> bool: """Whether the epic's finishing comes next: it holds an issue, and none is open.""" return bool(issues) and not still_open(issues) def still_open(issues: list[EpicIssue]) -> list[str]: """The key of each issue that isn't done; an item split by repo is done once its sub-tasks are.""" return [issue.key for issue in issues if not finished(issues, issue.key)] def repo_of(issue: EpicIssue, team: LabelRepos) -> str | None: """The name of the repo the issue's labels record; None where they record none.""" pick = recorded(issue, team) return pick.name if isinstance(pick, Repo) else None def unreviewed(issues: list[EpicIssue], team: LabelRepos) -> list[str]: """The repos the epic changed that have no release review, sorted. The epic changed a repo where a done issue names it, and a repo has its review once an issue labelled REVIEW_LABEL names it, open or done.""" reviewed = {repo_of(issue, team) for issue in issues if REVIEW_LABEL in issue.labels} changed = {repo_of(issue, team) for issue in issues if issue.done and REVIEW_LABEL not in issue.labels} return sorted(repo for repo in changed - reviewed if repo is not None) def task(epic: str, issues: list[EpicIssue], team: LabelRepos, launcher: pathlib.Path, language: str) -> str: """The finishing chunk's task, for the epic with the key epic as issues has it. launcher is the do-epic that runs the chunk, and language the one the epic's Jira text is in.""" opening = f"Finish the epic {epic}, which holds no open issue, as one chunk that changes no repo: work in the folder you start in." if lacking := unreviewed(issues, team): return ( f"{opening} Each repo the epic changed takes a release review first, and {listed(lacking, 'and')} {'has' if len(lacking) == 1 else 'have'} none. " f"File one issue per such repo, with `{launcher} {epic} {findings.FILE} \"\" {findings.LABEL}