Skip to content

Commit 7a27456

Browse files
committed
Merge remote-tracking branch 'upstream/master' into Issue569_3_cherrypick_1
2 parents 26c4263 + 4a42a1d commit 7a27456

20 files changed

+177
-25
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ for {
171171
if resp.NextPage == 0 {
172172
break
173173
}
174-
opt.ListOptions.Page = resp.NextPage
174+
opt.Page = resp.NextPage
175175
}
176176
```
177177

github/authorizations.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -343,8 +343,13 @@ func (s *AuthorizationsService) Revoke(ctx context.Context, clientID string, tok
343343
// tokens an application has generated for the user.
344344
//
345345
// GitHub API docs: https://developer.github.com/v3/oauth_authorizations/#list-your-grants
346-
func (s *AuthorizationsService) ListGrants(ctx context.Context) ([]*Grant, *Response, error) {
347-
req, err := s.client.NewRequest("GET", "applications/grants", nil)
346+
func (s *AuthorizationsService) ListGrants(ctx context.Context, opt *ListOptions) ([]*Grant, *Response, error) {
347+
u, err := addOptions("applications/grants", opt)
348+
if err != nil {
349+
return nil, nil, err
350+
}
351+
352+
req, err := s.client.NewRequest("GET", u, nil)
348353
if err != nil {
349354
return nil, nil, err
350355
}

github/authorizations_test.go

+19-1
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ func TestListGrants(t *testing.T) {
260260
fmt.Fprint(w, `[{"id": 1}]`)
261261
})
262262

263-
got, _, err := client.Authorizations.ListGrants(context.Background())
263+
got, _, err := client.Authorizations.ListGrants(context.Background(), nil)
264264
if err != nil {
265265
t.Errorf("OAuthAuthorizations.ListGrants returned error: %v", err)
266266
}
@@ -271,6 +271,24 @@ func TestListGrants(t *testing.T) {
271271
}
272272
}
273273

274+
func TestListGrants_withOptions(t *testing.T) {
275+
setup()
276+
defer teardown()
277+
278+
mux.HandleFunc("/applications/grants", func(w http.ResponseWriter, r *http.Request) {
279+
testMethod(t, r, "GET")
280+
testFormValues(t, r, values{
281+
"page": "2",
282+
})
283+
fmt.Fprint(w, `[{"id": 1}]`)
284+
})
285+
286+
_, _, err := client.Authorizations.ListGrants(context.Background(), &ListOptions{Page: 2})
287+
if err != nil {
288+
t.Errorf("OAuthAuthorizations.ListGrants returned error: %v", err)
289+
}
290+
}
291+
274292
func TestGetGrant(t *testing.T) {
275293
setup()
276294
defer teardown()

github/doc.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ github.Response struct.
153153
if resp.NextPage == 0 {
154154
break
155155
}
156-
opt.ListOptions.Page = resp.NextPage
156+
opt.Page = resp.NextPage
157157
}
158158
159159
Google App Engine

github/gists.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,13 @@ func (s *GistsService) Edit(ctx context.Context, id string, gist *Gist) (*Gist,
241241
// ListCommits lists commits of a gist.
242242
//
243243
// GitHub API docs: https://developer.github.com/v3/gists/#list-gist-commits
244-
func (s *GistsService) ListCommits(ctx context.Context, id string) ([]*GistCommit, *Response, error) {
244+
func (s *GistsService) ListCommits(ctx context.Context, id string, opt *ListOptions) ([]*GistCommit, *Response, error) {
245245
u := fmt.Sprintf("gists/%v/commits", id)
246+
u, err := addOptions(u, opt)
247+
if err != nil {
248+
return nil, nil, err
249+
}
250+
246251
req, err := s.client.NewRequest("GET", u, nil)
247252
if err != nil {
248253
return nil, nil, err

github/gists_test.go

+19-1
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ func TestGistsService_ListCommits(t *testing.T) {
308308
`)
309309
})
310310

311-
gistCommits, _, err := client.Gists.ListCommits(context.Background(), "1")
311+
gistCommits, _, err := client.Gists.ListCommits(context.Background(), "1", nil)
312312
if err != nil {
313313
t.Errorf("Gists.ListCommits returned error: %v", err)
314314
}
@@ -329,6 +329,24 @@ func TestGistsService_ListCommits(t *testing.T) {
329329
}
330330
}
331331

