Add agentpr pr edit subcommand #15

Merged
benvin merged 3 commits from benvin/agentpr-pr-edit into main 2026-09-19 13:48:44 +10:00
Member

agentpr could open a PR and comment on one, but not correct a PR body or title afterwards, so there was no agent-identity path to fix a PR once opened.

  • add pr edit --repo --pr with optional --title/--body, requiring at least one
  • add GiteaClient.EditPR calling PATCH /repos/{owner}/{repo}/pulls/{index}
  • send only the flags actually given, so an omitted field is left unchanged
  • document pr edit in README and AGENTS
agentpr could open a PR and comment on one, but not correct a PR body or title afterwards, so there was no agent-identity path to fix a PR once opened. - add `pr edit --repo --pr` with optional `--title`/`--body`, requiring at least one - add `GiteaClient.EditPR` calling `PATCH /repos/{owner}/{repo}/pulls/{index}` - send only the flags actually given, so an omitted field is left unchanged - document `pr edit` in README and AGENTS
unkin-agent added 1 commit 2026-09-19 12:32:17 +10:00
Add agentpr pr edit subcommand
ci/woodpecker/pr/pre-commit Pipeline was successful
ci/woodpecker/pr/build Pipeline was successful
ci/woodpecker/pr/test Pipeline was successful
7bc4082cb0
Update a PR's title and/or body as the agent user, sending only the
fields supplied.
Author
Member

Findings:

  • internal/agent/gitea.go:219 — comment says a pointer to "" clears the title. Gitea's EditPullRequest guards the title with len(form.Title) > 0 (only Body is a *string there), so {"title":""} is silently dropped, not applied → fix the comment: Title can be set but never cleared; only Body can be blanked.
  • cmd/agentpr/main.go:165--title "" passes the Changed("title") gate, is sent, is ignored by Gitea, and the command still prints #N <url> as if it succeeded → reject an empty --title with an error, the way pr comment rejects an empty --body.
  • nit: internal/agent/client_test.go:155TestEditPRAPIError mocks a 422 title cannot be empty, which this endpoint never returns; it encodes a wrong belief about the API → use a failure Gitea actually produces (404/403) for the error-surfacing assertion.
Findings: - `internal/agent/gitea.go:219` — comment says a pointer to `""` clears the title. Gitea's `EditPullRequest` guards the title with `len(form.Title) > 0` (only `Body` is a `*string` there), so `{"title":""}` is silently dropped, not applied → fix the comment: `Title` can be set but never cleared; only `Body` can be blanked. - `cmd/agentpr/main.go:165` — `--title ""` passes the `Changed("title")` gate, is sent, is ignored by Gitea, and the command still prints `#N <url>` as if it succeeded → reject an empty `--title` with an error, the way `pr comment` rejects an empty `--body`. - nit: `internal/agent/client_test.go:155` — `TestEditPRAPIError` mocks a 422 `title cannot be empty`, which this endpoint never returns; it encodes a wrong belief about the API → use a failure Gitea actually produces (404/403) for the error-surfacing assertion.
unkin-agent added 1 commit 2026-09-19 12:38:18 +10:00
Reject an empty pr edit title Gitea would ignore
ci/woodpecker/pr/build Pipeline was successful
ci/woodpecker/pr/test Pipeline was successful
ci/woodpecker/pr/pre-commit Pipeline failed
78d83b7a61
Author
Member

Findings:

  • nit: internal/agent/client_test.go:159 — the mocked 404 body {"message":"pull request does not exist"} is not a response Gitea produces; a real 404 from this endpoint is {"message":"not found","url":"...","errors":null} (checked against git.unkin.net, Gitea 1.26.2) → mock that body and assert on it, so the test pins the real response shape rather than an invented message.
Findings: - nit: `internal/agent/client_test.go:159` — the mocked 404 body `{"message":"pull request does not exist"}` is not a response Gitea produces; a real 404 from this endpoint is `{"message":"not found","url":"...","errors":null}` (checked against git.unkin.net, Gitea 1.26.2) → mock that body and assert on it, so the test pins the real response shape rather than an invented message.
unkin-agent added 1 commit 2026-09-19 12:44:05 +10:00
Mock the 404 body Gitea really returns
ci/woodpecker/pr/build Pipeline was successful
ci/woodpecker/pr/test Pipeline was successful
ci/woodpecker/pr/pre-commit Pipeline was successful
3f990c841d
benvin merged commit 72adebbf8b into main 2026-09-19 13:48:44 +10:00
benvin deleted branch benvin/agentpr-pr-edit 2026-09-19 13:48:45 +10:00
Sign in to join this conversation.