Browse Source

add pagination support for more methods

This includes all of the methods mentioned in this blog post:
https://developer.github.com/changes/2014-03-18-paginating-method-changes/
as well as a handful of others I found.  Sadly, this is a breaking
change for many of these methods because it changes the method
signature, but with yesterday's API change these methods are now broken
anyway. :(
Will Norris 12 years ago
parent
commit
7aa0972552
32 changed files with 247 additions and 77 deletions
  1. +6
    -1
      github/gists_comments.go
  2. +4
    -2
      github/gists_comments_test.go
  3. +7
    -0
      github/git_refs.go
  4. +2
    -1
      github/git_refs_test.go
  5. +6
    -1
      github/issues_assignees.go
  6. +4
    -2
      github/issues_assignees_test.go
  7. +18
    -3
      github/issues_labels.go
  8. +12
    -6
      github/issues_labels_test.go
  9. +18
    -3
      github/orgs_teams.go
  10. +10
    -4
      github/orgs_teams_test.go
  11. +14
    -2
      github/pulls.go
  12. +9
    -6
      github/pulls_test.go
  13. +20
    -4
      github/repos.go
  14. +6
    -1
      github/repos_collaborators.go
  15. +4
    -2
      github/repos_collaborators_test.go
  16. +12
    -2
      github/repos_comments.go
  17. +8
    -4
      github/repos_comments_test.go
  18. +5
    -1
      github/repos_keys.go
  19. +4
    -2
      github/repos_keys_test.go
  20. +10
    -2
      github/repos_releases.go
  21. +6
    -2
      github/repos_releases_test.go
  22. +6
    -1
      github/repos_statuses.go
  23. +4
    -2
      github/repos_statuses_test.go
  24. +14
    -4
      github/repos_test.go
  25. +6
    -1
      github/users_emails.go
  26. +3
    -1
      github/users_emails_test.go
  27. +5
    -1
      github/users_followers.go
  28. +5
    -3
      github/users_followers_test.go
  29. +5
    -1
      github/users_keys.go
  30. +5
    -3
      github/users_keys_test.go
  31. +2
    -2
      tests/integration/repos_test.go
  32. +7
    -7
      tests/integration/users_test.go

+ 6
- 1
github/gists_comments.go View File

@ -26,8 +26,13 @@ func (g GistComment) String() string {
// ListComments lists all comments for a gist. // ListComments lists all comments for a gist.
// //
// GitHub API docs: http://developer.github.com/v3/gists/comments/#list-comments-on-a-gist // GitHub API docs: http://developer.github.com/v3/gists/comments/#list-comments-on-a-gist
func (s *GistsService) ListComments(gistID string) ([]GistComment, *Response, error) {
func (s *GistsService) ListComments(gistID string, opt *ListOptions) ([]GistComment, *Response, error) {
u := fmt.Sprintf("gists/%v/comments", gistID) u := fmt.Sprintf("gists/%v/comments", gistID)
u, err := addOptions(u, opt)
if err != nil {
return nil, nil, err
}
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err


+ 4
- 2
github/gists_comments_test.go View File

@ -19,10 +19,12 @@ func TestGistsService_ListComments(t *testing.T) {
mux.HandleFunc("/gists/1/comments", func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("/gists/1/comments", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET") testMethod(t, r, "GET")
testFormValues(t, r, values{"page": "2"})
fmt.Fprint(w, `[{"id": 1}]`) fmt.Fprint(w, `[{"id": 1}]`)
}) })
comments, _, err := client.Gists.ListComments("1")
opt := &ListOptions{Page: 2}
comments, _, err := client.Gists.ListComments("1", opt)
if err != nil { if err != nil {
t.Errorf("Gists.Comments returned error: %v", err) t.Errorf("Gists.Comments returned error: %v", err)
@ -35,7 +37,7 @@ func TestGistsService_ListComments(t *testing.T) {
} }
func TestGistsService_ListComments_invalidID(t *testing.T) { func TestGistsService_ListComments_invalidID(t *testing.T) {
_, _, err := client.Gists.ListComments("%")
_, _, err := client.Gists.ListComments("%", nil)
testURLParseError(t, err) testURLParseError(t, err)
} }


+ 7
- 0
github/git_refs.go View File

@ -66,6 +66,8 @@ func (s *GitService) GetRef(owner string, repo string, ref string) (*Reference,
// GitService.ListRefs method. // GitService.ListRefs method.
type ReferenceListOptions struct { type ReferenceListOptions struct {
Type string `url:"-"` Type string `url:"-"`
ListOptions
} }
// ListRefs lists all refs in a repository. // ListRefs lists all refs in a repository.
@ -78,6 +80,11 @@ func (s *GitService) ListRefs(owner, repo string, opt *ReferenceListOptions) ([]
} else { } else {
u = fmt.Sprintf("repos/%v/%v/git/refs", owner, repo) u = fmt.Sprintf("repos/%v/%v/git/refs", owner, repo)
} }
u, err := addOptions(u, opt)
if err != nil {
return nil, nil, err
}
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err


+ 2
- 1
github/git_refs_test.go View File

@ -115,10 +115,11 @@ func TestGitService_ListRefs_options(t *testing.T) {
mux.HandleFunc("/repos/o/r/git/refs/t", func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("/repos/o/r/git/refs/t", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET") testMethod(t, r, "GET")
testFormValues(t, r, values{"page": "2"})
fmt.Fprint(w, `[{"ref": "r"}]`) fmt.Fprint(w, `[{"ref": "r"}]`)
}) })
opt := &ReferenceListOptions{Type: "t"}
opt := &ReferenceListOptions{Type: "t", ListOptions: ListOptions{Page: 2}}
refs, _, err := client.Git.ListRefs("o", "r", opt) refs, _, err := client.Git.ListRefs("o", "r", opt)
if err != nil { if err != nil {
t.Errorf("Git.ListRefs returned error: %v", err) t.Errorf("Git.ListRefs returned error: %v", err)


+ 6
- 1
github/issues_assignees.go View File

@ -11,8 +11,13 @@ import "fmt"
// which issues may be assigned. // which issues may be assigned.
// //
// GitHub API docs: http://developer.github.com/v3/issues/assignees/#list-assignees // GitHub API docs: http://developer.github.com/v3/issues/assignees/#list-assignees
func (s *IssuesService) ListAssignees(owner string, repo string) ([]User, *Response, error) {
func (s *IssuesService) ListAssignees(owner string, repo string, opt *ListOptions) ([]User, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/assignees", owner, repo) u := fmt.Sprintf("repos/%v/%v/assignees", owner, repo)
u, err := addOptions(u, opt)
if err != nil {
return nil, nil, err
}
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err


+ 4
- 2
github/issues_assignees_test.go View File

@ -18,10 +18,12 @@ func TestIssuesService_ListAssignees(t *testing.T) {
mux.HandleFunc("/repos/o/r/assignees", func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("/repos/o/r/assignees", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET") testMethod(t, r, "GET")
testFormValues(t, r, values{"page": "2"})
fmt.Fprint(w, `[{"id":1}]`) fmt.Fprint(w, `[{"id":1}]`)
}) })
assignees, _, err := client.Issues.ListAssignees("o", "r")
opt := &ListOptions{Page: 2}
assignees, _, err := client.Issues.ListAssignees("o", "r", opt)
if err != nil { if err != nil {
t.Errorf("Issues.List returned error: %v", err) t.Errorf("Issues.List returned error: %v", err)
} }
@ -33,7 +35,7 @@ func TestIssuesService_ListAssignees(t *testing.T) {
} }
func TestIssuesService_ListAssignees_invalidOwner(t *testing.T) { func TestIssuesService_ListAssignees_invalidOwner(t *testing.T) {
_, _, err := client.Issues.ListAssignees("%", "r")
_, _, err := client.Issues.ListAssignees("%", "r", nil)
testURLParseError(t, err) testURLParseError(t, err)
} }


+ 18
- 3
github/issues_labels.go View File

@ -21,8 +21,13 @@ func (l Label) String() string {
// ListLabels lists all labels for a repository. // ListLabels lists all labels for a repository.
// //
// GitHub API docs: http://developer.github.com/v3/issues/labels/#list-all-labels-for-this-repository // GitHub API docs: http://developer.github.com/v3/issues/labels/#list-all-labels-for-this-repository
func (s *IssuesService) ListLabels(owner string, repo string) ([]Label, *Response, error) {
func (s *IssuesService) ListLabels(owner string, repo string, opt *ListOptions) ([]Label, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/labels", owner, repo) u := fmt.Sprintf("repos/%v/%v/labels", owner, repo)
u, err := addOptions(u, opt)
if err != nil {
return nil, nil, err
}
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
@ -109,8 +114,13 @@ func (s *IssuesService) DeleteLabel(owner string, repo string, name string) (*Re
// ListLabelsByIssue lists all labels for an issue. // ListLabelsByIssue lists all labels for an issue.
// //
// GitHub API docs: http://developer.github.com/v3/issues/labels/#list-all-labels-for-this-repository // GitHub API docs: http://developer.github.com/v3/issues/labels/#list-all-labels-for-this-repository
func (s *IssuesService) ListLabelsByIssue(owner string, repo string, number int) ([]Label, *Response, error) {
func (s *IssuesService) ListLabelsByIssue(owner string, repo string, number int, opt *ListOptions) ([]Label, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/issues/%d/labels", owner, repo, number) u := fmt.Sprintf("repos/%v/%v/issues/%d/labels", owner, repo, number)
u, err := addOptions(u, opt)
if err != nil {
return nil, nil, err
}
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
@ -190,8 +200,13 @@ func (s *IssuesService) RemoveLabelsForIssue(owner string, repo string, number i
// ListLabelsForMilestone lists labels for every issue in a milestone. // ListLabelsForMilestone lists labels for every issue in a milestone.
// //
// GitHub API docs: http://developer.github.com/v3/issues/labels/#get-labels-for-every-issue-in-a-milestone // GitHub API docs: http://developer.github.com/v3/issues/labels/#get-labels-for-every-issue-in-a-milestone
func (s *IssuesService) ListLabelsForMilestone(owner string, repo string, number int) ([]Label, *Response, error) {
func (s *IssuesService) ListLabelsForMilestone(owner string, repo string, number int, opt *ListOptions) ([]Label, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/milestones/%d/labels", owner, repo, number) u := fmt.Sprintf("repos/%v/%v/milestones/%d/labels", owner, repo, number)
u, err := addOptions(u, opt)
if err != nil {
return nil, nil, err
}
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err


+ 12
- 6
github/issues_labels_test.go View File

@ -19,10 +19,12 @@ func TestIssuesService_ListLabels(t *testing.T) {
mux.HandleFunc("/repos/o/r/labels", func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("/repos/o/r/labels", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET") testMethod(t, r, "GET")
testFormValues(t, r, values{"page": "2"})
fmt.Fprint(w, `[{"name": "a"},{"name": "b"}]`) fmt.Fprint(w, `[{"name": "a"},{"name": "b"}]`)
}) })
labels, _, err := client.Issues.ListLabels("o", "r")
opt := &ListOptions{Page: 2}
labels, _, err := client.Issues.ListLabels("o", "r", opt)
if err != nil { if err != nil {
t.Errorf("Issues.ListLabels returned error: %v", err) t.Errorf("Issues.ListLabels returned error: %v", err)
} }
@ -34,7 +36,7 @@ func TestIssuesService_ListLabels(t *testing.T) {
} }
func TestIssuesService_ListLabels_invalidOwner(t *testing.T) { func TestIssuesService_ListLabels_invalidOwner(t *testing.T) {
_, _, err := client.Issues.ListLabels("%", "%")
_, _, err := client.Issues.ListLabels("%", "%", nil)
testURLParseError(t, err) testURLParseError(t, err)
} }
@ -156,10 +158,12 @@ func TestIssuesService_ListLabelsByIssue(t *testing.T) {
mux.HandleFunc("/repos/o/r/issues/1/labels", func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("/repos/o/r/issues/1/labels", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET") testMethod(t, r, "GET")
testFormValues(t, r, values{"page": "2"})
fmt.Fprint(w, `[{"name": "a"},{"name": "b"}]`) fmt.Fprint(w, `[{"name": "a"},{"name": "b"}]`)
}) })
labels, _, err := client.Issues.ListLabelsByIssue("o", "r", 1)
opt := &ListOptions{Page: 2}
labels, _, err := client.Issues.ListLabelsByIssue("o", "r", 1, opt)
if err != nil { if err != nil {
t.Errorf("Issues.ListLabelsByIssue returned error: %v", err) t.Errorf("Issues.ListLabelsByIssue returned error: %v", err)
} }
@ -171,7 +175,7 @@ func TestIssuesService_ListLabelsByIssue(t *testing.T) {
} }
func TestIssuesService_ListLabelsByIssue_invalidOwner(t *testing.T) { func TestIssuesService_ListLabelsByIssue_invalidOwner(t *testing.T) {
_, _, err := client.Issues.ListLabelsByIssue("%", "%", 1)
_, _, err := client.Issues.ListLabelsByIssue("%", "%", 1, nil)
testURLParseError(t, err) testURLParseError(t, err)
} }
@ -287,10 +291,12 @@ func TestIssuesService_ListLabelsForMilestone(t *testing.T) {
mux.HandleFunc("/repos/o/r/milestones/1/labels", func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("/repos/o/r/milestones/1/labels", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET") testMethod(t, r, "GET")
testFormValues(t, r, values{"page": "2"})
fmt.Fprint(w, `[{"name": "a"},{"name": "b"}]`) fmt.Fprint(w, `[{"name": "a"},{"name": "b"}]`)
}) })
labels, _, err := client.Issues.ListLabelsForMilestone("o", "r", 1)
opt := &ListOptions{Page: 2}
labels, _, err := client.Issues.ListLabelsForMilestone("o", "r", 1, opt)
if err != nil { if err != nil {
t.Errorf("Issues.ListLabelsForMilestone returned error: %v", err) t.Errorf("Issues.ListLabelsForMilestone returned error: %v", err)
} }
@ -302,6 +308,6 @@ func TestIssuesService_ListLabelsForMilestone(t *testing.T) {
} }
func TestIssuesService_ListLabelsForMilestone_invalidOwner(t *testing.T) { func TestIssuesService_ListLabelsForMilestone_invalidOwner(t *testing.T) {
_, _, err := client.Issues.ListLabelsForMilestone("%", "%", 1)
_, _, err := client.Issues.ListLabelsForMilestone("%", "%", 1, nil)
testURLParseError(t, err) testURLParseError(t, err)
} }

+ 18
- 3
github/orgs_teams.go View File

@ -26,8 +26,13 @@ func (t Team) String() string {
// ListTeams lists all of the teams for an organization. // ListTeams lists all of the teams for an organization.
// //
// GitHub API docs: http://developer.github.com/v3/orgs/teams/#list-teams // GitHub API docs: http://developer.github.com/v3/orgs/teams/#list-teams
func (s *OrganizationsService) ListTeams(org string) ([]Team, *Response, error) {
func (s *OrganizationsService) ListTeams(org string, opt *ListOptions) ([]Team, *Response, error) {
u := fmt.Sprintf("orgs/%v/teams", org) u := fmt.Sprintf("orgs/%v/teams", org)
u, err := addOptions(u, opt)
if err != nil {
return nil, nil, err
}
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
@ -116,8 +121,13 @@ func (s *OrganizationsService) DeleteTeam(team int) (*Response, error) {
// team. // team.
// //
// GitHub API docs: http://developer.github.com/v3/orgs/teams/#list-team-members // GitHub API docs: http://developer.github.com/v3/orgs/teams/#list-team-members
func (s *OrganizationsService) ListTeamMembers(team int) ([]User, *Response, error) {
func (s *OrganizationsService) ListTeamMembers(team int, opt *ListOptions) ([]User, *Response, error) {
u := fmt.Sprintf("teams/%v/members", team) u := fmt.Sprintf("teams/%v/members", team)
u, err := addOptions(u, opt)
if err != nil {
return nil, nil, err
}
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
@ -176,8 +186,13 @@ func (s *OrganizationsService) RemoveTeamMember(team int, user string) (*Respons
// ListTeamRepos lists the repositories that the specified team has access to. // ListTeamRepos lists the repositories that the specified team has access to.
// //
// GitHub API docs: http://developer.github.com/v3/orgs/teams/#list-team-repos // GitHub API docs: http://developer.github.com/v3/orgs/teams/#list-team-repos
func (s *OrganizationsService) ListTeamRepos(team int) ([]Repository, *Response, error) {
func (s *OrganizationsService) ListTeamRepos(team int, opt *ListOptions) ([]Repository, *Response, error) {
u := fmt.Sprintf("teams/%v/repos", team) u := fmt.Sprintf("teams/%v/repos", team)
u, err := addOptions(u, opt)
if err != nil {
return nil, nil, err
}
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err


+ 10
- 4
github/orgs_teams_test.go View File

@ -19,10 +19,12 @@ func TestOrganizationsService_ListTeams(t *testing.T) {
mux.HandleFunc("/orgs/o/teams", func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("/orgs/o/teams", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET") testMethod(t, r, "GET")
testFormValues(t, r, values{"page": "2"})
fmt.Fprint(w, `[{"id":1}]`) fmt.Fprint(w, `[{"id":1}]`)
}) })
teams, _, err := client.Organizations.ListTeams("o")
opt := &ListOptions{Page: 2}
teams, _, err := client.Organizations.ListTeams("o", opt)
if err != nil { if err != nil {
t.Errorf("Organizations.ListTeams returned error: %v", err) t.Errorf("Organizations.ListTeams returned error: %v", err)
} }
@ -34,7 +36,7 @@ func TestOrganizationsService_ListTeams(t *testing.T) {
} }
func TestOrganizationsService_ListTeams_invalidOrg(t *testing.T) { func TestOrganizationsService_ListTeams_invalidOrg(t *testing.T) {
_, _, err := client.Organizations.ListTeams("%")
_, _, err := client.Organizations.ListTeams("%", nil)
testURLParseError(t, err) testURLParseError(t, err)
} }
@ -141,10 +143,12 @@ func TestOrganizationsService_ListTeamMembers(t *testing.T) {
mux.HandleFunc("/teams/1/members", func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("/teams/1/members", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET") testMethod(t, r, "GET")
testFormValues(t, r, values{"page": "2"})
fmt.Fprint(w, `[{"id":1}]`) fmt.Fprint(w, `[{"id":1}]`)
}) })
members, _, err := client.Organizations.ListTeamMembers(1)
opt := &ListOptions{Page: 2}
members, _, err := client.Organizations.ListTeamMembers(1, opt)
if err != nil { if err != nil {
t.Errorf("Organizations.ListTeamMembers returned error: %v", err) t.Errorf("Organizations.ListTeamMembers returned error: %v", err)
} }
@ -302,10 +306,12 @@ func TestOrganizationsService_ListTeamRepos(t *testing.T) {
mux.HandleFunc("/teams/1/repos", func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("/teams/1/repos", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET") testMethod(t, r, "GET")
testFormValues(t, r, values{"page": "2"})
fmt.Fprint(w, `[{"id":1}]`) fmt.Fprint(w, `[{"id":1}]`)
}) })
members, _, err := client.Organizations.ListTeamRepos(1)
opt := &ListOptions{Page: 2}
members, _, err := client.Organizations.ListTeamRepos(1, opt)
if err != nil { if err != nil {
t.Errorf("Organizations.ListTeamRepos returned error: %v", err) t.Errorf("Organizations.ListTeamRepos returned error: %v", err)
} }


+ 14
- 2
github/pulls.go View File

@ -60,6 +60,8 @@ type PullRequestListOptions struct {
// Base filters pull requests by base branch name. // Base filters pull requests by base branch name.
Base string `url:"base,omitempty"` Base string `url:"base,omitempty"`
ListOptions
} }
// List the pull requests for the specified repository. // List the pull requests for the specified repository.
@ -146,8 +148,13 @@ func (s *PullRequestsService) Edit(owner string, repo string, number int, pull *
// ListCommits lists the commits in a pull request. // ListCommits lists the commits in a pull request.
// //
// GitHub API docs: https://developer.github.com/v3/pulls/#list-commits-on-a-pull-request // GitHub API docs: https://developer.github.com/v3/pulls/#list-commits-on-a-pull-request
func (s *PullRequestsService) ListCommits(owner string, repo string, number int) (*[]Commit, *Response, error) {
func (s *PullRequestsService) ListCommits(owner string, repo string, number int, opt *ListOptions) (*[]Commit, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/pulls/%d/commits", owner, repo, number) u := fmt.Sprintf("repos/%v/%v/pulls/%d/commits", owner, repo, number)
u, err := addOptions(u, opt)
if err != nil {
return nil, nil, err
}
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
@ -165,8 +172,13 @@ func (s *PullRequestsService) ListCommits(owner string, repo string, number int)
// ListFiles lists the files in a pull request. // ListFiles lists the files in a pull request.
// //
// GitHub API docs: https://developer.github.com/v3/pulls/#list-pull-requests-files // GitHub API docs: https://developer.github.com/v3/pulls/#list-pull-requests-files
func (s *PullRequestsService) ListFiles(owner string, repo string, number int) (*[]CommitFile, *Response, error) {
func (s *PullRequestsService) ListFiles(owner string, repo string, number int, opt *ListOptions) (*[]CommitFile, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/pulls/%d/files", owner, repo, number) u := fmt.Sprintf("repos/%v/%v/pulls/%d/files", owner, repo, number)
u, err := addOptions(u, opt)
if err != nil {
return nil, nil, err
}
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err


+ 9
- 6
github/pulls_test.go View File

@ -23,11 +23,12 @@ func TestPullRequestsService_List(t *testing.T) {
"state": "closed", "state": "closed",
"head": "h", "head": "h",
"base": "b", "base": "b",
"page": "2",
}) })
fmt.Fprint(w, `[{"number":1}]`) fmt.Fprint(w, `[{"number":1}]`)
}) })
opt := &PullRequestListOptions{"closed", "h", "b"}
opt := &PullRequestListOptions{"closed", "h", "b", ListOptions{Page: 2}}
pulls, _, err := client.PullRequests.List("o", "r", opt) pulls, _, err := client.PullRequests.List("o", "r", opt)
if err != nil { if err != nil {
@ -145,7 +146,7 @@ func TestPullRequestsService_ListCommits(t *testing.T) {
mux.HandleFunc("/repos/o/r/pulls/1/commits", func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("/repos/o/r/pulls/1/commits", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET") testMethod(t, r, "GET")
testFormValues(t, r, values{"page": "2"})
fmt.Fprint(w, ` fmt.Fprint(w, `
[ [
{ {
@ -156,7 +157,7 @@ func TestPullRequestsService_ListCommits(t *testing.T) {
} }
] ]
}, },
{
{
"sha": "2", "sha": "2",
"parents": [ "parents": [
{ {
@ -167,7 +168,8 @@ func TestPullRequestsService_ListCommits(t *testing.T) {
]`) ]`)
}) })
commits, _, err := client.PullRequests.ListCommits("o", "r", 1)
opt := &ListOptions{Page: 2}
commits, _, err := client.PullRequests.ListCommits("o", "r", 1, opt)
if err != nil { if err != nil {
t.Errorf("PullRequests.ListCommits returned error: %v", err) t.Errorf("PullRequests.ListCommits returned error: %v", err)
} }
@ -201,7 +203,7 @@ func TestPullRequestsService_ListFiles(t *testing.T) {
mux.HandleFunc("/repos/o/r/pulls/1/files", func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("/repos/o/r/pulls/1/files", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET") testMethod(t, r, "GET")
testFormValues(t, r, values{"page": "2"})
fmt.Fprint(w, ` fmt.Fprint(w, `
[ [
{ {
@ -225,7 +227,8 @@ func TestPullRequestsService_ListFiles(t *testing.T) {
]`) ]`)
}) })
commitFiles, _, err := client.PullRequests.ListFiles("o", "r", 1)
opt := &ListOptions{Page: 2}
commitFiles, _, err := client.PullRequests.ListFiles("o", "r", 1, opt)
if err != nil { if err != nil {
t.Errorf("PullRequests.ListFiles returned error: %v", err) t.Errorf("PullRequests.ListFiles returned error: %v", err)
} }


+ 20
- 4
github/repos.go View File

@ -270,6 +270,8 @@ type Contributor struct {
type ListContributorsOptions struct { type ListContributorsOptions struct {
// Include anonymous contributors in results or not // Include anonymous contributors in results or not
Anon string `url:"anon,omitempty"` Anon string `url:"anon,omitempty"`
ListOptions
} }
// ListContributors lists contributors for a repository. // ListContributors lists contributors for a repository.
@ -277,7 +279,6 @@ type ListContributorsOptions struct {
// GitHub API docs: http://developer.github.com/v3/repos/#list-contributors // GitHub API docs: http://developer.github.com/v3/repos/#list-contributors
func (s *RepositoriesService) ListContributors(owner string, repository string, opt *ListContributorsOptions) ([]Contributor, *Response, error) { func (s *RepositoriesService) ListContributors(owner string, repository string, opt *ListContributorsOptions) ([]Contributor, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/contributors", owner, repository) u := fmt.Sprintf("repos/%v/%v/contributors", owner, repository)
u, err := addOptions(u, opt) u, err := addOptions(u, opt)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
@ -326,8 +327,13 @@ func (s *RepositoriesService) ListLanguages(owner string, repo string) (map[stri
// ListTeams lists the teams for the specified repository. // ListTeams lists the teams for the specified repository.
// //
// GitHub API docs: https://developer.github.com/v3/repos/#list-teams // GitHub API docs: https://developer.github.com/v3/repos/#list-teams
func (s *RepositoriesService) ListTeams(owner string, repo string) ([]Team, *Response, error) {
func (s *RepositoriesService) ListTeams(owner string, repo string, opt *ListOptions) ([]Team, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/teams", owner, repo) u := fmt.Sprintf("repos/%v/%v/teams", owner, repo)
u, err := addOptions(u, opt)
if err != nil {
return nil, nil, err
}
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
@ -353,8 +359,13 @@ type RepositoryTag struct {
// ListTags lists tags for the specified repository. // ListTags lists tags for the specified repository.
// //
// GitHub API docs: https://developer.github.com/v3/repos/#list-tags // GitHub API docs: https://developer.github.com/v3/repos/#list-tags
func (s *RepositoriesService) ListTags(owner string, repo string) ([]RepositoryTag, *Response, error) {
func (s *RepositoriesService) ListTags(owner string, repo string, opt *ListOptions) ([]RepositoryTag, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/tags", owner, repo) u := fmt.Sprintf("repos/%v/%v/tags", owner, repo)
u, err := addOptions(u, opt)
if err != nil {
return nil, nil, err
}
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
@ -378,8 +389,13 @@ type Branch struct {
// ListBranches lists branches for the specified repository. // ListBranches lists branches for the specified repository.
// //
// GitHub API docs: http://developer.github.com/v3/repos/#list-branches // GitHub API docs: http://developer.github.com/v3/repos/#list-branches
func (s *RepositoriesService) ListBranches(owner string, repo string) ([]Branch, *Response, error) {
func (s *RepositoriesService) ListBranches(owner string, repo string, opt *ListOptions) ([]Branch, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/branches", owner, repo) u := fmt.Sprintf("repos/%v/%v/branches", owner, repo)
u, err := addOptions(u, opt)
if err != nil {
return nil, nil, err
}
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err


+ 6
- 1
github/repos_collaborators.go View File

@ -10,8 +10,13 @@ import "fmt"
// ListCollaborators lists the Github users that have access to the repository. // ListCollaborators lists the Github users that have access to the repository.
// //
// GitHub API docs: http://developer.github.com/v3/repos/collaborators/#list // GitHub API docs: http://developer.github.com/v3/repos/collaborators/#list
func (s *RepositoriesService) ListCollaborators(owner, repo string) ([]User, *Response, error) {
func (s *RepositoriesService) ListCollaborators(owner, repo string, opt *ListOptions) ([]User, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/collaborators", owner, repo) u := fmt.Sprintf("repos/%v/%v/collaborators", owner, repo)
u, err := addOptions(u, opt)
if err != nil {
return nil, nil, err
}
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err


+ 4
- 2
github/repos_collaborators_test.go View File

@ -18,10 +18,12 @@ func TestRepositoriesService_ListCollaborators(t *testing.T) {
mux.HandleFunc("/repos/o/r/collaborators", func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("/repos/o/r/collaborators", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET") testMethod(t, r, "GET")
testFormValues(t, r, values{"page": "2"})
fmt.Fprintf(w, `[{"id":1}, {"id":2}]`) fmt.Fprintf(w, `[{"id":1}, {"id":2}]`)
}) })
users, _, err := client.Repositories.ListCollaborators("o", "r")
opt := &ListOptions{Page: 2}
users, _, err := client.Repositories.ListCollaborators("o", "r", opt)
if err != nil { if err != nil {
t.Errorf("Repositories.ListCollaborators returned error: %v", err) t.Errorf("Repositories.ListCollaborators returned error: %v", err)
} }
@ -33,7 +35,7 @@ func TestRepositoriesService_ListCollaborators(t *testing.T) {
} }
func TestRepositoriesService_ListCollaborators_invalidOwner(t *testing.T) { func TestRepositoriesService_ListCollaborators_invalidOwner(t *testing.T) {
_, _, err := client.Repositories.ListCollaborators("%", "%")
_, _, err := client.Repositories.ListCollaborators("%", "%", nil)
testURLParseError(t, err) testURLParseError(t, err)
} }


+ 12
- 2
github/repos_comments.go View File

@ -34,8 +34,13 @@ func (r RepositoryComment) String() string {
// ListComments lists all the comments for the repository. // ListComments lists all the comments for the repository.
// //
// GitHub API docs: http://developer.github.com/v3/repos/comments/#list-commit-comments-for-a-repository // GitHub API docs: http://developer.github.com/v3/repos/comments/#list-commit-comments-for-a-repository
func (s *RepositoriesService) ListComments(owner, repo string) ([]RepositoryComment, *Response, error) {
func (s *RepositoriesService) ListComments(owner, repo string, opt *ListOptions) ([]RepositoryComment, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/comments", owner, repo) u := fmt.Sprintf("repos/%v/%v/comments", owner, repo)
u, err := addOptions(u, opt)
if err != nil {
return nil, nil, err
}
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
@ -53,8 +58,13 @@ func (s *RepositoriesService) ListComments(owner, repo string) ([]RepositoryComm
// ListCommitComments lists all the comments for a given commit SHA. // ListCommitComments lists all the comments for a given commit SHA.
// //
// GitHub API docs: http://developer.github.com/v3/repos/comments/#list-comments-for-a-single-commit // GitHub API docs: http://developer.github.com/v3/repos/comments/#list-comments-for-a-single-commit
func (s *RepositoriesService) ListCommitComments(owner, repo, sha string) ([]RepositoryComment, *Response, error) {
func (s *RepositoriesService) ListCommitComments(owner, repo, sha string, opt *ListOptions) ([]RepositoryComment, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/commits/%v/comments", owner, repo, sha) u := fmt.Sprintf("repos/%v/%v/commits/%v/comments", owner, repo, sha)
u, err := addOptions(u, opt)
if err != nil {
return nil, nil, err
}
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err


+ 8
- 4
github/repos_comments_test.go View File

@ -19,10 +19,12 @@ func TestRepositoriesService_ListComments(t *testing.T) {
mux.HandleFunc("/repos/o/r/comments", func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("/repos/o/r/comments", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET") testMethod(t, r, "GET")
testFormValues(t, r, values{"page": "2"})
fmt.Fprint(w, `[{"id":1}, {"id":2}]`) fmt.Fprint(w, `[{"id":1}, {"id":2}]`)
}) })
comments, _, err := client.Repositories.ListComments("o", "r")
opt := &ListOptions{Page: 2}
comments, _, err := client.Repositories.ListComments("o", "r", opt)
if err != nil { if err != nil {
t.Errorf("Repositories.ListComments returned error: %v", err) t.Errorf("Repositories.ListComments returned error: %v", err)
} }
@ -34,7 +36,7 @@ func TestRepositoriesService_ListComments(t *testing.T) {
} }
func TestRepositoriesService_ListComments_invalidOwner(t *testing.T) { func TestRepositoriesService_ListComments_invalidOwner(t *testing.T) {
_, _, err := client.Repositories.ListComments("%", "%")
_, _, err := client.Repositories.ListComments("%", "%", nil)
testURLParseError(t, err) testURLParseError(t, err)
} }
@ -44,10 +46,12 @@ func TestRepositoriesService_ListCommitComments(t *testing.T) {
mux.HandleFunc("/repos/o/r/commits/s/comments", func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("/repos/o/r/commits/s/comments", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET") testMethod(t, r, "GET")
testFormValues(t, r, values{"page": "2"})
fmt.Fprint(w, `[{"id":1}, {"id":2}]`) fmt.Fprint(w, `[{"id":1}, {"id":2}]`)
}) })
comments, _, err := client.Repositories.ListCommitComments("o", "r", "s")
opt := &ListOptions{Page: 2}
comments, _, err := client.Repositories.ListCommitComments("o", "r", "s", opt)
if err != nil { if err != nil {
t.Errorf("Repositories.ListCommitComments returned error: %v", err) t.Errorf("Repositories.ListCommitComments returned error: %v", err)
} }
@ -59,7 +63,7 @@ func TestRepositoriesService_ListCommitComments(t *testing.T) {
} }
func TestRepositoriesService_ListCommitComments_invalidOwner(t *testing.T) { func TestRepositoriesService_ListCommitComments_invalidOwner(t *testing.T) {
_, _, err := client.Repositories.ListCommitComments("%", "%", "%")
_, _, err := client.Repositories.ListCommitComments("%", "%", "%", nil)
testURLParseError(t, err) testURLParseError(t, err)
} }


+ 5
- 1
github/repos_keys.go View File

@ -12,8 +12,12 @@ import "fmt"
// ListKeys lists the deploy keys for a repository. // ListKeys lists the deploy keys for a repository.
// //
// GitHub API docs: http://developer.github.com/v3/repos/keys/#list // GitHub API docs: http://developer.github.com/v3/repos/keys/#list
func (s *RepositoriesService) ListKeys(owner string, repo string) ([]Key, *Response, error) {
func (s *RepositoriesService) ListKeys(owner string, repo string, opt *ListOptions) ([]Key, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/keys", owner, repo) u := fmt.Sprintf("repos/%v/%v/keys", owner, repo)
u, err := addOptions(u, opt)
if err != nil {
return nil, nil, err
}
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
if err != nil { if err != nil {


+ 4
- 2
github/repos_keys_test.go View File

@ -19,10 +19,12 @@ func TestRepositoriesService_ListKeys(t *testing.T) {
mux.HandleFunc("/repos/o/r/keys", func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("/repos/o/r/keys", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET") testMethod(t, r, "GET")
testFormValues(t, r, values{"page": "2"})
fmt.Fprint(w, `[{"id":1}]`) fmt.Fprint(w, `[{"id":1}]`)
}) })
keys, _, err := client.Repositories.ListKeys("o", "r")
opt := &ListOptions{Page: 2}
keys, _, err := client.Repositories.ListKeys("o", "r", opt)
if err != nil { if err != nil {
t.Errorf("Repositories.ListKeys returned error: %v", err) t.Errorf("Repositories.ListKeys returned error: %v", err)
} }
@ -34,7 +36,7 @@ func TestRepositoriesService_ListKeys(t *testing.T) {
} }
func TestRepositoriesService_ListKeys_invalidOwner(t *testing.T) { func TestRepositoriesService_ListKeys_invalidOwner(t *testing.T) {
_, _, err := client.Repositories.ListKeys("%", "%")
_, _, err := client.Repositories.ListKeys("%", "%", nil)
testURLParseError(t, err) testURLParseError(t, err)
} }


+ 10
- 2
github/repos_releases.go View File

@ -55,8 +55,12 @@ func (r ReleaseAsset) String() string {
// ListReleases lists the releases for a repository. // ListReleases lists the releases for a repository.
// //
// GitHub API docs: http://developer.github.com/v3/repos/releases/#list-releases-for-a-repository // GitHub API docs: http://developer.github.com/v3/repos/releases/#list-releases-for-a-repository
func (s *RepositoriesService) ListReleases(owner, repo string) ([]RepositoryRelease, *Response, error) {
func (s *RepositoriesService) ListReleases(owner, repo string, opt *ListOptions) ([]RepositoryRelease, *Response, error) {
u := fmt.Sprintf("repos/%s/%s/releases", owner, repo) u := fmt.Sprintf("repos/%s/%s/releases", owner, repo)
u, err := addOptions(u, opt)
if err != nil {
return nil, nil, err
}
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
if err != nil { if err != nil {
@ -144,8 +148,12 @@ func (s *RepositoriesService) DeleteRelease(owner, repo string, id int) (*Respon
// ListReleaseAssets lists the release's assets. // ListReleaseAssets lists the release's assets.
// //
// GitHub API docs : http://developer.github.com/v3/repos/releases/#list-assets-for-a-release // GitHub API docs : http://developer.github.com/v3/repos/releases/#list-assets-for-a-release
func (s *RepositoriesService) ListReleaseAssets(owner, repo string, id int) ([]ReleaseAsset, *Response, error) {
func (s *RepositoriesService) ListReleaseAssets(owner, repo string, id int, opt *ListOptions) ([]ReleaseAsset, *Response, error) {
u := fmt.Sprintf("repos/%s/%s/releases/%d/assets", owner, repo, id) u := fmt.Sprintf("repos/%s/%s/releases/%d/assets", owner, repo, id)
u, err := addOptions(u, opt)
if err != nil {
return nil, nil, err
}
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
if err != nil { if err != nil {


+ 6
- 2
github/repos_releases_test.go View File

@ -20,10 +20,12 @@ func TestRepositoriesService_ListReleases(t *testing.T) {
mux.HandleFunc("/repos/o/r/releases", func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("/repos/o/r/releases", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET") testMethod(t, r, "GET")
testFormValues(t, r, values{"page": "2"})
fmt.Fprint(w, `[{"id":1}]`) fmt.Fprint(w, `[{"id":1}]`)
}) })
releases, _, err := client.Repositories.ListReleases("o", "r")
opt := &ListOptions{Page: 2}
releases, _, err := client.Repositories.ListReleases("o", "r", opt)
if err != nil { if err != nil {
t.Errorf("Repositories.ListReleases returned error: %v", err) t.Errorf("Repositories.ListReleases returned error: %v", err)
} }
@ -128,10 +130,12 @@ func TestRepositoriesService_ListReleaseAssets(t *testing.T) {
mux.HandleFunc("/repos/o/r/releases/1/assets", func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("/repos/o/r/releases/1/assets", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET") testMethod(t, r, "GET")
testFormValues(t, r, values{"page": "2"})
fmt.Fprint(w, `[{"id":1}]`) fmt.Fprint(w, `[{"id":1}]`)
}) })
assets, _, err := client.Repositories.ListReleaseAssets("o", "r", 1)
opt := &ListOptions{Page: 2}
assets, _, err := client.Repositories.ListReleaseAssets("o", "r", 1, opt)
if err != nil { if err != nil {
t.Errorf("Repositories.ListReleaseAssets returned error: %v", err) t.Errorf("Repositories.ListReleaseAssets returned error: %v", err)
} }


+ 6
- 1
github/repos_statuses.go View File

@ -41,8 +41,13 @@ func (r RepoStatus) String() string {
// reference. ref can be a SHA, a branch name, or a tag name. // reference. ref can be a SHA, a branch name, or a tag name.
// //
// GitHub API docs: http://developer.github.com/v3/repos/statuses/#list-statuses-for-a-specific-ref // GitHub API docs: http://developer.github.com/v3/repos/statuses/#list-statuses-for-a-specific-ref
func (s *RepositoriesService) ListStatuses(owner, repo, ref string) ([]RepoStatus, *Response, error) {
func (s *RepositoriesService) ListStatuses(owner, repo, ref string, opt *ListOptions) ([]RepoStatus, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/statuses/%v", owner, repo, ref) u := fmt.Sprintf("repos/%v/%v/statuses/%v", owner, repo, ref)
u, err := addOptions(u, opt)
if err != nil {
return nil, nil, err
}
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err


+ 4
- 2
github/repos_statuses_test.go View File

@ -19,10 +19,12 @@ func TestRepositoriesService_ListStatuses(t *testing.T) {
mux.HandleFunc("/repos/o/r/statuses/r", func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("/repos/o/r/statuses/r", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET") testMethod(t, r, "GET")
testFormValues(t, r, values{"page": "2"})
fmt.Fprint(w, `[{"id":1}]`) fmt.Fprint(w, `[{"id":1}]`)
}) })
statuses, _, err := client.Repositories.ListStatuses("o", "r", "r")
opt := &ListOptions{Page: 2}
statuses, _, err := client.Repositories.ListStatuses("o", "r", "r", opt)
if err != nil { if err != nil {
t.Errorf("Repositories.ListStatuses returned error: %v", err) t.Errorf("Repositories.ListStatuses returned error: %v", err)
} }
@ -34,7 +36,7 @@ func TestRepositoriesService_ListStatuses(t *testing.T) {
} }
func TestRepositoriesService_ListStatuses_invalidOwner(t *testing.T) { func TestRepositoriesService_ListStatuses_invalidOwner(t *testing.T) {
_, _, err := client.Repositories.ListStatuses("%", "r", "r")
_, _, err := client.Repositories.ListStatuses("%", "r", "r", nil)
testURLParseError(t, err) testURLParseError(t, err)
} }


+ 14
- 4
github/repos_test.go View File

@ -264,10 +264,14 @@ func TestRepositoriesService_ListContributors(t *testing.T) {
mux.HandleFunc("/repos/o/r/contributors", func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("/repos/o/r/contributors", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET") testMethod(t, r, "GET")
testFormValues(t, r, values{
"anon": "true",
"page": "2",
})
fmt.Fprint(w, `[{"contributions":42}]`) fmt.Fprint(w, `[{"contributions":42}]`)
}) })
opts := &ListContributorsOptions{Anon: "true"}
opts := &ListContributorsOptions{Anon: "true", ListOptions: ListOptions{Page: 2}}
contributors, _, err := client.Repositories.ListContributors("o", "r", opts) contributors, _, err := client.Repositories.ListContributors("o", "r", opts)
if err != nil { if err != nil {
@ -306,10 +310,12 @@ func TestRepositoriesService_ListTeams(t *testing.T) {
mux.HandleFunc("/repos/o/r/teams", func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("/repos/o/r/teams", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET") testMethod(t, r, "GET")
testFormValues(t, r, values{"page": "2"})
fmt.Fprint(w, `[{"id":1}]`) fmt.Fprint(w, `[{"id":1}]`)
}) })
teams, _, err := client.Repositories.ListTeams("o", "r")
opt := &ListOptions{Page: 2}
teams, _, err := client.Repositories.ListTeams("o", "r", opt)
if err != nil { if err != nil {
t.Errorf("Repositories.ListTeams returned error: %v", err) t.Errorf("Repositories.ListTeams returned error: %v", err)
} }
@ -326,10 +332,12 @@ func TestRepositoriesService_ListTags(t *testing.T) {
mux.HandleFunc("/repos/o/r/tags", func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("/repos/o/r/tags", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET") testMethod(t, r, "GET")
testFormValues(t, r, values{"page": "2"})
fmt.Fprint(w, `[{"name":"n", "commit" : {"sha" : "s", "url" : "u"}, "zipball_url": "z", "tarball_url": "t"}]`) fmt.Fprint(w, `[{"name":"n", "commit" : {"sha" : "s", "url" : "u"}, "zipball_url": "z", "tarball_url": "t"}]`)
}) })
tags, _, err := client.Repositories.ListTags("o", "r")
opt := &ListOptions{Page: 2}
tags, _, err := client.Repositories.ListTags("o", "r", opt)
if err != nil { if err != nil {
t.Errorf("Repositories.ListTags returned error: %v", err) t.Errorf("Repositories.ListTags returned error: %v", err)
} }
@ -356,10 +364,12 @@ func TestRepositoriesService_ListBranches(t *testing.T) {
mux.HandleFunc("/repos/o/r/branches", func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("/repos/o/r/branches", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET") testMethod(t, r, "GET")
testFormValues(t, r, values{"page": "2"})
fmt.Fprint(w, `[{"name":"master", "commit" : {"sha" : "a57781", "url" : "https://api.github.com/repos/o/r/commits/a57781"}}]`) fmt.Fprint(w, `[{"name":"master", "commit" : {"sha" : "a57781", "url" : "https://api.github.com/repos/o/r/commits/a57781"}}]`)
}) })
branches, _, err := client.Repositories.ListBranches("o", "r")
opt := &ListOptions{Page: 2}
branches, _, err := client.Repositories.ListBranches("o", "r", opt)
if err != nil { if err != nil {
t.Errorf("Repositories.ListBranches returned error: %v", err) t.Errorf("Repositories.ListBranches returned error: %v", err)
} }


+ 6
- 1
github/users_emails.go View File

@ -15,8 +15,13 @@ type UserEmail struct {
// ListEmails lists all email addresses for the authenticated user. // ListEmails lists all email addresses for the authenticated user.
// //
// GitHub API docs: http://developer.github.com/v3/users/emails/#list-email-addresses-for-a-user // GitHub API docs: http://developer.github.com/v3/users/emails/#list-email-addresses-for-a-user
func (s *UsersService) ListEmails() ([]UserEmail, *Response, error) {
func (s *UsersService) ListEmails(opt *ListOptions) ([]UserEmail, *Response, error) {
u := "user/emails" u := "user/emails"
u, err := addOptions(u, opt)
if err != nil {
return nil, nil, err
}
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err


+ 3
- 1
github/users_emails_test.go View File

@ -19,6 +19,7 @@ func TestUsersService_ListEmails(t *testing.T) {
mux.HandleFunc("/user/emails", func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("/user/emails", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET") testMethod(t, r, "GET")
testFormValues(t, r, values{"page": "2"})
fmt.Fprint(w, `[{ fmt.Fprint(w, `[{
"email": "user@example.com", "email": "user@example.com",
"verified": false, "verified": false,
@ -26,7 +27,8 @@ func TestUsersService_ListEmails(t *testing.T) {
}]`) }]`)
}) })
emails, _, err := client.Users.ListEmails()
opt := &ListOptions{Page: 2}
emails, _, err := client.Users.ListEmails(opt)
if err != nil { if err != nil {
t.Errorf("Users.ListEmails returned error: %v", err) t.Errorf("Users.ListEmails returned error: %v", err)
} }


+ 5
- 1
github/users_followers.go View File

@ -11,13 +11,17 @@ import "fmt"
// fetch followers for the authenticated user. // fetch followers for the authenticated user.
// //
// GitHub API docs: http://developer.github.com/v3/users/followers/#list-followers-of-a-user // GitHub API docs: http://developer.github.com/v3/users/followers/#list-followers-of-a-user
func (s *UsersService) ListFollowers(user string) ([]User, *Response, error) {
func (s *UsersService) ListFollowers(user string, opt *ListOptions) ([]User, *Response, error) {
var u string var u string
if user != "" { if user != "" {
u = fmt.Sprintf("users/%v/followers", user) u = fmt.Sprintf("users/%v/followers", user)
} else { } else {
u = "user/followers" u = "user/followers"
} }
u, err := addOptions(u, opt)
if err != nil {
return nil, nil, err
}
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
if err != nil { if err != nil {


+ 5
- 3
github/users_followers_test.go View File

@ -18,10 +18,12 @@ func TestUsersService_ListFollowers_authenticatedUser(t *testing.T) {
mux.HandleFunc("/user/followers", func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("/user/followers", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET") testMethod(t, r, "GET")
testFormValues(t, r, values{"page": "2"})
fmt.Fprint(w, `[{"id":1}]`) fmt.Fprint(w, `[{"id":1}]`)
}) })
users, _, err := client.Users.ListFollowers("")
opt := &ListOptions{Page: 2}
users, _, err := client.Users.ListFollowers("", opt)
if err != nil { if err != nil {
t.Errorf("Users.ListFollowers returned error: %v", err) t.Errorf("Users.ListFollowers returned error: %v", err)
} }
@ -41,7 +43,7 @@ func TestUsersService_ListFollowers_specifiedUser(t *testing.T) {
fmt.Fprint(w, `[{"id":1}]`) fmt.Fprint(w, `[{"id":1}]`)
}) })
users, _, err := client.Users.ListFollowers("u")
users, _, err := client.Users.ListFollowers("u", nil)
if err != nil { if err != nil {
t.Errorf("Users.ListFollowers returned error: %v", err) t.Errorf("Users.ListFollowers returned error: %v", err)
} }
@ -53,7 +55,7 @@ func TestUsersService_ListFollowers_specifiedUser(t *testing.T) {
} }
func TestUsersService_ListFollowers_invalidUser(t *testing.T) { func TestUsersService_ListFollowers_invalidUser(t *testing.T) {
_, _, err := client.Users.ListFollowers("%")
_, _, err := client.Users.ListFollowers("%", nil)
testURLParseError(t, err) testURLParseError(t, err)
} }


+ 5
- 1
github/users_keys.go View File

@ -23,13 +23,17 @@ func (k Key) String() string {
// string will fetch keys for the authenticated user. // string will fetch keys for the authenticated user.
// //
// GitHub API docs: http://developer.github.com/v3/users/keys/#list-public-keys-for-a-user // GitHub API docs: http://developer.github.com/v3/users/keys/#list-public-keys-for-a-user
func (s *UsersService) ListKeys(user string) ([]Key, *Response, error) {
func (s *UsersService) ListKeys(user string, opt *ListOptions) ([]Key, *Response, error) {
var u string var u string
if user != "" { if user != "" {
u = fmt.Sprintf("users/%v/keys", user) u = fmt.Sprintf("users/%v/keys", user)
} else { } else {
u = "user/keys" u = "user/keys"
} }
u, err := addOptions(u, opt)
if err != nil {
return nil, nil, err
}
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
if err != nil { if err != nil {


+ 5
- 3
github/users_keys_test.go View File

@ -19,10 +19,12 @@ func TestUsersService_ListKeys_authenticatedUser(t *testing.T) {
mux.HandleFunc("/user/keys", func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("/user/keys", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET") testMethod(t, r, "GET")
testFormValues(t, r, values{"page": "2"})
fmt.Fprint(w, `[{"id":1}]`) fmt.Fprint(w, `[{"id":1}]`)
}) })
keys, _, err := client.Users.ListKeys("")
opt := &ListOptions{Page: 2}
keys, _, err := client.Users.ListKeys("", opt)
if err != nil { if err != nil {
t.Errorf("Users.ListKeys returned error: %v", err) t.Errorf("Users.ListKeys returned error: %v", err)
} }
@ -42,7 +44,7 @@ func TestUsersService_ListKeys_specifiedUser(t *testing.T) {
fmt.Fprint(w, `[{"id":1}]`) fmt.Fprint(w, `[{"id":1}]`)
}) })
keys, _, err := client.Users.ListKeys("u")
keys, _, err := client.Users.ListKeys("u", nil)
if err != nil { if err != nil {
t.Errorf("Users.ListKeys returned error: %v", err) t.Errorf("Users.ListKeys returned error: %v", err)
} }
@ -54,7 +56,7 @@ func TestUsersService_ListKeys_specifiedUser(t *testing.T) {
} }
func TestUsersService_ListKeys_invalidUser(t *testing.T) { func TestUsersService_ListKeys_invalidUser(t *testing.T) {
_, _, err := client.Users.ListKeys("%")
_, _, err := client.Users.ListKeys("%", nil)
testURLParseError(t, err) testURLParseError(t, err)
} }


+ 2
- 2
tests/integration/repos_test.go View File

@ -71,7 +71,7 @@ func TestRepositories_CRUD(t *testing.T) {
func TestRepositories_BranchesTags(t *testing.T) { func TestRepositories_BranchesTags(t *testing.T) {
// branches // branches
branches, _, err := client.Repositories.ListBranches("git", "git")
branches, _, err := client.Repositories.ListBranches("git", "git", nil)
if err != nil { if err != nil {
t.Fatalf("Repositories.ListBranches() returned error: %v", err) t.Fatalf("Repositories.ListBranches() returned error: %v", err)
} }
@ -86,7 +86,7 @@ func TestRepositories_BranchesTags(t *testing.T) {
} }
// tags // tags
tags, _, err := client.Repositories.ListTags("git", "git")
tags, _, err := client.Repositories.ListTags("git", "git", nil)
if err != nil { if err != nil {
t.Fatalf("Repositories.ListTags() returned error: %v", err) t.Fatalf("Repositories.ListTags() returned error: %v", err)
} }


+ 7
- 7
tests/integration/users_test.go View File

@ -92,7 +92,7 @@ func TestUsers_Emails(t *testing.T) {
return return
} }
emails, _, err := client.Users.ListEmails()
emails, _, err := client.Users.ListEmails(nil)
if err != nil { if err != nil {
t.Fatalf("Users.ListEmails() returned error: %v", err) t.Fatalf("Users.ListEmails() returned error: %v", err)
} }
@ -117,7 +117,7 @@ EmailLoop:
} }
// List emails again and verify new email is present // List emails again and verify new email is present
emails, _, err = client.Users.ListEmails()
emails, _, err = client.Users.ListEmails(nil)
if err != nil { if err != nil {
t.Fatalf("Users.ListEmails() returned error: %v", err) t.Fatalf("Users.ListEmails() returned error: %v", err)
} }
@ -141,7 +141,7 @@ EmailLoop:
} }
// List emails again and verify new email was removed // List emails again and verify new email was removed
emails, _, err = client.Users.ListEmails()
emails, _, err = client.Users.ListEmails(nil)
if err != nil { if err != nil {
t.Fatalf("Users.ListEmails() returned error: %v", err) t.Fatalf("Users.ListEmails() returned error: %v", err)
} }
@ -154,7 +154,7 @@ EmailLoop:
} }
func TestUsers_Keys(t *testing.T) { func TestUsers_Keys(t *testing.T) {
keys, _, err := client.Users.ListKeys("willnorris")
keys, _, err := client.Users.ListKeys("willnorris", nil)
if err != nil { if err != nil {
t.Fatalf("Users.ListKeys('willnorris') returned error: %v", err) t.Fatalf("Users.ListKeys('willnorris') returned error: %v", err)
} }
@ -168,7 +168,7 @@ func TestUsers_Keys(t *testing.T) {
return return
} }
keys, _, err = client.Users.ListKeys("")
keys, _, err = client.Users.ListKeys("", nil)
if err != nil { if err != nil {
t.Fatalf("Users.ListKeys('') returned error: %v", err) t.Fatalf("Users.ListKeys('') returned error: %v", err)
} }
@ -191,7 +191,7 @@ func TestUsers_Keys(t *testing.T) {
} }
// List keys again and verify new key is present // List keys again and verify new key is present
keys, _, err = client.Users.ListKeys("")
keys, _, err = client.Users.ListKeys("", nil)
if err != nil { if err != nil {
t.Fatalf("Users.ListKeys('') returned error: %v", err) t.Fatalf("Users.ListKeys('') returned error: %v", err)
} }
@ -224,7 +224,7 @@ func TestUsers_Keys(t *testing.T) {
} }
// List keys again and verify test key was removed // List keys again and verify test key was removed
keys, _, err = client.Users.ListKeys("")
keys, _, err = client.Users.ListKeys("", nil)
if err != nil { if err != nil {
t.Fatalf("Users.ListKeys('') returned error: %v", err) t.Fatalf("Users.ListKeys('') returned error: %v", err)
} }


Loading…
Cancel
Save