332+
func TestGistsService_ListCommits_withOptions(t *testing.T) {
333+
setup()
334+
defer teardown()
335+
336+
mux.HandleFunc("/gists/1/commits", func(w http.ResponseWriter, r *http.Request) {
337+
testMethod(t, r, "GET")
338+
testFormValues(t, r, values{
339+
"page": "2",
340+
})
341+
fmt.Fprint(w, `[]`)
342+
})
343+
344+
_, _, err := client.Gists.ListCommits(context.Background(), "1", &ListOptions{Page: 2})
345+
if err != nil {
346+
t.Errorf("Gists.ListCommits returned error: %v", err)
347+
}
348+
}
349+
332350
func TestGistsService_Delete(t *testing.T) {
333351
setup()
334352
defer teardown()

github/git_trees.go

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ type TreeEntry struct {
3030
Type *string `json:"type,omitempty"`
3131
Size *int `json:"size,omitempty"`
3232
Content *string `json:"content,omitempty"`
33+
URL *string `json:"url,omitempty"`
3334
}
3435

3536
func (t TreeEntry) String() string {

github/git_trees_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ func TestGitService_CreateTree_Content(t *testing.T) {
175175
Type: String("blob"),
176176
Size: Int(12),
177177
SHA: String("aad8feacf6f8063150476a7b2bd9770f2794c08b"),
178+
URL: String("https://api.github.com/repos/o/r/git/blobs/aad8feacf6f8063150476a7b2bd9770f2794c08b"),
178179
},
179180
},
180181
}

github/github.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import (
2727
)
2828

