From 7aa09725529963deb06ab96d29d8b690565db5d4 Mon Sep 17 00:00:00 2001 From: Will Norris Date: Thu, 17 Apr 2014 16:49:17 -0700 Subject: [PATCH] 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. :( --- github/gists_comments.go | 7 ++++++- github/gists_comments_test.go | 6 ++++-- github/git_refs.go | 7 +++++++ github/git_refs_test.go | 3 ++- github/issues_assignees.go | 7 ++++++- github/issues_assignees_test.go | 6 ++++-- github/issues_labels.go | 21 ++++++++++++++++++--- github/issues_labels_test.go | 18 ++++++++++++------ github/orgs_teams.go | 21 ++++++++++++++++++--- github/orgs_teams_test.go | 14 ++++++++++---- github/pulls.go | 16 ++++++++++++++-- github/pulls_test.go | 15 +++++++++------ github/repos.go | 24 ++++++++++++++++++++---- github/repos_collaborators.go | 7 ++++++- github/repos_collaborators_test.go | 6 ++++-- github/repos_comments.go | 14 ++++++++++++-- github/repos_comments_test.go | 12 ++++++++---- github/repos_keys.go | 6 +++++- github/repos_keys_test.go | 6 ++++-- github/repos_releases.go | 12 ++++++++++-- github/repos_releases_test.go | 8 ++++++-- github/repos_statuses.go | 7 ++++++- github/repos_statuses_test.go | 6 ++++-- github/repos_test.go | 18 ++++++++++++++---- github/users_emails.go | 7 ++++++- github/users_emails_test.go | 4 +++- github/users_followers.go | 6 +++++- github/users_followers_test.go | 8 +++++--- github/users_keys.go | 6 +++++- github/users_keys_test.go | 8 +++++--- tests/integration/repos_test.go | 4 ++-- tests/integration/users_test.go | 14 +++++++------- 32 files changed, 247 insertions(+), 77 deletions(-) diff --git a/github/gists_comments.go b/github/gists_comments.go index e700bbd..c5c21bd 100644 --- a/github/gists_comments.go +++ b/github/gists_comments.go @@ -26,8 +26,13 @@ func (g GistComment) String() string { // ListComments lists all comments for 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, err := addOptions(u, opt) + if err != nil { + return nil, nil, err + } + req, err := s.client.NewRequest("GET", u, nil) if err != nil { return nil, nil, err diff --git a/github/gists_comments_test.go b/github/gists_comments_test.go index a1040b2..b2bbf23 100644 --- a/github/gists_comments_test.go +++ b/github/gists_comments_test.go @@ -19,10 +19,12 @@ func TestGistsService_ListComments(t *testing.T) { mux.HandleFunc("/gists/1/comments", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") + testFormValues(t, r, values{"page": "2"}) 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 { 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) { - _, _, err := client.Gists.ListComments("%") + _, _, err := client.Gists.ListComments("%", nil) testURLParseError(t, err) } diff --git a/github/git_refs.go b/github/git_refs.go index 280464a..a0b4ce4 100644 --- a/github/git_refs.go +++ b/github/git_refs.go @@ -66,6 +66,8 @@ func (s *GitService) GetRef(owner string, repo string, ref string) (*Reference, // GitService.ListRefs method. type ReferenceListOptions struct { Type string `url:"-"` + + ListOptions } // ListRefs lists all refs in a repository. @@ -78,6 +80,11 @@ func (s *GitService) ListRefs(owner, repo string, opt *ReferenceListOptions) ([] } else { 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) if err != nil { return nil, nil, err diff --git a/github/git_refs_test.go b/github/git_refs_test.go index e158a34..e75092e 100644 --- a/github/git_refs_test.go +++ b/github/git_refs_test.go @@ -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) { testMethod(t, r, "GET") + testFormValues(t, r, values{"page": "2"}) 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) if err != nil { t.Errorf("Git.ListRefs returned error: %v", err) diff --git a/github/issues_assignees.go b/github/issues_assignees.go index a46d866..6338c22 100644 --- a/github/issues_assignees.go +++ b/github/issues_assignees.go @@ -11,8 +11,13 @@ import "fmt" // which issues may be assigned. // // 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, err := addOptions(u, opt) + if err != nil { + return nil, nil, err + } + req, err := s.client.NewRequest("GET", u, nil) if err != nil { return nil, nil, err diff --git a/github/issues_assignees_test.go b/github/issues_assignees_test.go index 9bcb86d..63e024d 100644 --- a/github/issues_assignees_test.go +++ b/github/issues_assignees_test.go @@ -18,10 +18,12 @@ func TestIssuesService_ListAssignees(t *testing.T) { mux.HandleFunc("/repos/o/r/assignees", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") + testFormValues(t, r, values{"page": "2"}) 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 { 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) { - _, _, err := client.Issues.ListAssignees("%", "r") + _, _, err := client.Issues.ListAssignees("%", "r", nil) testURLParseError(t, err) } diff --git a/github/issues_labels.go b/github/issues_labels.go index eb7b1b3..5ad25c1 100644 --- a/github/issues_labels.go +++ b/github/issues_labels.go @@ -21,8 +21,13 @@ func (l Label) String() string { // ListLabels lists all labels for a 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, err := addOptions(u, opt) + if err != nil { + return nil, nil, err + } + req, err := s.client.NewRequest("GET", u, nil) if err != nil { 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. // // 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, err := addOptions(u, opt) + if err != nil { + return nil, nil, err + } + req, err := s.client.NewRequest("GET", u, nil) if err != nil { 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. // // 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, err := addOptions(u, opt) + if err != nil { + return nil, nil, err + } + req, err := s.client.NewRequest("GET", u, nil) if err != nil { return nil, nil, err diff --git a/github/issues_labels_test.go b/github/issues_labels_test.go index 9d0a2cb..2243eb0 100644 --- a/github/issues_labels_test.go +++ b/github/issues_labels_test.go @@ -19,10 +19,12 @@ func TestIssuesService_ListLabels(t *testing.T) { mux.HandleFunc("/repos/o/r/labels", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") + testFormValues(t, r, values{"page": "2"}) 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 { 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) { - _, _, err := client.Issues.ListLabels("%", "%") + _, _, err := client.Issues.ListLabels("%", "%", nil) 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) { testMethod(t, r, "GET") + testFormValues(t, r, values{"page": "2"}) 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 { 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) { - _, _, err := client.Issues.ListLabelsByIssue("%", "%", 1) + _, _, err := client.Issues.ListLabelsByIssue("%", "%", 1, nil) 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) { testMethod(t, r, "GET") + testFormValues(t, r, values{"page": "2"}) 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 { 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) { - _, _, err := client.Issues.ListLabelsForMilestone("%", "%", 1) + _, _, err := client.Issues.ListLabelsForMilestone("%", "%", 1, nil) testURLParseError(t, err) } diff --git a/github/orgs_teams.go b/github/orgs_teams.go index 46c434b..dc64fa5 100644 --- a/github/orgs_teams.go +++ b/github/orgs_teams.go @@ -26,8 +26,13 @@ func (t Team) String() string { // ListTeams lists all of the teams for an organization. // // 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, err := addOptions(u, opt) + if err != nil { + return nil, nil, err + } + req, err := s.client.NewRequest("GET", u, nil) if err != nil { return nil, nil, err @@ -116,8 +121,13 @@ func (s *OrganizationsService) DeleteTeam(team int) (*Response, error) { // team. // // 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, err := addOptions(u, opt) + if err != nil { + return nil, nil, err + } + req, err := s.client.NewRequest("GET", u, nil) if err != nil { 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. // // 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, err := addOptions(u, opt) + if err != nil { + return nil, nil, err + } + req, err := s.client.NewRequest("GET", u, nil) if err != nil { return nil, nil, err diff --git a/github/orgs_teams_test.go b/github/orgs_teams_test.go index 7205ce5..c62aedc 100644 --- a/github/orgs_teams_test.go +++ b/github/orgs_teams_test.go @@ -19,10 +19,12 @@ func TestOrganizationsService_ListTeams(t *testing.T) { mux.HandleFunc("/orgs/o/teams", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") + testFormValues(t, r, values{"page": "2"}) 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 { 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) { - _, _, err := client.Organizations.ListTeams("%") + _, _, err := client.Organizations.ListTeams("%", nil) 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) { testMethod(t, r, "GET") + testFormValues(t, r, values{"page": "2"}) 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 { 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) { testMethod(t, r, "GET") + testFormValues(t, r, values{"page": "2"}) 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 { t.Errorf("Organizations.ListTeamRepos returned error: %v", err) } diff --git a/github/pulls.go b/github/pulls.go index b3d382a..3548852 100644 --- a/github/pulls.go +++ b/github/pulls.go @@ -60,6 +60,8 @@ type PullRequestListOptions struct { // Base filters pull requests by base branch name. Base string `url:"base,omitempty"` + + ListOptions } // 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. // // 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, err := addOptions(u, opt) + if err != nil { + return nil, nil, err + } + req, err := s.client.NewRequest("GET", u, nil) if err != nil { 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. // // 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, err := addOptions(u, opt) + if err != nil { + return nil, nil, err + } + req, err := s.client.NewRequest("GET", u, nil) if err != nil { return nil, nil, err diff --git a/github/pulls_test.go b/github/pulls_test.go index 041b392..681211e 100644 --- a/github/pulls_test.go +++ b/github/pulls_test.go @@ -23,11 +23,12 @@ func TestPullRequestsService_List(t *testing.T) { "state": "closed", "head": "h", "base": "b", + "page": "2", }) 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) 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) { testMethod(t, r, "GET") - + testFormValues(t, r, values{"page": "2"}) fmt.Fprint(w, ` [ { @@ -156,7 +157,7 @@ func TestPullRequestsService_ListCommits(t *testing.T) { } ] }, - { + { "sha": "2", "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 { 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) { testMethod(t, r, "GET") - + testFormValues(t, r, values{"page": "2"}) 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 { t.Errorf("PullRequests.ListFiles returned error: %v", err) } diff --git a/github/repos.go b/github/repos.go index 9c9fbf1..4a937ba 100644 --- a/github/repos.go +++ b/github/repos.go @@ -270,6 +270,8 @@ type Contributor struct { type ListContributorsOptions struct { // Include anonymous contributors in results or not Anon string `url:"anon,omitempty"` + + ListOptions } // ListContributors lists contributors for a repository. @@ -277,7 +279,6 @@ type ListContributorsOptions struct { // GitHub API docs: http://developer.github.com/v3/repos/#list-contributors func (s *RepositoriesService) ListContributors(owner string, repository string, opt *ListContributorsOptions) ([]Contributor, *Response, error) { u := fmt.Sprintf("repos/%v/%v/contributors", owner, repository) - u, err := addOptions(u, opt) if err != nil { 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. // // 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, err := addOptions(u, opt) + if err != nil { + return nil, nil, err + } + req, err := s.client.NewRequest("GET", u, nil) if err != nil { return nil, nil, err @@ -353,8 +359,13 @@ type RepositoryTag struct { // ListTags lists tags for the specified repository. // // 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, err := addOptions(u, opt) + if err != nil { + return nil, nil, err + } + req, err := s.client.NewRequest("GET", u, nil) if err != nil { return nil, nil, err @@ -378,8 +389,13 @@ type Branch struct { // ListBranches lists branches for the specified repository. // // 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, err := addOptions(u, opt) + if err != nil { + return nil, nil, err + } + req, err := s.client.NewRequest("GET", u, nil) if err != nil { return nil, nil, err diff --git a/github/repos_collaborators.go b/github/repos_collaborators.go index a84a92e..3ad6162 100644 --- a/github/repos_collaborators.go +++ b/github/repos_collaborators.go @@ -10,8 +10,13 @@ import "fmt" // ListCollaborators lists the Github users that have access to the repository. // // 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, err := addOptions(u, opt) + if err != nil { + return nil, nil, err + } + req, err := s.client.NewRequest("GET", u, nil) if err != nil { return nil, nil, err diff --git a/github/repos_collaborators_test.go b/github/repos_collaborators_test.go index 7556d18..de26ba9 100644 --- a/github/repos_collaborators_test.go +++ b/github/repos_collaborators_test.go @@ -18,10 +18,12 @@ func TestRepositoriesService_ListCollaborators(t *testing.T) { mux.HandleFunc("/repos/o/r/collaborators", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") + testFormValues(t, r, values{"page": "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 { 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) { - _, _, err := client.Repositories.ListCollaborators("%", "%") + _, _, err := client.Repositories.ListCollaborators("%", "%", nil) testURLParseError(t, err) } diff --git a/github/repos_comments.go b/github/repos_comments.go index 7b06cd9..2d090bb 100644 --- a/github/repos_comments.go +++ b/github/repos_comments.go @@ -34,8 +34,13 @@ func (r RepositoryComment) String() string { // ListComments lists all the comments for the 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, err := addOptions(u, opt) + if err != nil { + return nil, nil, err + } + req, err := s.client.NewRequest("GET", u, nil) if err != nil { 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. // // 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, err := addOptions(u, opt) + if err != nil { + return nil, nil, err + } + req, err := s.client.NewRequest("GET", u, nil) if err != nil { return nil, nil, err diff --git a/github/repos_comments_test.go b/github/repos_comments_test.go index 9bcd7a9..b5a8786 100644 --- a/github/repos_comments_test.go +++ b/github/repos_comments_test.go @@ -19,10 +19,12 @@ func TestRepositoriesService_ListComments(t *testing.T) { mux.HandleFunc("/repos/o/r/comments", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") + testFormValues(t, r, values{"page": "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 { 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) { - _, _, err := client.Repositories.ListComments("%", "%") + _, _, err := client.Repositories.ListComments("%", "%", nil) 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) { testMethod(t, r, "GET") + testFormValues(t, r, values{"page": "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 { 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) { - _, _, err := client.Repositories.ListCommitComments("%", "%", "%") + _, _, err := client.Repositories.ListCommitComments("%", "%", "%", nil) testURLParseError(t, err) } diff --git a/github/repos_keys.go b/github/repos_keys.go index abb1ca7..0d12ec9 100644 --- a/github/repos_keys.go +++ b/github/repos_keys.go @@ -12,8 +12,12 @@ import "fmt" // ListKeys lists the deploy keys for a repository. // // 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, err := addOptions(u, opt) + if err != nil { + return nil, nil, err + } req, err := s.client.NewRequest("GET", u, nil) if err != nil { diff --git a/github/repos_keys_test.go b/github/repos_keys_test.go index 8b5dab0..dcf6c55 100644 --- a/github/repos_keys_test.go +++ b/github/repos_keys_test.go @@ -19,10 +19,12 @@ func TestRepositoriesService_ListKeys(t *testing.T) { mux.HandleFunc("/repos/o/r/keys", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") + testFormValues(t, r, values{"page": "2"}) 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 { 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) { - _, _, err := client.Repositories.ListKeys("%", "%") + _, _, err := client.Repositories.ListKeys("%", "%", nil) testURLParseError(t, err) } diff --git a/github/repos_releases.go b/github/repos_releases.go index bfeafd8..09da650 100644 --- a/github/repos_releases.go +++ b/github/repos_releases.go @@ -55,8 +55,12 @@ func (r ReleaseAsset) String() string { // ListReleases lists the 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, err := addOptions(u, opt) + if err != nil { + return nil, nil, err + } req, err := s.client.NewRequest("GET", u, nil) if err != nil { @@ -144,8 +148,12 @@ func (s *RepositoriesService) DeleteRelease(owner, repo string, id int) (*Respon // ListReleaseAssets lists the release's assets. // // 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, err := addOptions(u, opt) + if err != nil { + return nil, nil, err + } req, err := s.client.NewRequest("GET", u, nil) if err != nil { diff --git a/github/repos_releases_test.go b/github/repos_releases_test.go index 56e97d4..17c6702 100644 --- a/github/repos_releases_test.go +++ b/github/repos_releases_test.go @@ -20,10 +20,12 @@ func TestRepositoriesService_ListReleases(t *testing.T) { mux.HandleFunc("/repos/o/r/releases", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") + testFormValues(t, r, values{"page": "2"}) 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 { 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) { testMethod(t, r, "GET") + testFormValues(t, r, values{"page": "2"}) 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 { t.Errorf("Repositories.ListReleaseAssets returned error: %v", err) } diff --git a/github/repos_statuses.go b/github/repos_statuses.go index 34bdea3..1fd55bc 100644 --- a/github/repos_statuses.go +++ b/github/repos_statuses.go @@ -41,8 +41,13 @@ func (r RepoStatus) String() string { // 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 -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, err := addOptions(u, opt) + if err != nil { + return nil, nil, err + } + req, err := s.client.NewRequest("GET", u, nil) if err != nil { return nil, nil, err diff --git a/github/repos_statuses_test.go b/github/repos_statuses_test.go index 8643e5b..ebce542 100644 --- a/github/repos_statuses_test.go +++ b/github/repos_statuses_test.go @@ -19,10 +19,12 @@ func TestRepositoriesService_ListStatuses(t *testing.T) { mux.HandleFunc("/repos/o/r/statuses/r", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") + testFormValues(t, r, values{"page": "2"}) 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 { 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) { - _, _, err := client.Repositories.ListStatuses("%", "r", "r") + _, _, err := client.Repositories.ListStatuses("%", "r", "r", nil) testURLParseError(t, err) } diff --git a/github/repos_test.go b/github/repos_test.go index 02b8351..def2119 100644 --- a/github/repos_test.go +++ b/github/repos_test.go @@ -264,10 +264,14 @@ func TestRepositoriesService_ListContributors(t *testing.T) { mux.HandleFunc("/repos/o/r/contributors", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") + testFormValues(t, r, values{ + "anon": "true", + "page": "2", + }) 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) 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) { testMethod(t, r, "GET") + testFormValues(t, r, values{"page": "2"}) 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 { 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) { 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"}]`) }) - tags, _, err := client.Repositories.ListTags("o", "r") + opt := &ListOptions{Page: 2} + tags, _, err := client.Repositories.ListTags("o", "r", opt) if err != nil { 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) { 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"}}]`) }) - branches, _, err := client.Repositories.ListBranches("o", "r") + opt := &ListOptions{Page: 2} + branches, _, err := client.Repositories.ListBranches("o", "r", opt) if err != nil { t.Errorf("Repositories.ListBranches returned error: %v", err) } diff --git a/github/users_emails.go b/github/users_emails.go index 051ed5e..7553191 100644 --- a/github/users_emails.go +++ b/github/users_emails.go @@ -15,8 +15,13 @@ type UserEmail struct { // 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 -func (s *UsersService) ListEmails() ([]UserEmail, *Response, error) { +func (s *UsersService) ListEmails(opt *ListOptions) ([]UserEmail, *Response, error) { u := "user/emails" + u, err := addOptions(u, opt) + if err != nil { + return nil, nil, err + } + req, err := s.client.NewRequest("GET", u, nil) if err != nil { return nil, nil, err diff --git a/github/users_emails_test.go b/github/users_emails_test.go index b3009c0..7eb6508 100644 --- a/github/users_emails_test.go +++ b/github/users_emails_test.go @@ -19,6 +19,7 @@ func TestUsersService_ListEmails(t *testing.T) { mux.HandleFunc("/user/emails", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") + testFormValues(t, r, values{"page": "2"}) fmt.Fprint(w, `[{ "email": "user@example.com", "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 { t.Errorf("Users.ListEmails returned error: %v", err) } diff --git a/github/users_followers.go b/github/users_followers.go index 13973a6..7ecbed9 100644 --- a/github/users_followers.go +++ b/github/users_followers.go @@ -11,13 +11,17 @@ import "fmt" // fetch followers for the authenticated 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 if user != "" { u = fmt.Sprintf("users/%v/followers", user) } else { u = "user/followers" } + u, err := addOptions(u, opt) + if err != nil { + return nil, nil, err + } req, err := s.client.NewRequest("GET", u, nil) if err != nil { diff --git a/github/users_followers_test.go b/github/users_followers_test.go index 988739d..f4d2457 100644 --- a/github/users_followers_test.go +++ b/github/users_followers_test.go @@ -18,10 +18,12 @@ func TestUsersService_ListFollowers_authenticatedUser(t *testing.T) { mux.HandleFunc("/user/followers", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") + testFormValues(t, r, values{"page": "2"}) fmt.Fprint(w, `[{"id":1}]`) }) - users, _, err := client.Users.ListFollowers("") + opt := &ListOptions{Page: 2} + users, _, err := client.Users.ListFollowers("", opt) if err != nil { t.Errorf("Users.ListFollowers returned error: %v", err) } @@ -41,7 +43,7 @@ func TestUsersService_ListFollowers_specifiedUser(t *testing.T) { fmt.Fprint(w, `[{"id":1}]`) }) - users, _, err := client.Users.ListFollowers("u") + users, _, err := client.Users.ListFollowers("u", nil) if err != nil { 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) { - _, _, err := client.Users.ListFollowers("%") + _, _, err := client.Users.ListFollowers("%", nil) testURLParseError(t, err) } diff --git a/github/users_keys.go b/github/users_keys.go index 6867453..dcbd773 100644 --- a/github/users_keys.go +++ b/github/users_keys.go @@ -23,13 +23,17 @@ func (k Key) String() string { // string will fetch keys for the authenticated 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 if user != "" { u = fmt.Sprintf("users/%v/keys", user) } else { u = "user/keys" } + u, err := addOptions(u, opt) + if err != nil { + return nil, nil, err + } req, err := s.client.NewRequest("GET", u, nil) if err != nil { diff --git a/github/users_keys_test.go b/github/users_keys_test.go index 794b064..e47afd7 100644 --- a/github/users_keys_test.go +++ b/github/users_keys_test.go @@ -19,10 +19,12 @@ func TestUsersService_ListKeys_authenticatedUser(t *testing.T) { mux.HandleFunc("/user/keys", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") + testFormValues(t, r, values{"page": "2"}) fmt.Fprint(w, `[{"id":1}]`) }) - keys, _, err := client.Users.ListKeys("") + opt := &ListOptions{Page: 2} + keys, _, err := client.Users.ListKeys("", opt) if err != nil { t.Errorf("Users.ListKeys returned error: %v", err) } @@ -42,7 +44,7 @@ func TestUsersService_ListKeys_specifiedUser(t *testing.T) { fmt.Fprint(w, `[{"id":1}]`) }) - keys, _, err := client.Users.ListKeys("u") + keys, _, err := client.Users.ListKeys("u", nil) if err != nil { 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) { - _, _, err := client.Users.ListKeys("%") + _, _, err := client.Users.ListKeys("%", nil) testURLParseError(t, err) } diff --git a/tests/integration/repos_test.go b/tests/integration/repos_test.go index 11c23f3..624d60b 100644 --- a/tests/integration/repos_test.go +++ b/tests/integration/repos_test.go @@ -71,7 +71,7 @@ func TestRepositories_CRUD(t *testing.T) { func TestRepositories_BranchesTags(t *testing.T) { // branches - branches, _, err := client.Repositories.ListBranches("git", "git") + branches, _, err := client.Repositories.ListBranches("git", "git", nil) if err != nil { t.Fatalf("Repositories.ListBranches() returned error: %v", err) } @@ -86,7 +86,7 @@ func TestRepositories_BranchesTags(t *testing.T) { } // tags - tags, _, err := client.Repositories.ListTags("git", "git") + tags, _, err := client.Repositories.ListTags("git", "git", nil) if err != nil { t.Fatalf("Repositories.ListTags() returned error: %v", err) } diff --git a/tests/integration/users_test.go b/tests/integration/users_test.go index d382257..f36628e 100644 --- a/tests/integration/users_test.go +++ b/tests/integration/users_test.go @@ -92,7 +92,7 @@ func TestUsers_Emails(t *testing.T) { return } - emails, _, err := client.Users.ListEmails() + emails, _, err := client.Users.ListEmails(nil) if err != nil { t.Fatalf("Users.ListEmails() returned error: %v", err) } @@ -117,7 +117,7 @@ EmailLoop: } // List emails again and verify new email is present - emails, _, err = client.Users.ListEmails() + emails, _, err = client.Users.ListEmails(nil) if err != nil { t.Fatalf("Users.ListEmails() returned error: %v", err) } @@ -141,7 +141,7 @@ EmailLoop: } // List emails again and verify new email was removed - emails, _, err = client.Users.ListEmails() + emails, _, err = client.Users.ListEmails(nil) if err != nil { t.Fatalf("Users.ListEmails() returned error: %v", err) } @@ -154,7 +154,7 @@ EmailLoop: } func TestUsers_Keys(t *testing.T) { - keys, _, err := client.Users.ListKeys("willnorris") + keys, _, err := client.Users.ListKeys("willnorris", nil) if err != nil { t.Fatalf("Users.ListKeys('willnorris') returned error: %v", err) } @@ -168,7 +168,7 @@ func TestUsers_Keys(t *testing.T) { return } - keys, _, err = client.Users.ListKeys("") + keys, _, err = client.Users.ListKeys("", nil) if err != nil { 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 - keys, _, err = client.Users.ListKeys("") + keys, _, err = client.Users.ListKeys("", nil) if err != nil { 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 - keys, _, err = client.Users.ListKeys("") + keys, _, err = client.Users.ListKeys("", nil) if err != nil { t.Fatalf("Users.ListKeys('') returned error: %v", err) }