address review feedback: wrap ErrCannotDeleteSubmittedReview, fix nits

- Wrap ErrCannotDeleteSubmittedReview with operation context via fmt.Errorf
  so callers get both sentinel identity and context (MINOR fix)
- Combine double iteration in PostReview into single loop (NIT)
- Remove extra trailing blank line in review_test.go (NIT)
- Clarify translateGitHubReviewState comment re: PENDING state (NIT)
- Update requestOptions.bodyFn comment to mention DELETE-with-body (NIT)
This commit is contained in:
claw
2026-05-13 00:54:21 -07:00
committed by Aaron Weiker
parent eba97321ad
commit 293296b50c
3 changed files with 7 additions and 11 deletions
+2 -1
View File
@@ -196,7 +196,8 @@ func (c *Client) SetRetryBackoff(d []time.Duration) error {
// requestOptions holds per-request configuration for doRequestCore. // requestOptions holds per-request configuration for doRequestCore.
type requestOptions struct { type requestOptions struct {
// bodyFn returns a fresh io.Reader for the request body on each attempt. // bodyFn returns a fresh io.Reader for the request body on each attempt.
// Must be non-nil for requests that carry a body (POST, PUT, PATCH). // Must be non-nil for any request that carries a body (POST, PUT, PATCH,
// or DELETE when a body is required by the API).
// Returning a fresh reader on each call allows retries to re-send the body. // Returning a fresh reader on each call allows retries to re-send the body.
bodyFn func() io.Reader bodyFn func() io.Reader
+5 -8
View File
@@ -59,7 +59,8 @@ func translateGitHubReviewState(state string) string {
return "COMMENT" return "COMMENT"
default: default:
// States like APPROVED, DISMISSED, and PENDING pass through unchanged // States like APPROVED, DISMISSED, and PENDING pass through unchanged
// as they already match the canonical vcs representation. // as they already match the canonical vcs representation. PENDING appears
// on draft reviews that have not yet been submitted via the GitHub UI or API.
return state return state
} }
} }
@@ -77,16 +78,12 @@ func (c *Client) PostReview(ctx context.Context, owner, repo string, number int,
Event: string(req.Event), Event: string(req.Event),
} }
// Populate CommitID from the first comment if available. // Populate CommitID from the first comment and build the payload in one pass.
// All comments in a single review share the same commit_id. // All comments in a single review share the same commit_id.
for _, comment := range req.Comments { for _, comment := range req.Comments {
if comment.CommitID != "" { if payload.CommitID == "" && comment.CommitID != "" {
payload.CommitID = comment.CommitID payload.CommitID = comment.CommitID
break
} }
}
for _, comment := range req.Comments {
payload.Comments = append(payload.Comments, reviewCommentEntry{ payload.Comments = append(payload.Comments, reviewCommentEntry{
Path: comment.Path, Path: comment.Path,
Position: comment.Position, Position: comment.Position,
@@ -159,7 +156,7 @@ func (c *Client) DeleteReview(ctx context.Context, owner, repo string, number in
if err != nil { if err != nil {
var apiErr *APIError var apiErr *APIError
if errors.As(err, &apiErr) && apiErr.StatusCode == 422 { if errors.As(err, &apiErr) && apiErr.StatusCode == 422 {
return ErrCannotDeleteSubmittedReview return fmt.Errorf("delete review: %w", ErrCannotDeleteSubmittedReview)
} }
return fmt.Errorf("delete review: %w", err) return fmt.Errorf("delete review: %w", err)
} }
-2
View File
@@ -379,5 +379,3 @@ func TestTranslateGitHubReviewState(t *testing.T) {
} }
} }
} }