Answer stability round 1: 1 🔴, 5 🟡 (0 misread); hold a pull request's base on the forge to the recorded one, ask origin for the epic branch, and name where a chunk's work landed
CI / tests (pull_request) Successful in 3m46s

This commit is contained in:
Lilleman
2026-11-20 21:42:32 +01:00
parent 525f3f8836
commit d464f271bf
13 changed files with 352 additions and 74 deletions
+25 -10
View File
@@ -13,13 +13,17 @@ pull request only while its head is the commit checked out, so push before you r
Where the project's config sets `epic-branch` (`project-config --help`), a chunk's pull request
goes into its epic's working branch, which chunk-preflight or do-epic recorded for the chunk's
branch when the chunk began. There, each step below reads "origin's default branch" as that
branch, with these differences:
branch as it started or continued the chunk. There, each step below reads "origin's default
branch" as that branch, with these differences:
- merge merges the pull request itself, whatever `merge` and `wait-for-approval` say: those
govern the pull request into the default branch, which open-epic opens;
- ready and push ask for a review, where the config sets `review-request-comment`, by making
that comment on the pull request;
- clean still fast-forwards the main checkout to origin's default branch.
ready and merge fail, naming both branches, where the forge merges the pull request into another
branch than the one recorded, or than the default branch where the checkout records none. A person
then settles which holds: they change the pull request's base on the forge, or the record, which
is `branch.<branch>.chunk-base` in git's config.
open pushes the branch, setting its upstream, and opens a draft pull request into origin's
default branch. <title> is one line, as ~/.claude/CLAUDE.md → "Git, commits, and PRs"
@@ -99,7 +103,8 @@ open-epic runs in any checkout of the repository, once the epic's last chunk ha
that branch into the default branch, ready and titled <title>, and leaves it to a person
to merge. Where the two don't merge cleanly it doesn't open anything and says how a
person merges them. Where the pull request is open already, it doesn't open a second
one. It fails where the config sets no `epic-branch`, or origin has no such branch.
one. It fails where the config sets no `epic-branch`, or origin has no such branch, as
once its pull request has merged and the forge deleted it.
It prints what it did, exit 0, or why it failed, exit 1.
"""
@@ -115,8 +120,8 @@ import time
import typing
from chunk_pr.approval import approval, approved, awaited, left_to_a_person, left_to_park, PARKS, unanswered
from forge.pulls import checks_passed, merged_pull, open_pull, required_checks
from git_cli.git_repo import CHUNK_BASE
from forge.pulls import checks_passed, merged_pull, open_pull, other_base, required_checks
from git_cli.git_repo import CHUNK_BASE, Git
from git_cli import epic_branch
from failure import Failure
from forge.commands import Forge, forge_of, gitea, Run, runner
@@ -239,7 +244,7 @@ def base_of(branch: str, run: Run) -> Base | Failure:
def pull(run: Run) -> tuple[Forge, str, str] | Failure:
"""The forge, the number of the branch's open pull request at its head, and that head."""
"""The forge, the number of the branch's open pull request at its head, and that head. A Failure where the forge merges that pull request into another branch than `base_of` names: that base says whether a person merges, so no step acts while the two differ."""
found = checkout(run)
if isinstance(found, Failure):
return found
@@ -247,7 +252,12 @@ def pull(run: Run) -> tuple[Forge, str, str] | Failure:
number = open_pull(forge, branch, head, run)
if number is None:
return Failure(f"no pull request from origin's {branch} is open at {head[:12]}; push the branch, or open one with chunk-pr open")
return number if isinstance(number, Failure) else (forge, number, head)
if isinstance(number, Failure):
return number
base = base_of(branch, run)
if isinstance(base, Failure):
return base
return other_base(forge, number, base.branch, run) or (forge, number, head)
def opened(title: str, body: str, run: Run) -> str | Failure:
@@ -402,10 +412,12 @@ def epic_opened(epic: str, title: str, body: str, run: Run, config: Config) -> s
if isinstance(default, Failure):
return default
forge = forge_of(found[0])
git: Git = lambda *args, cwd=None, timeout=None, guarded=False, errors="strict": run(["git", *args])
# `levelled` makes a branch origin lacks, which here would be a stray one: a mistyped key, or a branch its merge deleted.
if isinstance(held := answers(run, ["fetch", "--quiet", "origin"]), Failure) or isinstance(run(["git", "rev-parse", "--quiet", "--verify", f"refs/remotes/origin/{branch}"]), Failure):
return held if isinstance(held, Failure) else Failure(f"origin has no branch {branch}, so no chunk of {epic} has merged into one: check the epic's key, and whether the branch's pull request merged already")
level = epic_branch.levelled(branch, f"origin/{default}", run=lambda *args, cwd=None, timeout=None, guarded=False, errors="strict": run(["git", *args]))
held = epic_branch.on_origin(branch, None, None, git)
if not held:
return Failure(f"origin has no branch {branch}, so no chunk of {epic} has merged into one: check the epic's key, and whether the branch's pull request merged already")
level = held if isinstance(held, Failure) else epic_branch.levelled(branch, f"origin/{default}", run=git)
head = level if isinstance(level, Failure) else answers(run, ["rev-parse", f"origin/{branch}"])
number = head if isinstance(head, Failure) else open_pull(forge, branch, head[0], run)
if isinstance(number, Failure):
@@ -518,6 +530,9 @@ def merge_turn(pull_request: Merging, finishes: typing.Sequence[list[str]], conf
asked = unanswered(pull_request.number, run) if pull_request.waits else None
if asked is not None:
return asked
# A person may have changed the pull request's base since the turn began, as while its checks ran.
if moved := other_base(pull_request.forge, pull_request.number, pull_request.base, run):
return moved
if pull_request.forge == "gh":
done = run(["gh", "pr", "merge", pull_request.number, pull_request.method, "--match-head-commit", str(head)])
else: