Skip to content

Commit df6fff8

Browse files
committed
Address review feedback - require non-nil pull argument
Change-Id: Ibd502b7ab2d8e6bddda834e65529fa7f58141cc3
1 parent 73b2f74 commit df6fff8

File tree

2 files changed

+13
-16
lines changed

2 files changed

+13
-16
lines changed

github/pulls.go

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -198,23 +198,26 @@ type pullRequestUpdate struct {
198198
}
199199

200200
// Edit a pull request.
201-
// pull may be nil, in which case the requested PR is returned unmodified.
201+
// pull must not be nil.
202202
//
203203
// The following fields are editable: Title, Body, State, and Base.Ref.
204204
// Base.Ref updates the base branch of the pull request.
205205
//
206206
// GitHub API docs: https://developer.github.com/v3/pulls/#update-a-pull-request
207207
func (s *PullRequestsService) Edit(ctx context.Context, owner string, repo string, number int, pull *PullRequest) (*PullRequest, *Response, error) {
208+
if pull == nil {
209+
return nil, nil, fmt.Errorf("pull must be provided")
210+
}
211+
208212
u := fmt.Sprintf("repos/%v/%v/pulls/%d", owner, repo, number)
209213

210-
update := new(pullRequestUpdate)
211-
if pull != nil {
212-
update.Title = pull.Title
213-
update.Body = pull.Body
214-
update.State = pull.State
215-
if pull.Base != nil {
216-
update.Base = pull.Base.Ref
217-
}
214+
update := &pullRequestUpdate{
215+
Title: pull.Title,
216+
Body: pull.Body,
217+
State: pull.State,
218+
}
219+
if pull.Base != nil {
220+
update.Base = pull.Base.Ref
218221
}
219222

220223
req, err := s.client.NewRequest("PATCH", u, update)

github/pulls_test.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -250,12 +250,6 @@ func TestPullRequestsService_Edit(t *testing.T) {
250250
wantUpdate: `{"title":"t"}`,
251251
want: &PullRequest{Number: Int(1)},
252252
},
253-
{
254-
// nil request
255-
sendResponse: `{}`,
256-
wantUpdate: `{}`,
257-
want: &PullRequest{},
258-
},
259253
{
260254
// base update
261255
input: &PullRequest{Base: &PullRequestBranch{Ref: String("master")}},
@@ -293,7 +287,7 @@ func TestPullRequestsService_Edit(t *testing.T) {
293287
}
294288

295289
func TestPullRequestsService_Edit_invalidOwner(t *testing.T) {
296-
_, _, err := client.PullRequests.Edit(context.Background(), "%", "r", 1, nil)
290+
_, _, err := client.PullRequests.Edit(context.Background(), "%", "r", 1, &PullRequest{})
297291
testURLParseError(t, err)
298292
}
299293

0 commit comments

Comments
 (0)