Repository: google/go-github
Pull request #1177 (2019-05-26 20:05:13)

Add method for updating a pull request review
Fixes: #1174 

- Add UpdateReview to PullRequestReview.
- Add its test.

codecov[bot]: # [Codecov](https://codecov.io/gh/google/go-github/pull/1177?src=pr&el=h1) Report
> Merging [#1177](https://codecov.io/gh/google/go-github/pull/1177?src=pr&el=desc) into [master](https://codecov.io/gh/google/go-github/commit/901030391ab7f418a984389fd3f8f65e39e5c823?src=pr&el=desc) will **decrease** coverage by `<.01%`.
> The diff coverage is `69.23%`.

[![Impacted file tree graph](https://codecov.io/gh/google/go-github/pull/1177/graphs/tree.svg?width=650&token=EgYjGjZlI0&height=150&src=pr)](https://codecov.io/gh/google/go-github/pull/1177?src=pr&el=tree)

```diff
@@            Coverage Diff            @@
##           master   #1177      +/-   ##
=========================================
- Coverage    70.2%   70.2%   -0.01%     
=========================================
  Files          84      84              
  Lines        5844    5857      +13     
=========================================
+ Hits         4103    4112       +9     
- Misses        954     956       +2     
- Partials      787     789       +2
```


| [Impacted Files](https://codecov.io/gh/google/go-github/pull/1177?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [github/pulls\_reviews.go](https://codecov.io/gh/google/go-github/pull/1177/diff?src=pr&el=tree#diff-Z2l0aHViL3B1bGxzX3Jldmlld3MuZ28=) | `77.31% <69.23%> (-1.26%)` | :arrow_down: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/google/go-github/pull/1177?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/google/go-github/pull/1177?src=pr&el=footer). Last update [9010303...78c0974](https://codecov.io/gh/google/go-github/pull/1177?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

gmlewis: Thank you, @gauntface!
Merging.

Patch:
diff --git a/github/pulls_reviews.go b/github/pulls_reviews.go
index c2924473..88b82982 100644
--- a/github/pulls_reviews.go
+++ b/github/pulls_reviews.go
@@ -189,6 +189,29 @@ func (s *PullRequestsService) CreateReview(ctx context.Context, owner, repo stri
 	return r, resp, nil
 }
 
+// UpdateReview updates the review summary on the specified pull request.
+//
+// GitHub API docs: https://developer.github.com/v3/pulls/reviews/#update-a-pull-request-review
+func (s *PullRequestsService) UpdateReview(ctx context.Context, owner, repo string, number int, reviewID int64, body string) (*PullRequestReview, *Response, error) {
+	opts := &struct {
+		Body string `json:"body"`
+	}{Body: body}
+	u := fmt.Sprintf("repos/%v/%v/pulls/%d/reviews/%d", owner, repo, number, reviewID)
+
+	req, err := s.client.NewRequest("PUT", u, opts)
+	if err != nil {
+		return nil, nil, err
+	}
+
+	review := &PullRequestReview{}
+	resp, err := s.client.Do(ctx, req, review)
+	if err != nil {
+		return nil, resp, err
+	}
+
+	return review, resp, nil
+}
+
 // SubmitReview submits a specified review on the specified pull request.
 //
 // TODO: Follow up with GitHub support about an issue with this method's


Test patch:
diff --git a/github/pulls_reviews_test.go b/github/pulls_reviews_test.go
index 58e301bd..3b78bc9e 100644
--- a/github/pulls_reviews_test.go
+++ b/github/pulls_reviews_test.go
@@ -195,6 +195,26 @@ func TestPullRequestsService_CreateReview_invalidOwner(t *testing.T) {
 	testURLParseError(t, err)
 }
 
+func TestPullRequestsService_UpdateReview(t *testing.T) {
+	client, mux, _, teardown := setup()
+	defer teardown()
+
+	mux.HandleFunc("/repos/o/r/pulls/1/reviews/1", func(w http.ResponseWriter, r *http.Request) {
+		testMethod(t, r, "PUT")
+		fmt.Fprintf(w, `{"id":1}`)
+	})
+
+	got, _, err := client.PullRequests.UpdateReview(context.Background(), "o", "r", 1, 1, "updated_body")
+	if err != nil {
+		t.Errorf("PullRequests.UpdateReview returned error: %v", err)
+	}
+
+	want := &PullRequestReview{ID: Int64(1)}
+	if !reflect.DeepEqual(got, want) {
+		t.Errorf("PullRequests.UpdateReview = %+v, want %+v", got, want)
+	}
+}
+
 func TestPullRequestsService_SubmitReview(t *testing.T) {
 	client, mux, _, teardown := setup()
 	defer teardown()