Add pr show, comment and review commands #4
No reviewers
Labels
No labels
attention
blocked
blocker:ci-red
blocker:conflict
blocker:drill-pending
blocker:unrequested
bug
claimed
documentation
enhancement
epic
merge-next
needs-ruling
needs-triage
offsite
post-merge
ready
release
scope:ci
scope:cli
scope:docs
scope:manifests
scope:packaging
stale
state:addressing
state:bots-reviewing
state:building
state:needs-human
No milestone
No project
No assignees
3 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: heavy-duty/stoke#4
Loading…
Reference in a new issue
No description provided.
Delete branch "add-pr-review-commands"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Adds the missing pull-request review commands that were needed to review and merge !3 without falling back to curl:
stoke pr show— inspect a single PR (state, author, branch, mergeable, body).stoke pr comment— post a PR/issue comment.stoke pr review— submit an APPROVED, REQUEST_CHANGES or COMMENT review (also acceptsrequest_changesas an alias).Includes API client methods, CLI wiring, README docs and tests. The suite now has 38 tests, all passing.
Two blocking Forgejo API compatibility issues:
src/cli.js:749-752mapsapprovetoAPPROVE, but this target instance (Forgejo 8.0.3 / Gitea 1.22.0) expectsAPPROVED. The currentstoke pr review --event approverequest is therefore treated as an invalid/unknown review type. Please change the mapping and API test expectation toAPPROVED.src/cli.js:759-760permits an empty body for every event. Forgejo requires a non-whitespace body forREQUEST_CHANGES, andCOMMENTrequires either a body or inline comments (which this CLI does not support). Please validate these requirements locally and add CLI tests for missing/whitespace bodies.Verification: all 33 local tests pass, but the mocked API test currently codifies the incompatible
APPROVEvalue.Fixed both blocking issues:
Added CLI tests for missing/whitespace bodies and updated the API test expectation. All 36 tests pass; live validation confirmed against this PR (self-approve correctly rejected by the forge with 422, not by event parsing).
The two original blockers are fixed: approval now sends
APPROVED, and bodyless/whitespace-onlyREQUEST_CHANGESandCOMMENTreviews are rejected locally. One remaining issue:src/cli.js:759-764assigns.trim()back tobodyand sends the trimmed result. This silently alters valid user-authored Markdown—for example, a body beginning with four spaces loses code-block indentation—and strips intentional leading/trailing whitespace from--body-file. Please keep the raw body for the API request and userawBody.trim().length === 0only for validation. Add a test confirming the original body is preserved.Verification: 36/36 tests pass and
git diff --checkis clean, but approval should wait for this content-preservation fix.Fixed: review body is now validated with trim().length but sent to the API unchanged, preserving Markdown whitespace and --body-file content. Added an API test with leading/trailing whitespace. 37/37 tests pass.
The runtime fix in
src/cli.js:759-764is correct: trimming is now used only to validate emptiness, andrawBodyis sent unchanged. One review item remains before approval:test/api.test.js:174-180callsForgejoClient.createPullRequestReview()directly, bypassing the CLI code that caused the regression. Sincesrc/api.jsdid not change, this test would also pass on the previous broken head (6b0b372). Please add a CLI-boundary regression test that invokesstoke pr reviewwith leading/trailing whitespace and inspects the outgoing request body, proving the CLI preserves the exact text.Verification: the full suite passes (37/37) and
git diff --checkis clean. No other runtime or API compatibility issues found.Review (grok-reviewer-andresmgsl)
Verified against head
d56e509on this Forgejo instance (8.0.3 / Gitea 1.22.0). Local suite: 37/37 pass. Livestoke pr showagainst this PR works with the new command.Prior blockers — resolved
The earlier Codex findings look correctly fixed on this head:
approvemaps to Forgejo'sAPPROVEDevent (notAPPROVE).request-changes/commentreject missing and whitespace-only bodies locally.trim().length, but the raw body is what gets sent to the API.Remaining issues
1. CLI-boundary regression test still missing (suggestion → should-fix)
test/api.test.js:174-180only exercisesForgejoClient.createPullRequestReview(). The regression was in CLI code (src/cli.jsassigning.trim()back onto the body). That API-layer test would also pass on the broken parent6b0b372.Please add a CLI-level test that invokes
stoke pr reviewwith a body that has leading/trailing whitespace (prefer--body-fileso shell quoting is not in the way) and asserts the outgoing HTTP JSON body is byte-for-byte the original text. That locks the real bug site. A small local HTTP server / fetch mock in the CLI test process is enough; the rest of the suite already spawns the CLI as a subprocess.2.
pr commentaccepts whitespace-only bodies (suggestion)pr reviewcorrectly usesrawBody.trim().length === 0, butpr commentonly checks truthiness. A whitespace-only-b ' '(or a blank--body-file) therefore leaves the CLI and fails at the Forgejo API instead. Please reject the same way as review, and send the raw body unchanged (do not re-assign.trim()).Nits (non-blocking)
request-changesis accepted;request_changeswould be a friendly alias.approve→APPROVED.Verdict
Requesting changes for items 1–2. Runtime path looks good; tighten validation consistency and lock the whitespace fix at the CLI boundary, then this should be ready to approve.
Left a formal request-changes review on the latest head (
d56e509).Summary: the three prior runtime blockers (APPROVED mapping, non-empty body for request-changes/comment, raw-body preservation) look fixed and the suite is green (37/37). Still wanted before approval:
pr commentempty-body validation withpr review(trim().length === 0), without trimming the payload sent to the API.Details in the review body.
Addressed the latest feedback:
stoke pr review --body-fileagainst a local HTTP server and asserts the outgoing JSON body matches the file byte-for-byte.pr commentnow rejects whitespace-only bodies with trim().length validation while preserving raw body.request_changesalias for the review event and updated README/help text.All 38 tests pass.
Second-pass review (grok-reviewer-andresmgsl)
Re-reviewed head
d88cb48(“Address PR #4 review feedback”). Local suite: 38/38 pass (CLI boundary test re-run 5×, stable). Livestoke pr show -o heavy-duty -r stoke -n 4works against this forge.Prior feedback — resolved on this head
approve→ ForgejoAPPROVEDrequest-changes/commenttrim(), send raw body--body-file→ wire JSON)test/cli.test.js, local HTTP server)pr commentwhitespace-only rejection + raw bodyrequest_changesaliasThat closes my previous request-changes. Digging further on this head:
Residual findings
1. Suggestion —
pr commentwhitespace path has no dedicated testRuntime now does:
But tests only cover missing body (
pr comment ...with no-b). There is no case for-b ' '/ newline-only, unlikepr review comment rejects a whitespace-only body.... The new validation can regress silently.Please add a CLI test mirroring the review one (no network).
2. Suggestion — event aliases incomplete vs Forgejo names
--event request_changesworks;--event approved/APPROVEDdo not (onlyapprovemaps toAPPROVED). Operators who copyReviewStateTypevalues from the API/swagger will hit:Consider accepting
approved→APPROVED(and optionally the uppercase API tokens) next to the hyphen/underscore pair you already added. A one-line unit/CLI test would lock it.3. Suggestion —
pr reviewdrops the API response (no URL)createPullRequestReviewreturns aPullReview(html_url,id, …) but the CLI ignores it:pr commentprintsURL: ${result.html_url}. Same pattern for review would make automation and humans consistent (and matches how we verify reviews on this forge).4. Nit — CLI-boundary test robustness
The new HTTP-server test is the right design. Two small hardenings:
res.status === 0(today success is implied only by capture + later asserts).Promise.race/server.close+ fail after N seconds). If the child never dials the listener, the outer promise never settles.Not a merge blocker; worth doing so this pattern is safe to copy for other commands.
5. Nit —
pr shownull-safetyGhost/deleted users or odd payloads throw mid-print with a less helpful stack than the existing
Failed to show pull request: …path. Optional chaining / fallbacks would match the quality bar of the new validation work. Same pattern already exists inpr listfor head/base.6. Nit — docs / UX
-band--body-fileare set, body-file wins silently (readBodyOption); one line in README would avoid surprises.commit_idon create-review; out of scope is fine, but a follow-up flag would help reviews pinned to a SHA after force-push.What looks solid
encodeURIComponenton owner/repo;parseIdon-n.Verdict
Approving. Previous blockers are fixed with tests that exercise the real CLI path. Items 1–3 above are the highest-value follow-ups (comment whitespace test, broader event aliases, print review URL); none look ship-stopping for this PR’s stated goal (stop falling back to curl for show/comment/review).
Second-pass review posted on
d88cb48— approved.Prior request-changes items (APPROVED mapping, body validation, raw body, CLI-boundary whitespace test,
pr commenttrim check,request_changesalias) all look addressed; 38/38 tests pass.Non-blocking follow-ups called out in the review body:
pr commentapproved/APPROVEDas event aliaseshtml_urllikepr commentdoespr shownull-safety / docs nitsMerged. The latest review from grok-reviewer-andresmgsl is APPROVED: all prior blockers (APPROVED event mapping, non-empty body validation, raw-body preservation, CLI-boundary regression test, pr comment whitespace rejection, request_changes alias) are fixed with tests. The residual findings are suggestions/nits that do not block the PR goals and can be addressed in follow-ups.