Let a project's config name a working branch per epic that chunks branch off and merge into
CI / tests (pull_request) Successful in 5m4s

This commit is contained in:
Lilleman
2026-11-20 19:32:59 +01:00
parent 9531e5c337
commit 72a4d346d7
33 changed files with 991 additions and 56 deletions
+32 -7
View File
@@ -41,7 +41,11 @@ and prints that the release reviews and the cuts are the human's to call. It pri
each / of the branch a dash, on the branch the config's `branch` template names, which is
item-<ID> where the config names none. It continues a worktree already on that branch; else it adds one on the
local branch, else on a new branch tracking origin's, else on a new branch off the default
branch. Without --worktree, it prints that none was made;
branch. Without --worktree, it prints that none was made. Where the config sets `epic-branch`
(`project-config --help`), it first makes the working branch of the plan's epic on origin, off
the default branch, or merges the default branch into it; a new branch is then made off that
branch, and the checkout records that the chunk's pull request goes into it, for `chunk-pr`.
Where the two don't merge cleanly, it makes no worktree and says how a person merges them;
- each path the project's config sets, as `project-config` prints them in that worktree, or else
in the checkout;
- the language the config names for the project's prose, and its templates for commit titles,
@@ -81,7 +85,8 @@ import subprocess
import sys
import typing
from git_cli.git_repo import commit_exists, default_branch, file_at, git, top
from git_cli.git_repo import commit_exists, default_branch, file_at, git, record_chunk_base, top
from git_cli import epic_branch
from failure import Failure
from forge.commands import Forge, forge_of, Run, runner
from chunk_preflight.gathered import Gathered, ItemFacts, LeftWorktree, NamedPath, Ran, Worktree
@@ -91,7 +96,9 @@ from forge.pulls import merged_pull
from plan.named_paths import named_paths
from release_plan.next_chunk import NextChunk, NoItem, plan_name, planned
from release_plan.release_standing import project_plan
from project_config.settings import ProjectConfig
from chunk_preflight.choices import pulls_command, worktree_add, worktree_on, worktrees
from project_config import templates
BIN = pathlib.Path(__file__).resolve().parents[1]
# Each tool run in the item's worktree, {item} standing for the item's ID.
@@ -152,20 +159,38 @@ def preflight(root: pathlib.Path, timeout: float, make: bool, item_id: int | Non
forge_run = runner(str(root), timeout)
held = project_plan(config, ref, str(root), forge_run=forge_run)
plan = planned(held.plan, held.cut, ref, config.branch, outside, item_id)
item = plan if isinstance(plan, NoItem) else item_facts(root, ref, plan, timeout, make)
item = plan if isinstance(plan, NoItem) else item_facts(root, ref, plan, timeout, make, epic_branch_of(config))
# A `checkout:` path lands in the worktree the chunk works in.
made = located(str(item.worktree.path), pathlib.Path.home()) if isinstance(item, ItemFacts) and isinstance(item.worktree, Worktree) else config
return render(Gathered(ref, note, held.cut, item, plan_name(ref, outside), (config if isinstance(made, Failure) else made).places, outside is not None, config.texts, merges_unread=held.merges_unread, left=left_worktrees(root, forge_run) if config.merge == "human" else ()))
def item_facts(root: pathlib.Path, default: str, plan: NextChunk, timeout: float, make: bool) -> ItemFacts:
worktree = item_worktree(root, plan.branch, default) if make else Failure(f"none made, since it ran without {WORKTREE}.")
def epic_branch_of(config: ProjectConfig) -> str | None | Failure:
"""The working branch of the plan's epic, as the config's `epic-branch` names it; None where the config sets none."""
if config.epic_branch is None:
return None
if config.epic is None:
return Failure("none made: the config sets `epic-branch`, but its `plan` names no Jira epic to name the branch by; chunk-preflight makes an epic's chunks only from a plan kept in Jira")
return templates.epic_branch(config.epic_branch, config.epic.key)
def item_facts(root: pathlib.Path, default: str, plan: NextChunk, timeout: float, make: bool, epic: str | None | Failure = None) -> ItemFacts:
worktree = Failure(f"none made, since it ran without {WORKTREE}.") if not make else epic if isinstance(epic, Failure) else item_worktree(root, plan.branch, default, timeout, epic)
path = worktree.path if isinstance(worktree, Worktree) else None
return ItemFacts(plan, worktree, pull_listing(root, plan.branch, timeout), named_files(plan.text, path or root), tools_run(plan.first.id, path, timeout) if path else [])
def item_worktree(root: pathlib.Path, branch: str, default: str) -> Worktree | Failure:
"""The worktree on branch, made where none is; a Failure where git cannot make it, or its path holds something else."""
def item_worktree(root: pathlib.Path, branch: str, default: str, timeout: float | None = None, epic: str | None = None) -> Worktree | Failure:
"""The worktree on branch, made where none is; a Failure where git cannot make it, or its path holds something else.
epic names the working branch of the chunk's epic, where the project keeps one. The worktree then branches off that branch, which is first made on origin or brought level with default (`epic_branch.levelled`), and the checkout records that the chunk merges into it."""
if epic is not None:
level = epic_branch.levelled(epic, default, timeout=timeout)
recorded = level if isinstance(level, Failure) else record_chunk_base(branch, epic)
if isinstance(recorded, Failure):
return Failure(f"none made: {recorded.reason}")
made = item_worktree(root, branch, f"origin/{epic}")
return made if isinstance(made, Failure) else Worktree(made.path, f"{made.how} {level} Its pull request goes into {epic}.")
listing = git("worktree", "list", "--porcelain")
if isinstance(listing, Failure):
return listing