feat: add pr merge and update-branch (task 0012) #12

Merged
alexion merged 1 commits from task-0012-pr-merge-and-update-branch into main 2026-07-13 20:24:02 -04:00
Owner

Task: .claude/tasks/0012-pr-merge-and-update-branch.md

Summary

Adds two pr subcommands:

  • pr merge <n> — all six Gitea methods via --method, the three common-method shorthands (--merge/--squash/--rebase), plus --auto, --delete-branch, --subject, --body/--body-file, and --merge-commit-id. Conflicting/duplicate method flags and the manually-merged--merge-commit-id pairing are rejected as VALIDATION_ERROR before any API call. An already-merged PR short-circuits (no merge call) to a pull_request entity block carrying merged_by/merged_at; a successful merge outputs merged: { number, status: "ok", method }. Merge-blocked 405/409 responses surface as VALIDATION_ERROR with the server's message plus remediation help lines.
  • pr update-branch <n> — merges the base branch into the head via the update endpoint with --style <merge|rebase> (default merge), outputting updated: { number, status: "ok" }.

Fixture-server tests cover each method, the shorthands, the local validations, the idempotent no-op, and the 405/409 mappings (24 new tests; full suite 301 green).

Deviations

  • No method given → Do: merge sent, method: default reported. Gitea's merge endpoint requires a concrete Do; the reported field describes the caller's (absent) choice, matching the gh-axi interface shape. Consequence: a squash-only repo will reject a bare pr merge with a 405 (surfaced with the server message). Respecting the repo's default_merge_style is a possible follow-up.
  • One combined conflict message covers both the multiple-shorthand and --method+shorthand cases, rather than the interface doc's two separate strings.
  • The 405/409 remediation suggests pr checkout <n>, which lands in task 0014 and does not exist yet.

Review

Risk

Overall: Medium

  • Blast radius — Low: additive, confined to src/commands/pr.ts plus two new test files; no existing callers touched.
  • Reversibility — Low: pure feature addition; clean removal, no migrations/deletions/schema changes.
  • Test coverage — Low: method resolution, shorthands, validations, idempotency, 405/409, and update styles all covered.
  • Sensitive domain — Medium: pr merge/update-branch are irreversible remote mutations; a wrong method or premature merge has real consequences.
  • Size & complexity — Medium: ~170 new lines with branching validation logic, but linear and readable.
  • Runtime criticality — Medium: dev tooling, but the merge path is the highest-stakes operation the tool exposes; mitigated by the pre-flight idempotency GET and pre-request validation.

Unaddressed findings

Standards and Spec each surfaced only judgement calls; the one actionable Standards item (double classifyHttpError call in the 405/409 branch) was fixed in this diff. Remaining, left as-is:

  • Standards — method ?? "default" mixes a magic string into the method: enum field (judgement call). Deliberate and documented: it matches the gh-axi interface's reported shape and never reaches the wire as a Do value.
  • Standards — MERGE_SHORTHANDS as a record+loop for three fixed entries (judgement call). Kept: the map reads clearly as data and localizes the shorthand→method mapping.
  • Spec — combined conflict message differs from the interface doc's three separate strings (doc-consistency nit, not a task-spec violation). The task's criteria only require VALIDATION_ERROR before any API call, which holds; the combined message reads at least as clearly.
Task: `.claude/tasks/0012-pr-merge-and-update-branch.md` ## Summary Adds two `pr` subcommands: - **`pr merge <n>`** — all six Gitea methods via `--method`, the three common-method shorthands (`--merge`/`--squash`/`--rebase`), plus `--auto`, `--delete-branch`, `--subject`, `--body`/`--body-file`, and `--merge-commit-id`. Conflicting/duplicate method flags and the `manually-merged` ↔ `--merge-commit-id` pairing are rejected as `VALIDATION_ERROR` before any API call. An already-merged PR short-circuits (no merge call) to a `pull_request` entity block carrying `merged_by`/`merged_at`; a successful merge outputs `merged: { number, status: "ok", method }`. Merge-blocked 405/409 responses surface as `VALIDATION_ERROR` with the server's message plus remediation help lines. - **`pr update-branch <n>`** — merges the base branch into the head via the update endpoint with `--style <merge|rebase>` (default merge), outputting `updated: { number, status: "ok" }`. Fixture-server tests cover each method, the shorthands, the local validations, the idempotent no-op, and the 405/409 mappings (24 new tests; full suite 301 green). ### Deviations - **No method given → `Do: merge` sent, `method: default` reported.** Gitea's merge endpoint requires a concrete `Do`; the reported field describes the caller's (absent) choice, matching the gh-axi interface shape. Consequence: a squash-only repo will reject a bare `pr merge` with a 405 (surfaced with the server message). Respecting the repo's `default_merge_style` is a possible follow-up. - **One combined conflict message** covers both the multiple-shorthand and `--method`+shorthand cases, rather than the interface doc's two separate strings. - The 405/409 remediation suggests `pr checkout <n>`, which lands in task 0014 and does not exist yet. ## Review ### Risk **Overall: Medium** - Blast radius — Low: additive, confined to `src/commands/pr.ts` plus two new test files; no existing callers touched. - Reversibility — Low: pure feature addition; clean removal, no migrations/deletions/schema changes. - Test coverage — Low: method resolution, shorthands, validations, idempotency, 405/409, and update styles all covered. - Sensitive domain — Medium: `pr merge`/`update-branch` are irreversible remote mutations; a wrong method or premature merge has real consequences. - Size & complexity — Medium: ~170 new lines with branching validation logic, but linear and readable. - Runtime criticality — Medium: dev tooling, but the merge path is the highest-stakes operation the tool exposes; mitigated by the pre-flight idempotency GET and pre-request validation. ### Unaddressed findings Standards and Spec each surfaced only judgement calls; the one actionable Standards item (double `classifyHttpError` call in the 405/409 branch) was fixed in this diff. Remaining, left as-is: - **Standards — `method ?? "default"` mixes a magic string into the `method:` enum field** (judgement call). Deliberate and documented: it matches the gh-axi interface's reported shape and never reaches the wire as a `Do` value. - **Standards — `MERGE_SHORTHANDS` as a record+loop for three fixed entries** (judgement call). Kept: the map reads clearly as data and localizes the shorthand→method mapping. - **Spec — combined conflict message differs from the interface doc's three separate strings** (doc-consistency nit, not a task-spec violation). The task's criteria only require `VALIDATION_ERROR` before any API call, which holds; the combined message reads at least as clearly.
alexion added 1 commit 2026-07-13 20:23:07 -04:00
feat: add pr merge and update-branch (task 0012)
All checks were successful
CI / test (pull_request) Successful in 41s
CI / test (push) Successful in 40s
40859b9e6b
Add `pr merge` with all six Gitea methods, the three common-method
shorthands, `--auto`, `--delete-branch`, `--subject`, `--body`/`--body-file`,
and `--merge-commit-id` (required with and only valid for
`--method manually-merged`). Conflicting method flags and the
manually-merged/commit-id pairing are rejected as VALIDATION_ERROR before
any API call. An already-merged PR short-circuits to a `pull_request` entity
block with `merged_by`/`merged_at`; merge-blocked 405/409 responses surface
as VALIDATION_ERROR with update-branch/checkout remediation.

Add `pr update-branch` merging the base into the head via the update
endpoint with `--style <merge|rebase>` (default merge).
alexion merged commit 40859b9e6b into main 2026-07-13 20:24:02 -04:00
alexion deleted branch task-0012-pr-merge-and-update-branch 2026-07-13 20:24:02 -04:00
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: alexion/gitea-axi#12