Skip to content

Commit 0ab167c

Browse files
joshuabezaleelgmlewis
authored andcommitted
Add method for updating a pull request review (#1177)
Fixes: #1174.
1 parent 9010303 commit 0ab167c

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

github/pulls_reviews.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,29 @@ func (s *PullRequestsService) CreateReview(ctx context.Context, owner, repo stri
189189
return r, resp, nil
190190
}
191191

192+
// UpdateReview updates the review summary on the specified pull request.
193+
//
194+
// GitHub API docs: https://developer.github.com/v3/pulls/reviews/#update-a-pull-request-review
195+
func (s *PullRequestsService) UpdateReview(ctx context.Context, owner, repo string, number int, reviewID int64, body string) (*PullRequestReview, *Response, error) {
196+
opts := &struct {
197+
Body string `json:"body"`
198+
}{Body: body}
199+
u := fmt.Sprintf("repos/%v/%v/pulls/%d/reviews/%d", owner, repo, number, reviewID)
200+
201+
req, err := s.client.NewRequest("PUT", u, opts)
202+
if err != nil {
203+
return nil, nil, err
204+
}
205+
206+
review := &PullRequestReview{}
207+
resp, err := s.client.Do(ctx, req, review)
208+
if err != nil {
209+
return nil, resp, err
210+
}
211+
212+
return review, resp, nil
213+
}
214+
192215
// SubmitReview submits a specified review on the specified pull request.
193216
//
194217
// TODO: Follow up with GitHub support about an issue with this method's

github/pulls_reviews_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,26 @@ func TestPullRequestsService_CreateReview_invalidOwner(t *testing.T) {
195195
testURLParseError(t, err)
196196
}
197197

198+
func TestPullRequestsService_UpdateReview(t *testing.T) {
199+
client, mux, _, teardown := setup()
200+
defer teardown()
201+
202+
mux.HandleFunc("/repos/o/r/pulls/1/reviews/1", func(w http.ResponseWriter, r *http.Request) {
203+
testMethod(t, r, "PUT")
204+
fmt.Fprintf(w, `{"id":1}`)
205+
})
206+
207+
got, _, err := client.PullRequests.UpdateReview(context.Background(), "o", "r", 1, 1, "updated_body")
208+
if err != nil {
209+
t.Errorf("PullRequests.UpdateReview returned error: %v", err)
210+
}
211+
212+
want := &PullRequestReview{ID: Int64(1)}
213+
if !reflect.DeepEqual(got, want) {
214+
t.Errorf("PullRequests.UpdateReview = %+v, want %+v", got, want)
215+
}
216+
}
217+
198218
func TestPullRequestsService_SubmitReview(t *testing.T) {
199219
client, mux, _, teardown := setup()
200220
defer teardown()

0 commit comments

Comments
 (0)