diff --git a/github/client.go b/github/client.go index 2d5204e..f958bfa 100644 --- a/github/client.go +++ b/github/client.go @@ -196,7 +196,8 @@ func (c *Client) SetRetryBackoff(d []time.Duration) error { // requestOptions holds per-request configuration for doRequestCore. type requestOptions struct { // 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. bodyFn func() io.Reader diff --git a/github/review.go b/github/review.go index 785175b..7502fc7 100644 --- a/github/review.go +++ b/github/review.go @@ -59,7 +59,8 @@ func translateGitHubReviewState(state string) string { return "COMMENT" default: // 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 } } @@ -77,16 +78,12 @@ func (c *Client) PostReview(ctx context.Context, owner, repo string, number int, 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. for _, comment := range req.Comments { - if comment.CommitID != "" { + if payload.CommitID == "" && comment.CommitID != "" { payload.CommitID = comment.CommitID - break } - } - - for _, comment := range req.Comments { payload.Comments = append(payload.Comments, reviewCommentEntry{ Path: comment.Path, Position: comment.Position, @@ -159,7 +156,7 @@ func (c *Client) DeleteReview(ctx context.Context, owner, repo string, number in if err != nil { var apiErr *APIError if errors.As(err, &apiErr) && apiErr.StatusCode == 422 { - return ErrCannotDeleteSubmittedReview + return fmt.Errorf("delete review: %w", ErrCannotDeleteSubmittedReview) } return fmt.Errorf("delete review: %w", err) } diff --git a/github/review_test.go b/github/review_test.go index 1c3d0ac..da6535d 100644 --- a/github/review_test.go +++ b/github/review_test.go @@ -379,5 +379,3 @@ func TestTranslateGitHubReviewState(t *testing.T) { } } } - -