2929
const (
30-
libraryVersion = "6"
30+
libraryVersion = "7"
3131
defaultBaseURL = "https://api.github.com/"
3232
uploadBaseURL = "https://uploads.github.com/"
3333
userAgent = "go-github/" + libraryVersion

github/issues_labels.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ type Label struct {
1919
}
2020

2121
func (l Label) String() string {
22-
return fmt.Sprint(*l.Name)
22+
return Stringify(l)
2323
}
2424

2525
// ListLabels lists all labels for a repository.

github/pulls_reviewers.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,12 @@ func (s *PullRequestsService) RequestReviewers(ctx context.Context, owner, repo
4141
// ListReviewers lists users whose reviews have been requested on the specified pull request.
4242
//
4343
// GitHub API docs: https://developer.github.com/v3/pulls/review_requests/#list-review-requests
44-
func (s *PullRequestsService) ListReviewers(ctx context.Context, owner, repo string, number int) ([]*User, *Response, error) {
44+
func (s *PullRequestsService) ListReviewers(ctx context.Context, owner, repo string, number int, opt *ListOptions) ([]*User, *Response, error) {
4545
u := fmt.Sprintf("repos/%v/%v/pulls/%d/requested_reviewers", owner, repo, number)
46+
u, err := addOptions(u, opt)
47+
if err != nil {
48+
return nil, nil, err
49+
}
4650

4751
req, err := s.client.NewRequest("GET", u, nil)
4852
if err != nil {

github/pulls_reviewers_test.go

+20-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func TestListReviewers(t *testing.T) {
6161
fmt.Fprint(w, `[{"login":"octocat","id":1}]`)
6262
})
6363

64-
reviewers, _, err := client.PullRequests.ListReviewers(context.Background(), "o", "r", 1)
64+
reviewers, _, err := client.PullRequests.ListReviewers(context.Background(), "o", "r", 1, nil)
6565
if err != nil {
6666
t.Errorf("PullRequests.ListReviewers returned error: %v", err)
6767
}
@@ -76,3 +76,22 @@ func TestListReviewers(t *testing.T) {
7676
t.Errorf("PullRequests.ListReviewers returned %+v, want %+v", reviewers, want)
7777
}
7878
}
79+
80+
func TestListReviewers_withOptions(t *testing.T) {
81+
setup()
82+
defer teardown()
83+
84+
mux.HandleFunc("/repos/o/r/pulls/1/requested_reviewers", func(w http.ResponseWriter, r *http.Request) {
85+
testMethod(t, r, "GET")
86+
testFormValues(t, r, values{
87+
"page": "2",
88+
})
89+
testHeader(t, r, "Accept", mediaTypePullRequestReviewsPreview)
90+
fmt.Fprint(w, `[]`)
91+
})
92+
93+
_, _, err := client.PullRequests.ListReviewers(context.Background(), "o", "r", 1, &ListOptions{Page: 2})
94+
if err != nil {
95+
t.Errorf("PullRequests.ListReviewers returned error: %v", err)
96+
}
97+
}

github/pulls_reviews.go

+11-3
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,12 @@ func (r PullRequestReviewDismissalRequest) String() string {
6565
// Read more about it here - https://github.com/google/go-github/issues/540
6666
//
6767
// GitHub API docs: https://developer.github.com/v3/pulls/reviews/#list-reviews-on-a-pull-request
68-
func (s *PullRequestsService) ListReviews(ctx context.Context, owner, repo string, number int) ([]*PullRequestReview, *Response, error) {
68+
func (s *PullRequestsService) ListReviews(ctx context.Context, owner, repo string, number int, opt *ListOptions) ([]*PullRequestReview, *Response, error) {
6969
u := fmt.Sprintf("repos/%v/%v/pulls/%d/reviews", owner, repo, number)
70+
u, err := addOptions(u, opt)
71+
if err != nil {
72+
return nil, nil, err
73+
}
7074

7175
req, err := s.client.NewRequest("GET", u, nil)
7276
if err != nil {
@@ -145,9 +149,13 @@ func (s *PullRequestsService) DeletePendingReview(ctx context.Context, owner, re
145149
// returned error format and remove this comment once it's fixed.
146150
// Read more about it here - https://github.com/google/go-github/issues/540
147151
//
148-
// GitHub API docs: https://developer.github.com/v3/pulls/reviews/#get-a-single-reviews-comments
149-
func (s *PullRequestsService) ListReviewComments(ctx context.Context, owner, repo string, number, reviewID int) ([]*PullRequestComment, *Response, error) {
152+
// GitHub API docs: https://developer.github.com/v3/pulls/reviews/#get-comments-for-a-single-review
153+
func (s *PullRequestsService) ListReviewComments(ctx context.Context, owner, repo string, number, reviewID int, opt *ListOptions) ([]*PullRequestComment, *Response, error) {
150154
u := fmt.Sprintf("repos/%v/%v/pulls/%d/reviews/%d/comments", owner, repo, number, reviewID)
155+
u, err := addOptions(u, opt)
156+
if err != nil {
157+
return nil, nil, err
158+
}
151159

152160
req, err := s.client.NewRequest("GET", u, nil)
153161
if err != nil {

github/pulls_reviews_test.go

+27-4
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,15 @@ func TestPullRequestsService_ListReviews(t *testing.T) {
2020

2121
mux.HandleFunc("/repos/o/r/pulls/1/reviews", func(w http.ResponseWriter, r *http.Request) {
2222
testMethod(t, r, "GET")
23+
testFormValues(t, r, values{
24+
"page": "2",
25+
})
2326
testHeader(t, r, "Accept", mediaTypePullRequestReviewsPreview)
2427
fmt.Fprint(w, `[{"id":1},{"id":2}]`)
2528
})
2629

27-
reviews, _, err := client.PullRequests.ListReviews(context.Background(), "o", "r", 1)
30+
opt := &ListOptions{Page: 2}
31+
reviews, _, err := client.PullRequests.ListReviews(context.Background(), "o", "r", 1, opt)
2832
if err != nil {
2933
t.Errorf("PullRequests.ListReviews returned error: %v", err)
3034
}
@@ -39,7 +43,7 @@ func TestPullRequestsService_ListReviews(t *testing.T) {
3943
}
4044

4145
func TestPullRequestsService_ListReviews_invalidOwner(t *testing.T) {
42-
_, _, err := client.PullRequests.ListReviews(context.Background(), "%", "r", 1)
46+
_, _, err := client.PullRequests.ListReviews(context.Background(), "%", "r", 1, nil)
4347
testURLParseError(t, err)
4448
}
4549

@@ -105,7 +109,7 @@ func TestPullRequestsService_ListReviewComments(t *testing.T) {
105109
fmt.Fprint(w, `[{"id":1},{"id":2}]`)
106110
})
107111

108-
comments, _, err := client.PullRequests.ListReviewComments(context.Background(), "o", "r", 1, 1)
112+
comments, _, err := client.PullRequests.ListReviewComments(context.Background(), "o", "r", 1, 1, nil)
109113
if err != nil {
110114
t.Errorf("PullRequests.ListReviewComments returned error: %v", err)
111115
}
@@ -119,8 +123,27 @@ func TestPullRequestsService_ListReviewComments(t *testing.T) {
119123
}
120124
}
121125

126+
func TestPullRequestsService_ListReviewComments_withOptions(t *testing.T) {
127+
setup()
128+
defer teardown()
129+
130+
mux.HandleFunc("/repos/o/r/pulls/1/reviews/1/comments", func(w http.ResponseWriter, r *http.Request) {
131+
testMethod(t, r, "GET")
132+
testFormValues(t, r, values{
133+
"page": "2",
134+
})
135+
testHeader(t, r, "Accept", mediaTypePullRequestReviewsPreview)
136+
fmt.Fprint(w, `[]`)
137+
})
138+
139+
_, _, err := client.PullRequests.ListReviewComments(context.Background(), "o", "r", 1, 1, &ListOptions{Page: 2})
140+
if err != nil {
141+
t.Errorf("PullRequests.ListReviewComments returned error: %v", err)
142+
}
143+
}
144+
122145
func TestPullRequestsService_ListReviewComments_invalidOwner(t *testing.T) {
123-
_, _, err := client.PullRequests.ListReviewComments(context.Background(), "%", "r", 1, 1)
146+
_, _, err := client.PullRequests.ListReviewComments(context.Background(), "%", "r", 1, 1, nil)
124147
testURLParseError(t, err)
125148
}
126149

github/repos_invitations.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -90,5 +90,9 @@ func (s *RepositoriesService) UpdateInvitation(ctx context.Context, owner, repo
9090

9191
invite := &RepositoryInvitation{}
9292
resp, err := s.client.Do(ctx, req, invite)
93-
return invite, resp, err
93+
if err != nil {
94+
return nil, resp, err
95+
}
96+
97+
return invite, resp, nil
9498
}

github/repos_pages.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,13 @@ func (s *RepositoriesService) GetPagesInfo(ctx context.Context, owner, repo stri
6161
// ListPagesBuilds lists the builds for a GitHub Pages site.
6262
//
6363
// GitHub API docs: https://developer.github.com/v3/repos/pages/#list-pages-builds
64-
func (s *RepositoriesService) ListPagesBuilds(ctx context.Context, owner, repo string) ([]*PagesBuild, *Response, error) {
64+
func (s *RepositoriesService) ListPagesBuilds(ctx context.Context, owner, repo string, opt *ListOptions) ([]*PagesBuild, *Response, error) {
6565
u := fmt.Sprintf("repos/%v/%v/pages/builds", owner, repo)
66+
u, err := addOptions(u, opt)
67+
if err != nil {
68+
return nil, nil, err
69+
}
70+
6671
req, err := s.client.NewRequest("GET", u, nil)
6772
if err != nil {
6873
return nil, nil, err

github/repos_pages_test.go

+19-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func TestRepositoriesService_ListPagesBuilds(t *testing.T) {
4343
fmt.Fprint(w, `[{"url":"u","status":"s","commit":"c"}]`)
4444
})
4545

46-
pages, _, err := client.Repositories.ListPagesBuilds(context.Background(), "o", "r")
46+
pages, _, err := client.Repositories.ListPagesBuilds(context.Background(), "o", "r", nil)
4747
if err != nil {
4848
t.Errorf("Repositories.ListPagesBuilds returned error: %v", err)
4949
}
@@ -54,6 +54,24 @@ func TestRepositoriesService_ListPagesBuilds(t *testing.T) {
5454
}
5555
}
5656

57+
func TestRepositoriesService_ListPagesBuilds_withOptions(t *testing.T) {
58+
setup()
59+
defer teardown()
60+
61+
mux.HandleFunc("/repos/o/r/pages/builds", func(w http.ResponseWriter, r *http.Request) {
62+
testMethod(t, r, "GET")
63+
testFormValues(t, r, values{
64+
"page": "2",
65+
})
66+
fmt.Fprint(w, `[]`)
67+
})
68+
69+
_, _, err := client.Repositories.ListPagesBuilds(context.Background(), "o", "r", &ListOptions{Page: 2})
70+
if err != nil {
71+
t.Errorf("Repositories.ListPagesBuilds returned error: %v", err)
72+
}
73+
}
74+
5775
func TestRepositoriesService_GetLatestPagesBuild(t *testing.T) {
5876
setup()
5977
defer teardown()

github/strings_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ func TestString(t *testing.T) {
105105
{IssueComment{ID: Int(1)}, `github.IssueComment{ID:1}`},
106106
{Issue{Number: Int(1)}, `github.Issue{Number:1}`},
107107
{Key{ID: Int(1)}, `github.Key{ID:1}`},
108-
{Label{Name: String("l")}, "l"},
108+
{Label{ID: Int(1), Name: String("l")}, `github.Label{ID:1, Name:"l"}`},
109109
{Organization{ID: Int(1)}, `github.Organization{ID:1}`},
110110
{PullRequestComment{ID: Int(1)}, `github.PullRequestComment{ID:1}`},
111111
{PullRequest{Number: Int(1)}, `github.PullRequest{Number:1}`},

github/users.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,13 @@ func (s *UsersService) ListAll(ctx context.Context, opt *UserListOptions) ([]*Us
172172
// authenticated user.
173173
//
174174
// GitHub API docs: https://developer.github.com/v3/repos/invitations/#list-a-users-repository-invitations
175-
func (s *UsersService) ListInvitations(ctx context.Context) ([]*RepositoryInvitation, *Response, error) {
176-
req, err := s.client.NewRequest("GET", "user/repository_invitations", nil)
175+
func (s *UsersService) ListInvitations(ctx context.Context, opt *ListOptions) ([]*RepositoryInvitation, *Response, error) {
176+
u, err := addOptions("user/repository_invitations", opt)
177+
if err != nil {
178+
return nil, nil, err
179+
}
180+
181+
req, err := s.client.NewRequest("GET", u, nil)
177182
if err != nil {
178183
return nil, nil, err
179184
}

0 commit comments

Comments
 (0)