Add edit/delete and idempotent upsert to pr comment #145

Merged
stephen merged 2 commits from feat/131-pr-comment-edit into main 2026-06-11 02:07:38 +00:00
Owner

Closes the write-once gap in fj pr comment from rasterstate/fj#131: the
command carried only number + body and could only post, while the issue
side already had edit/delete. Since a PR is an issue in Forgejo, comment
mutation shares the issues/comments/{id} path, so this is purely a missing
CLI verb plus the gh-parity upsert flag.

What changed

  • fj pr comment edit <id> and fj pr comment delete <id>, reusing the
    existing api::issue::edit_comment / delete_comment. Delete keeps the
    type-the-id confirmation (skippable with -y).
  • --edit-last retargets the add form at your most recent comment on the PR
    (selected by the monotonic comment id, not list order), erroring clearly
    when you have none.
  • --create-if-none posts a fresh comment when you have none yet;
    --create-or-edit is the shorthand for --edit-last --create-if-none.
    Together they collapse the "build running → build green" maintained-status
    comment dance into one idempotent call, no hand-managed comment id.
  • --body, --body - (stdin), and the $EDITOR fallback all compose with
    the new flags. The bare fj pr comment <number> add form stays the default.
  • Comment handling moves out of pr.rs into a new cli::pr_comment module.

Scoped to the pr comment command only: the issue side and the error layer are
untouched.

Tests

  • pr_comment_edit_last_selects_callers_newest_comment: drives the full
    fetch-user → list → PATCH sequence and asserts the selection lands on the
    caller's newest comment, not a later one by someone else.
  • pr_comment_create_if_none_posts_when_caller_has_no_comment: no own comment
    → selection is None → POST a new one.
  • pr_comment_edit_and_delete_missing_id_error: a missing id surfaces the API
    404 for both edit and delete.
  • Unit tests for the last_own_comment selection helper (newest-wins, absent
    login, empty list).

Fixes rasterstate/fj#131

Closes the write-once gap in `fj pr comment` from rasterstate/fj#131: the command carried only `number` + `body` and could only post, while the issue side already had edit/delete. Since a PR is an issue in Forgejo, comment mutation shares the `issues/comments/{id}` path, so this is purely a missing CLI verb plus the gh-parity upsert flag. ## What changed - `fj pr comment edit <id>` and `fj pr comment delete <id>`, reusing the existing `api::issue::edit_comment` / `delete_comment`. Delete keeps the type-the-id confirmation (skippable with `-y`). - `--edit-last` retargets the add form at your most recent comment on the PR (selected by the monotonic comment id, not list order), erroring clearly when you have none. - `--create-if-none` posts a fresh comment when you have none yet; `--create-or-edit` is the shorthand for `--edit-last --create-if-none`. Together they collapse the "build running → build green" maintained-status comment dance into one idempotent call, no hand-managed comment id. - `--body`, `--body -` (stdin), and the `$EDITOR` fallback all compose with the new flags. The bare `fj pr comment <number>` add form stays the default. - Comment handling moves out of `pr.rs` into a new `cli::pr_comment` module. Scoped to the pr comment command only: the issue side and the error layer are untouched. ## Tests - `pr_comment_edit_last_selects_callers_newest_comment`: drives the full fetch-user → list → PATCH sequence and asserts the selection lands on the caller's newest comment, not a later one by someone else. - `pr_comment_create_if_none_posts_when_caller_has_no_comment`: no own comment → selection is `None` → POST a new one. - `pr_comment_edit_and_delete_missing_id_error`: a missing id surfaces the API 404 for both edit and delete. - Unit tests for the `last_own_comment` selection helper (newest-wins, absent login, empty list). Fixes rasterstate/fj#131
Add edit/delete and idempotent upsert to pr comment
Some checks failed
ci / check (pull_request) Successful in 9m50s
ci / coverage (pull_request) Failing after 22s
ci / live-e2e (pull_request) Has been cancelled
fc6fef4cc5
`fj pr comment` was write-once: CommentArgs carried only number + body and
the handler only posted, with no edit/delete verb unlike the issue side.

- `fj pr comment edit <id>` and `fj pr comment delete <id>`, reusing the
  existing `api::issue::edit_comment` / `delete_comment` (a PR is an issue
  in Forgejo, so comment mutation shares the issues/comments path).
- `--edit-last` retargets the post at your most recent comment on the PR;
  `--create-if-none` (and the `--create-or-edit` shorthand) make it create
  one when you have none, collapsing the maintained-status-comment
  read-modify-write into a single idempotent call.
- The bare `fj pr comment <number>` add form is preserved as the default
  when no subcommand is given.

Comment-mutation logic moves to a new cli::pr_comment module.
ci: retrigger (coverage job hit a transient checkout failure)
All checks were successful
ci / check (pull_request) Successful in 9m50s
ci / coverage (pull_request) Successful in 11m1s
ci / live-e2e (pull_request) Successful in 1m45s
12d311f394
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
rasterstate/fj!145
No description provided.