Let chunk-pr ready take the pull request's final title

This commit is contained in:
2026-11-12 08:41:20 +01:00
parent e86a0cbc0c
commit 0d32cab386
+22 -11
View File
@@ -1,7 +1,7 @@
"""Open the chunk's pull request as a draft, mark it ready, or merge it, with gh where origin is on GitHub and tea elsewhere; once it has merged, remove the chunk's worktree and branch. """Open the chunk's pull request as a draft, mark it ready, or merge it, with gh where origin is on GitHub and tea elsewhere; once it has merged, remove the chunk's worktree and branch.
usage: chunk-pr open <title> [<body>] usage: chunk-pr open <title> [<body>]
chunk-pr ready chunk-pr ready [<title>]
chunk-pr merge --gate-passed chunk-pr merge --gate-passed
chunk-pr clean chunk-pr clean
@@ -13,7 +13,8 @@ open pushes the branch, setting its upstream, and opens a draft pull request
says, and <body> is the pull request's summary. Where the branch's pull request is open says, and <body> is the pull request's summary. Where the branch's pull request is open
already, it opens no second one. On origin's default branch it refuses, pushing nothing. already, it opens no second one. On origin's default branch it refuses, pushing nothing.
ready marks the pull request ready for review. On Gitea a draft is a pull request whose title ready marks the pull request ready for review. On Gitea a draft is a pull request whose title
starts with `WIP: `, so there it drops that prefix. starts with `WIP: `, so there it drops that prefix. Given <title>, one line, it sets that
as the pull request's title first; where that fails, the pull request stays a draft.
merge merges the pull request, and only while its head is still the commit checked out, so a merge merges the pull request, and only while its head is still the commit checked out, so a
push after the gate is never merged. It takes the first method the repository allows of: push after the gate is never merged. It takes the first method the repository allows of:
a merge commit, fast-forward only, a rebase followed by a merge commit, a rebase, a squash. a merge commit, fast-forward only, a rebase followed by a merge commit, a rebase, a squash.
@@ -44,7 +45,7 @@ from chunk_preflight.choices import forge_of
from deploy_release.forge import gitea, merged_pull, open_pull, Run, runner from deploy_release.forge import gitea, merged_pull, open_pull, Run, runner
BIN = pathlib.Path(__file__).resolve().parents[1] BIN = pathlib.Path(__file__).resolve().parents[1]
USAGE = "usage: chunk-pr open <title> [<body>] | chunk-pr ready | chunk-pr merge --gate-passed | chunk-pr clean" USAGE = "usage: chunk-pr open <title> [<body>] | chunk-pr ready [<title>] | chunk-pr merge --gate-passed | chunk-pr clean"
# Each forge's merge methods in the order merge prefers them, as the repository setting that allows the method and the method's name in the forge's merge call. A merge commit and a fast-forward keep the branch's commits as they are; a rebase or a squash rewrites them. # Each forge's merge methods in the order merge prefers them, as the repository setting that allows the method and the method's name in the forge's merge call. A merge commit and a fast-forward keep the branch's commits as they are; a rebase or a squash rewrites them.
METHODS: dict[Forge, tuple[tuple[str, str], ...]] = { METHODS: dict[Forge, tuple[tuple[str, str], ...]] = {
@@ -69,11 +70,9 @@ def step(argv: list[str], run: Run) -> str | Failure:
"""Run the step argv names: the line to print, or a Failure. A malformed argv runs nothing.""" """Run the step argv names: the line to print, or a Failure. A malformed argv runs nothing."""
match argv: match argv:
case ["open", title, *body] if len(body) <= 1: case ["open", title, *body] if len(body) <= 1:
if not title.strip() or "\n" in title: return Failure("give a title of one line") if not one_line(title) else opened(title, body[0] if body else "", run)
return Failure("give a title of one line") case ["ready", *title] if len(title) <= 1:
return opened(title, body[0] if body else "", run) return Failure("give a title of one line") if title and not one_line(title[0]) else marked_ready(run, title[0] if title else None)
case ["ready"]:
return marked_ready(run)
case ["merge", "--gate-passed"]: case ["merge", "--gate-passed"]:
return merged(run) return merged(run)
case ["merge"]: case ["merge"]:
@@ -83,6 +82,10 @@ def step(argv: list[str], run: Run) -> str | Failure:
return Failure(USAGE) return Failure(USAGE)
def one_line(title: str) -> bool:
return bool(title.strip()) and "\n" not in title
def answers(run: Run, *commands: list[str]) -> list[str] | Failure: def answers(run: Run, *commands: list[str]) -> list[str] | Failure:
"""What each git command printed, stripped, or the first Failure.""" """What each git command printed, stripped, or the first Failure."""
answered = [run(["git", *args]) for args in commands] answered = [run(["git", *args]) for args in commands]
@@ -147,13 +150,21 @@ def opened(title: str, body: str, run: Run) -> str | Failure:
return number if isinstance(number, Failure) else f"Opened draft pull request #{number}." return number if isinstance(number, Failure) else f"Opened draft pull request #{number}."
def marked_ready(run: Run) -> str | Failure: def marked_ready(run: Run, title: str | None) -> str | Failure:
found = pull(run) found = pull(run)
if isinstance(found, Failure): if isinstance(found, Failure):
return found return found
forge, number, _ = found forge, number, _ = found
ready = run(["gh", "pr", "ready", number] if forge == "gh" else ["tea", "pulls", "edit", number, "--ready"]) retitle = ["--title", title] if title is not None else []
return ready if isinstance(ready, Failure) else f"Marked pull request #{number} ready." if forge == "gh":
# gh marks a pull request ready only with `gh pr ready`, which takes no title.
titled = run(["gh", "pr", "edit", number, *retitle]) if retitle else ""
ready = titled if isinstance(titled, Failure) else run(["gh", "pr", "ready", number])
else:
ready = run(["tea", "pulls", "edit", number, *retitle, "--ready"])
if isinstance(ready, Failure):
return ready
return f"Marked pull request #{number} ready, titled “{title}”." if title is not None else f"Marked pull request #{number} ready."
def merged(run: Run) -> str | Failure: def merged(run: Run) -> str | Failure: