PR #112: gitea.Adapter.PostReview bypasses commitID — abstraction layer drops commit anchor #114
Reference in New Issue
Block a user
Delete Branch "%!s()"
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?
What was missed
PR #112 added a
commitID stringparameter togitea.Client.PostReviewand updatedcmd/review-bot/main.goto passevaluatedSHAdirectly to the client. However,gitea.Adapter.PostReview(thevcs.Clientimplementation) was not updated — it still callsa.client.PostReviewwith the old 7-argument signature, omitting the newcommitIDparameter. Since the review-bot is designed to operate through thevcs.Clientabstraction, the commit anchoring added by this PR is silently dropped whenever a caller uses the adapter interface.In
gitea/adapter.go, line 181:Should be:
But
vcs.ReviewRequesthas noCommitIDfield (see related issue), so the adapter has no way to thread it through without theReviewRequestfix.Source
gitea/adapter.goline 181What needs to happen
CommitID stringfield tovcs.ReviewRequest(see related issue)gitea.Adapter.PostReviewto passreq.CommitIDtoa.client.PostReviewgithub.Client.PostReviewto usereq.CommitIDas the primary commit anchor, falling back to comment-derived CommitID if empty (as originally specified in issue #107)gitea.Client.PostReviewdirectly should migrate to the adapterReferences
Plan: Thread CommitID through the VCS abstraction layer
Problem
PR #112 added
commitIDsupport togitea.Client.PostReviewat the transport level but never connected it to thevcs.Clientabstraction. Thevcs.ReviewRequeststruct has noCommitIDfield, sogitea.Adapter.PostReviewcannot thread a commit anchor through to the underlying Gitea API. Callers using thevcs.Clientinterface (the intended path) silently lose commit anchoring.The GitHub client extracts CommitID from individual
ReviewComment.CommitIDfields, but there's no top-level request-scoped CommitID — meaning body-only reviews (no inline comments) can't be anchored either.Constraints
vcs.Clientinterface contract for the GitHub adaptergitea.Client.PostReviewcurrently takes positional parameters — addingcommitIDas a new positional param changes the signature for all callerscommit_idas a top-level field in the CreatePullReview request bodycommit_idas a top-level field in the review creation payloadcmd/review-bot/main.go(usesvcs.Clientinterface) andgitea/adapter.gomust work correctly after the changeProposed Approach
1. Add
CommitIDfield tovcs.ReviewRequestThis is the canonical way to pass a commit anchor through the abstraction layer.
2. Update
gitea.Client.PostReviewto accept and sendcommitIDAdd
commitID stringparameter to the function signature. Includecommit_idin the JSON payload sent to the Gitea API:Payload struct gains:
CommitID string \x60json:"commit_id,omitempty"\x603. Update
gitea.Adapter.PostReviewto passreq.CommitID4. Update
github.Client.PostReviewto preferreq.CommitIDThe GitHub client should use
req.CommitIDas the primary commit anchor. If empty, fall back to extracting from the first comment'sCommitID(existing behavior). This matches the issue's specification.5. Update
cmd/review-bot/main.goto setReviewRequest.CommitID6. Update tests
gitea/adapter_test.go: Verify thatcommit_idappears in the API payload whenReviewRequest.CommitIDis setgitea/client_test.go: Verify the new parameter is serialized correctlygithub/review_test.go: Verifyreq.CommitIDtakes priority over comment-level CommitIDError Cases
omitempty— API falls back to default behavior (Gitea pins to PR head)req.CommitIDtakes priority. Ifreq.CommitIDis empty and comments disagree, existingErrConflictingCommitIDslogic applies (ingithub/review.go)Edge Cases
req.CommitIDdiffers fromReviewComment.CommitID— req-level wins (it's the intended anchor)CommitIDcontinues to work (zero-value string → omitempty → not sent)Testing Strategy
gitea.Client.PostReviewverifyingcommit_idin payloadgitea.Adapter.PostReviewverifying end-to-end threadinggithub.Client.PostReviewverifying req-level prioritycmd/review-bot/main.goflow worksOpen Questions
github/review.gofile has duplicate type declarations withgithub/reviews.go(both definereviewResponse,dismissReviewRequest). This appears to be an existing issue — I will NOT attempt to fix it in this PR as it's out of scope. However, it may cause compilation errors that I'll need to investigate.ReviewComment.CommitIDbe deprecated now that we have request-levelCommitID? I think no — per-comment CommitID is still useful for the GitHub adapter's fallback behavior and for mixed-commit scenarios. But the adapter comment ingitea/adapter.go(line 170-172) that says "intentionally not forwarded" should be updated to reference the request-level field.Completion Checklist
vcs.ReviewRequesthasCommitID stringfield with correct JSON taggitea.Client.PostReviewincludescommit_idin API payload when non-emptygitea.Adapter.PostReviewpassesreq.CommitIDto underlying clientgithub.Client.PostReviewusesreq.CommitIDas primary, comments as fallbackcmd/review-bot/main.gosetsCommitID: pr.Head.SHAon the ReviewRequest