diff --git a/github/api_test.go b/github/api_test.go index 2265897..cef381b 100644 --- a/github/api_test.go +++ b/github/api_test.go @@ -542,3 +542,41 @@ func TestDoRequestWithBody_RejectsHTTP(t *testing.T) { t.Fatal("expected error for HTTP request") } } + +func TestPostReview_CommitIDFromRequest(t *testing.T) { + const wantCommitID = "abc123def456" + + srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + var payload postReviewRequest + if err := json.NewDecoder(r.Body).Decode(&payload); err != nil { + t.Errorf("decode body: %v", err) + w.WriteHeader(http.StatusBadRequest) + return + } + if payload.CommitID != wantCommitID { + t.Errorf("commit_id = %q, want %q", payload.CommitID, wantCommitID) + } + w.Header().Set("Content-Type", "application/json") + json.NewEncoder(w).Encode(reviewResponse{ + ID: 1, + Body: payload.Body, + State: "COMMENTED", + CommitID: payload.CommitID, + User: struct{ Login string `json:"login"` }{Login: "rodin"}, + }) + })) + defer srv.Close() + + c := NewClient("tok", srv.URL, AllowInsecureHTTPForTest()) + review, err := c.PostReview(context.Background(), "owner", "repo", 1, vcs.ReviewRequest{ + Body: "looks good", + Event: vcs.ReviewEventApprove, + CommitID: wantCommitID, + }) + if err != nil { + t.Fatalf("PostReview: %v", err) + } + if review.CommitID != wantCommitID { + t.Errorf("review.CommitID = %q, want %q", review.CommitID, wantCommitID) + } +} diff --git a/github/client.go b/github/client.go index 4f6df67..67b19ad 100644 --- a/github/client.go +++ b/github/client.go @@ -438,8 +438,6 @@ func (c *Client) GetPullRequest(ctx context.Context, owner, repo string, number return &pr, nil } - - // GetPullRequestFiles fetches the list of files changed in a PR. func (c *Client) GetPullRequestFiles(ctx context.Context, owner, repo string, number int) ([]ChangedFile, error) { reqURL := fmt.Sprintf("%s/repos/%s/%s/pulls/%d/files",