PostReview: pass CommitID explicitly via ReviewRequest #107
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?
Context
In
github/reviews.go,PostReviewsources theCommitIDfor the review payload from the first inline comment that has one. Ifreq.Commentsis empty (comment-only review with no inline annotations),payload.CommitIDis empty and GitHub defaults to HEAD.Problem
This implicit behavior works but is fragile:
Proposed Fix
Add a
CommitID stringfield tovcs.ReviewRequestand pass it explicitly from the caller (which haspr.Head.SHA). The GitHub adapter should use it as the primary source, falling back to comment-derived CommitID only if the field is empty.References
Plan: PostReview — pass CommitID explicitly
Problem
gitea.Client.PostReview()does not include acommit_idfield in the review payload. The review is not explicitly anchored to the evaluated commit SHA. If the PR head advances between analysis and posting, the review may be associated with the wrong commit. The Gitea API supportscommit_idinCreatePullReviewOptions— we just don't pass it.Constraints
""(omitempty drops it from JSON)origin/mainusesgitea.Clientdirectly (novcspackage yet)Proposed Approach
gitea/client.go— AddcommitID stringparameter toPostReviewCommitID string \json:"commit_id,omitempty"``commitIDas a new parameter (afterbody, beforecomments)payload.CommitID = commitIDcmd/review-bot/main.go— Passpr.Head.ShatoPostReviewgiteaClient.PostReview(ctx, owner, repoName, prNumber, event, reviewBody, inlineComments)giteaClient.PostReview(ctx, owner, repoName, prNumber, event, reviewBody, evaluatedSHA, inlineComments)evaluatedSHAis already computed frompr.Head.Shaat line ~382Update all test callers — add
""or appropriate SHA to existingPostReviewcalls in:gitea/client_test.gogitea/post_review_comments_test.gocmd/review-bot/integration_test.goVerify commit_id appears in the wire payload — add assertion in existing happy-path test
Error Cases
omitemptydrops it from JSON, Gitea defaults to HEAD (backward-compatible)Edge Cases
evaluatedSHAvscurrentSHA; if HEAD moved, we skip posting entirely. So by the time we reachPostReview,evaluatedSHAis still current.pr.Head.Shacould theoretically be empty (API quirk) —omitemptyhandles this gracefullyTesting Strategy
""commitID (backward compat)TestPostReviewhappy path to verifycommit_idappears in the serialized payloadOpen Questions
commitIDbetweenbodyandcommentsfeels natural (matches JSON field order). Alternative: aftercomments. Going with before-comments since it's a top-level review property, not comment-level.Completion Checklist
PostReviewsignature includescommitID stringcommit_idappears in JSON payload when non-emptycommit_idis omitted from JSON when empty (omitempty)evaluatedSHA(which equalspr.Head.Sha)commit_idin request bodygo build ./...cleango test ./...green