Answer product-owner round 1: 0 🔴, 4 🟡 (0 misread); move through the open status, refuse open-epic without a branch, tell a conflict from git's other failures

This commit is contained in:
Lilleman
2026-11-20 20:15:33 +01:00
parent 9f367e90ca
commit ce2e9dc0e5
9 changed files with 143 additions and 21 deletions
+9 -5
View File
@@ -95,11 +95,11 @@ clean acts once the forge reports the branch's pull request merged at the com
still removes the worktree and the branch, and fails saying why.
open-epic runs in any checkout of the repository, once the epic's last chunk has merged. It
fetches origin and brings the working branch of the epic named level with origin's
default branch, by a merge commit pushed to origin, or makes the branch where origin has
none. Then it opens the pull request from 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
opens nothing and says how a person merges them. Where the pull request is open
already, it opens no second one. It fails where the config sets no `epic-branch`.
default branch, by a merge commit pushed to origin. Then it opens the pull request from
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.
It prints what it did, exit 0, or why it failed, exit 1.
"""
@@ -168,6 +168,7 @@ def step(argv: list[str], run: Run, config: Config, parks: bool = False) -> str
return synced(run, config)
case ["ready", *title] if len(title) <= 1 and not any(given.startswith("-") for given in title):
return Failure("give a title of one line") if title and not one_line(title[0]) else (misfit(title[0], run, config) if title else None) or readied(run, title[0] if title else None, config)
# Three readers, seated as those who run `chunk-pr`, picked the spellings `push`, 3-0, and `open-epic`, 2-1.
case ["push"]:
return pushed(run, config)
case ["open-epic", epic, title, *body] if len(body) <= 1 and not any(given.startswith("-") for given in (epic, title)):
@@ -401,6 +402,9 @@ 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])
# `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]))
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)
+7 -1
View File
@@ -1131,12 +1131,18 @@ class EpicBranch(unittest.TestCase):
def test_open_epic_leaves_a_conflict_with_the_default_branch_to_a_person_and_opens_nothing(self):
checkout = self.epic()
checkout.answers[("git", "rev-list", "--count", "origin/ABC-1..origin/main")] = "3\n"
checkout.answers[("git", "merge-tree", "--write-tree", "origin/ABC-1", "origin/main")] = Failure("git merge-tree: CONFLICT")
checkout.answers[("git", "merge-tree", "--write-tree", "origin/ABC-1", "origin/main")] = Failure("git merge-tree --write-tree: " + "a" * 40 + "\nCONFLICT (content): Merge conflict in a.txt")
done = step(["open-epic", "ABC-1", "Ship the epic"], checkout, checkout.config)
self.assertIsInstance(done, Failure)
self.assertIn("a person merges it", done.reason)
self.assertFalse(any(command[:3] == ["gh", "pr", "create"] for command in checkout.ran))
def test_open_epic_makes_no_branch_where_origin_has_none_for_the_epic(self):
checkout = self.epic()
checkout.answers[("git", "rev-parse", "--quiet", "--verify", "refs/remotes/origin/ABC-1")] = Failure("git rev-parse: no such ref")
self.assertEqual(step(["open-epic", "ABC-1", "Ship the epic"], checkout, checkout.config), Failure("origin has no branch ABC-1, so no chunk of ABC-1 has merged into one: check the epic's key, and whether the branch's pull request merged already"))
self.assertFalse(any(command[:2] in (["git", "push"], ["gh", "pr"]) for command in checkout.ran))
def test_open_epic_opens_no_second_pull_request(self):
checkout = self.epic()
checkout.answers[("gh", "pr", "list", "--head", "ABC-1", *GH_LIST[5:])] = "31\tabc123\tfalse\n"