Browse Source

use go-querystring to construct all request URLs

this is a breaking change for a handful of Option structs that were
defining the Page option directly (they now embed ListOptions).

finishes fixing #56
Will Norris 12 years ago
parent
commit
2ab27f559f
16 changed files with 122 additions and 234 deletions
  1. +25
    -45
      github/activity_events.go
  2. +8
    -16
      github/activity_star.go
  3. +1
    -1
      github/activity_star_test.go
  4. +10
    -22
      github/gists.go
  5. +14
    -24
      github/issues.go
  6. +6
    -14
      github/issues_comments.go
  7. +2
    -1
      github/issues_test.go
  8. +3
    -7
      github/orgs.go
  9. +6
    -11
      github/pulls.go
  10. +6
    -14
      github/pulls_comments.go
  11. +13
    -22
      github/repos_commits.go
  12. +9
    -16
      github/repos_forks.go
  13. +3
    -8
      github/repos_hooks.go
  14. +9
    -16
      github/search.go
  15. +4
    -9
      github/search_test.go
  16. +3
    -8
      github/users_followers.go

+ 25
- 45
github/activity_events.go View File

@ -8,8 +8,6 @@ package github
import (
"encoding/json"
"fmt"
"net/url"
"strconv"
"time"
)
@ -74,12 +72,9 @@ func (p PushEventCommit) String() string {
//
// GitHub API docs: http://developer.github.com/v3/activity/events/#list-public-events
func (s *ActivityService) ListEvents(opt *ListOptions) ([]Event, *Response, error) {
u := "events"
if opt != nil {
params := url.Values{
"page": []string{strconv.Itoa(opt.Page)},
}
u += "?" + params.Encode()
u, err := addOptions("events", opt)
if err != nil {
return nil, nil, err
}
req, err := s.client.NewRequest("GET", u, nil)
@ -101,11 +96,9 @@ func (s *ActivityService) ListEvents(opt *ListOptions) ([]Event, *Response, erro
// GitHub API docs: http://developer.github.com/v3/activity/events/#list-repository-events
func (s *ActivityService) ListRepositoryEvents(owner, repo string, opt *ListOptions) ([]Event, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/events", owner, repo)
if opt != nil {
params := url.Values{
"page": []string{strconv.Itoa(opt.Page)},
}
u += "?" + params.Encode()
u, err := addOptions(u, opt)
if err != nil {
return nil, nil, err
}
req, err := s.client.NewRequest("GET", u, nil)
@ -127,11 +120,9 @@ func (s *ActivityService) ListRepositoryEvents(owner, repo string, opt *ListOpti
// GitHub API docs: http://developer.github.com/v3/activity/events/#list-issue-events-for-a-repository
func (s *ActivityService) ListIssueEventsForRepository(owner, repo string, opt *ListOptions) ([]Event, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/issues/events", owner, repo)
if opt != nil {
params := url.Values{
"page": []string{strconv.Itoa(opt.Page)},
}
u += "?" + params.Encode()
u, err := addOptions(u, opt)
if err != nil {
return nil, nil, err
}
req, err := s.client.NewRequest("GET", u, nil)
@ -153,11 +144,9 @@ func (s *ActivityService) ListIssueEventsForRepository(owner, repo string, opt *
// GitHub API docs: http://developer.github.com/v3/activity/events/#list-public-events-for-a-network-of-repositories
func (s *ActivityService) ListEventsForRepoNetwork(owner, repo string, opt *ListOptions) ([]Event, *Response, error) {
u := fmt.Sprintf("networks/%v/%v/events", owner, repo)
if opt != nil {
params := url.Values{
"page": []string{strconv.Itoa(opt.Page)},
}
u += "?" + params.Encode()
u, err := addOptions(u, opt)
if err != nil {
return nil, nil, err
}
req, err := s.client.NewRequest("GET", u, nil)
@ -179,11 +168,9 @@ func (s *ActivityService) ListEventsForRepoNetwork(owner, repo string, opt *List
// GitHub API docs: http://developer.github.com/v3/activity/events/#list-public-events-for-an-organization
func (s *ActivityService) ListEventsForOrganization(org string, opt *ListOptions) ([]Event, *Response, error) {
u := fmt.Sprintf("orgs/%v/events", org)
if opt != nil {
params := url.Values{
"page": []string{strconv.Itoa(opt.Page)},
}
u += "?" + params.Encode()
u, err := addOptions(u, opt)
if err != nil {
return nil, nil, err
}
req, err := s.client.NewRequest("GET", u, nil)
@ -211,12 +198,9 @@ func (s *ActivityService) ListEventsPerformedByUser(user string, publicOnly bool
} else {
u = fmt.Sprintf("users/%v/events", user)
}
if opt != nil {
params := url.Values{
"page": []string{strconv.Itoa(opt.Page)},
}
u += "?" + params.Encode()
u, err := addOptions(u, opt)
if err != nil {
return nil, nil, err
}
req, err := s.client.NewRequest("GET", u, nil)
@ -244,12 +228,9 @@ func (s *ActivityService) ListEventsRecievedByUser(user string, publicOnly bool,
} else {
u = fmt.Sprintf("users/%v/received_events", user)
}
if opt != nil {
params := url.Values{
"page": []string{strconv.Itoa(opt.Page)},
}
u += "?" + params.Encode()
u, err := addOptions(u, opt)
if err != nil {
return nil, nil, err
}
req, err := s.client.NewRequest("GET", u, nil)
@ -272,12 +253,11 @@ func (s *ActivityService) ListEventsRecievedByUser(user string, publicOnly bool,
// GitHub API docs: http://developer.github.com/v3/activity/events/#list-events-for-an-organization
func (s *ActivityService) ListUserEventsForOrganization(org, user string, opt *ListOptions) ([]Event, *Response, error) {
u := fmt.Sprintf("users/%v/events/orgs/%v", user, org)
if opt != nil {
params := url.Values{
"page": []string{strconv.Itoa(opt.Page)},
}
u += "?" + params.Encode()
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


+ 8
- 16
github/activity_star.go View File

@ -5,25 +5,20 @@
package github
import (
"fmt"
"net/url"
"strconv"
)
import "fmt"
// ActivityListStarredOptions specifies the optional parameters to the
// ActivityService.ListStarred method.
type ActivityListStarredOptions struct {
// How to sort the repository list. Possible values are: created, updated,
// pushed, full_name. Default is "full_name".
Sort string
Sort string `url:"sort,omitempty"`
// Direction in which to sort repositories. Possible values are: asc, desc.
// Default is "asc" when sort is "full_name", otherwise default is "desc".
Direction string
Direction string `url:"direction,omitempty"`
// For paginated result sets, page of results to retrieve.
Page int
ListOptions
}
// ListStarred lists all the repos starred by a user. Passing the empty string
@ -37,14 +32,11 @@ func (s *ActivityService) ListStarred(user string, opt *ActivityListStarredOptio
} else {
u = "user/starred"
}
if opt != nil {
params := url.Values{
"sort": []string{opt.Sort},
"direction": []string{opt.Direction},
"page": []string{strconv.Itoa(opt.Page)},
}
u += "?" + params.Encode()
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


+ 1
- 1
github/activity_star_test.go View File

@ -46,7 +46,7 @@ func TestActivityService_ListStarred_specifiedUser(t *testing.T) {
fmt.Fprint(w, `[{"id":2}]`)
})
opt := &ActivityListStarredOptions{"created", "asc", 2}
opt := &ActivityListStarredOptions{"created", "asc", ListOptions{Page: 2}}
repos, _, err := client.Activity.ListStarred("u", opt)
if err != nil {
t.Errorf("Activity.ListStarred returned error: %v", err)


+ 10
- 22
github/gists.go View File

@ -7,7 +7,6 @@ package github
import (
"fmt"
"net/url"
"time"
)
@ -56,7 +55,7 @@ func (g GistFile) String() string {
// GistsService.List, GistsService.ListAll, and GistsService.ListStarred methods.
type GistListOptions struct {
// Since filters Gists by time.
Since time.Time
Since time.Time `url:"since,omitempty"`
}
// List gists for a user. Passing the empty string will list
@ -72,12 +71,9 @@ func (s *GistsService) List(user string, opt *GistListOptions) ([]Gist, *Respons
} else {
u = "gists"
}
if opt != nil {
params := url.Values{}
if !opt.Since.IsZero() {
params.Add("since", opt.Since.Format(time.RFC3339))
}
u += "?" + params.Encode()
u, err := addOptions(u, opt)
if err != nil {
return nil, nil, err
}
req, err := s.client.NewRequest("GET", u, nil)
@ -98,13 +94,9 @@ func (s *GistsService) List(user string, opt *GistListOptions) ([]Gist, *Respons
//
// GitHub API docs: http://developer.github.com/v3/gists/#list-gists
func (s *GistsService) ListAll(opt *GistListOptions) ([]Gist, *Response, error) {
u := "gists/public"
if opt != nil {
params := url.Values{}
if !opt.Since.IsZero() {
params.Add("since", opt.Since.Format(time.RFC3339))
}
u += "?" + params.Encode()
u, err := addOptions("gists/public", opt)
if err != nil {
return nil, nil, err
}
req, err := s.client.NewRequest("GET", u, nil)
@ -125,13 +117,9 @@ func (s *GistsService) ListAll(opt *GistListOptions) ([]Gist, *Response, error)
//
// GitHub API docs: http://developer.github.com/v3/gists/#list-gists
func (s *GistsService) ListStarred(opt *GistListOptions) ([]Gist, *Response, error) {
u := "gists/starred"
if opt != nil {
params := url.Values{}
if !opt.Since.IsZero() {
params.Add("since", opt.Since.Format(time.RFC3339))
}
u += "?" + params.Encode()
u, err := addOptions("gists/starred", opt)
if err != nil {
return nil, nil, err
}
req, err := s.client.NewRequest("GET", u, nil)


+ 14
- 24
github/issues.go View File

@ -7,9 +7,6 @@ package github
import (
"fmt"
"net/url"
"strconv"
"strings"
"time"
)
@ -47,28 +44,27 @@ func (i Issue) String() string {
type IssueListOptions struct {
// Filter specifies which issues to list. Possible values are: assigned,
// created, mentioned, subscribed, all. Default is "assigned".
Filter string
Filter string `url:"filter,omitempty"`
// State filters issues based on their state. Possible values are: open,
// closed. Default is "open".
State string
State string `url:"state,omitempty"`
// Labels filters issues based on their label.
Labels []string
Labels []string `url:"labels,comma,omitempty"`
// Sort specifies how to sort issues. Possible values are: created, updated,
// and comments. Default value is "assigned".
Sort string
Sort string `url:"sort,omitempty"`
// Direction in which to sort issues. Possible values are: asc, desc.
// Default is "asc".
Direction string
Direction string `url:"direction,omitempty"`
// Since filters issues by time.
Since time.Time
Since time.Time `url:"since,omitempty"`
// For paginated result sets, page of results to retrieve.
Page int
ListOptions
}
// List the issues for the authenticated user. If all is true, list issues
@ -97,19 +93,9 @@ func (s *IssuesService) ListByOrg(org string, opt *IssueListOptions) ([]Issue, *
}
func (s *IssuesService) listIssues(u string, opt *IssueListOptions) ([]Issue, *Response, error) {
if opt != nil {
params := url.Values{
"filter": {opt.Filter},
"state": {opt.State},
"labels": {strings.Join(opt.Labels, ",")},
"sort": {opt.Sort},
"direction": {opt.Direction},
"page": []string{strconv.Itoa(opt.Page)},
}
if !opt.Since.IsZero() {
params.Add("since", opt.Since.Format(time.RFC3339))
}
u += "?" + params.Encode()
u, err := addOptions(u, opt)
if err != nil {
return nil, nil, err
}
req, err := s.client.NewRequest("GET", u, nil)
@ -175,6 +161,7 @@ func (s *IssuesService) ListByRepo(owner string, repo string, opt *IssueListByRe
if err != nil {
return nil, nil, err
}
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
@ -198,6 +185,7 @@ func (s *IssuesService) Get(owner string, repo string, number int) (*Issue, *Res
if err != nil {
return nil, nil, err
}
issue := new(Issue)
resp, err := s.client.Do(req, issue)
if err != nil {
@ -216,6 +204,7 @@ func (s *IssuesService) Create(owner string, repo string, issue *Issue) (*Issue,
if err != nil {
return nil, nil, err
}
i := new(Issue)
resp, err := s.client.Do(req, i)
if err != nil {
@ -234,6 +223,7 @@ func (s *IssuesService) Edit(owner string, repo string, number int, issue *Issue
if err != nil {
return nil, nil, err
}
i := new(Issue)
resp, err := s.client.Do(req, i)
if err != nil {


+ 6
- 14
github/issues_comments.go View File

@ -7,7 +7,6 @@ package github
import (
"fmt"
"net/url"
"time"
)
@ -28,13 +27,13 @@ func (i IssueComment) String() string {
// IssuesService.ListComments method.
type IssueListCommentsOptions struct {
// Sort specifies how to sort comments. Possible values are: created, updated.
Sort string
Sort string `url:"sort,omitempty"`
// Direction in which to sort comments. Possible values are: asc, desc.
Direction string
Direction string `url:"direction,omitempty"`
// Since filters comments by time.
Since time.Time
Since time.Time `url:"since,omitempty"`
}
// ListComments lists all comments on the specified issue. Specifying an issue
@ -48,16 +47,9 @@ func (s *IssuesService) ListComments(owner string, repo string, number int, opt
} else {
u = fmt.Sprintf("repos/%v/%v/issues/%d/comments", owner, repo, number)
}
if opt != nil {
params := url.Values{
"sort": {opt.Sort},
"direction": {opt.Direction},
}
if !opt.Since.IsZero() {
params.Add("since", opt.Since.Format(time.RFC3339))
}
u += "?" + params.Encode()
u, err := addOptions(u, opt)
if err != nil {
return nil, nil, err
}
req, err := s.client.NewRequest("GET", u, nil)


+ 2
- 1
github/issues_test.go View File

@ -28,6 +28,7 @@ func TestIssuesService_List_all(t *testing.T) {
"direction": "asc",
"since": "2002-02-10T15:30:00Z",
"page": "1",
"per_page": "2",
})
fmt.Fprint(w, `[{"number":1}]`)
})
@ -35,7 +36,7 @@ func TestIssuesService_List_all(t *testing.T) {
opt := &IssueListOptions{
"all", "closed", []string{"a", "b"}, "updated", "asc",
time.Date(2002, time.February, 10, 15, 30, 0, 0, time.UTC),
1,
ListOptions{Page: 1, PerPage: 2},
}
issues, _, err := client.Issues.List(true, opt)


+ 3
- 7
github/orgs.go View File

@ -7,8 +7,6 @@ package github
import (
"fmt"
"net/url"
"strconv"
"time"
)
@ -72,11 +70,9 @@ func (s *OrganizationsService) List(user string, opt *ListOptions) ([]Organizati
} else {
u = "user/orgs"
}
if opt != nil {
params := url.Values{
"page": []string{strconv.Itoa(opt.Page)},
}
u += "?" + params.Encode()
u, err := addOptions(u, opt)
if err != nil {
return nil, nil, err
}
req, err := s.client.NewRequest("GET", u, nil)


+ 6
- 11
github/pulls.go View File

@ -7,7 +7,6 @@ package github
import (
"fmt"
"net/url"
"time"
)
@ -51,14 +50,14 @@ func (p PullRequest) String() string {
type PullRequestListOptions struct {
// State filters pull requests based on their state. Possible values are:
// open, closed. Default is "open".
State string
State string `url:"state,omitempty"`
// Head filters pull requests by head user and branch name in the format of:
// "user:ref-name".
Head string
Head string `url:"head,omitempty"`
// Base filters pull requests by base branch name.
Base string
Base string `url:"base,omitempty"`
}
// List the pull requests for the specified repository.
@ -66,13 +65,9 @@ type PullRequestListOptions struct {
// GitHub API docs: http://developer.github.com/v3/pulls/#list-pull-requests
func (s *PullRequestsService) List(owner string, repo string, opt *PullRequestListOptions) ([]PullRequest, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/pulls", owner, repo)
if opt != nil {
params := url.Values{
"state": {opt.State},
"head": {opt.Head},
"base": {opt.Base},
}
u += "?" + params.Encode()
u, err := addOptions(u, opt)
if err != nil {
return nil, nil, err
}
req, err := s.client.NewRequest("GET", u, nil)


+ 6
- 14
github/pulls_comments.go View File

@ -7,7 +7,6 @@ package github
import (
"fmt"
"net/url"
"time"
)
@ -31,13 +30,13 @@ func (p PullRequestComment) String() string {
// PullRequestsService.ListComments method.
type PullRequestListCommentsOptions struct {
// Sort specifies how to sort comments. Possible values are: created, updated.
Sort string
Sort string `url:"sort,omitempty"`
// Direction in which to sort comments. Possible values are: asc, desc.
Direction string
Direction string `url:"direction,omitempty"`
// Since filters comments by time.
Since time.Time
Since time.Time `url:"since,omitempty"`
}
// ListComments lists all comments on the specified pull request. Specifying a
@ -52,16 +51,9 @@ func (s *PullRequestsService) ListComments(owner string, repo string, number int
} else {
u = fmt.Sprintf("repos/%v/%v/pulls/%d/comments", owner, repo, number)
}
if opt != nil {
params := url.Values{
"sort": {opt.Sort},
"direction": {opt.Direction},
}
if !opt.Since.IsZero() {
params.Add("since", opt.Since.Format(time.RFC3339))
}
u += "?" + params.Encode()
u, err := addOptions(u, opt)
if err != nil {
return nil, nil, err
}
req, err := s.client.NewRequest("GET", u, nil)


+ 13
- 22
github/repos_commits.go View File

@ -7,7 +7,6 @@ package github
import (
"fmt"
"net/url"
"time"
)
@ -82,37 +81,29 @@ func (c CommitsComparison) String() string {
// RepositoriesService.ListCommits method.
type CommitsListOptions struct {
// SHA or branch to start listing Commits from.
SHA string
SHA string `url:"sha,omitempty"`
// Path that should be touched by the returned Commits.
Path string
Path string `url:"path,omitempty"`
// Author of by which to filter Commits.
Author string
Author string `url:"author,omitempty"`
// Since when should Commits be included in the response.
Since time.Time
Since time.Time `url:"since,omitempty"`
// Until when should Commits be included in the response.
Until time.Time
Until time.Time `url:"until,omitempty"`
}
// ListCommits lists the commits of a repository.
//
// GitHub API docs: http://developer.github.com/v3/repos/commits/#list
func (s *RepositoriesService) ListCommits(owner, repo string, opts *CommitsListOptions) ([]RepositoryCommit, *Response, error) {
func (s *RepositoriesService) ListCommits(owner, repo string, opt *CommitsListOptions) ([]RepositoryCommit, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/commits", owner, repo)
if opts != nil {
params := url.Values{
"sha": {opts.SHA},
"path": {opts.Path},
"author": {opts.Author},
}
if !opts.Since.IsZero() {
params.Add("since", opts.Since.Format(time.RFC3339))
}
if !opts.Until.IsZero() {
params.Add("until", opts.Until.Format(time.RFC3339))
}
u += "?" + params.Encode()
u, err := addOptions(u, opt)
if err != nil {
return nil, nil, err
}
req, err := s.client.NewRequest("GET", u, nil)


+ 9
- 16
github/repos_forks.go View File

@ -5,17 +5,14 @@
package github
import (
"fmt"
"net/url"
)
import "fmt"
// RepositoryListForksOptions specifies the optional parameters to the
// RepositoriesService.ListForks method.
type RepositoryListForksOptions struct {
// How to sort the forks list. Possible values are: newest, oldest,
// watchers. Default is "newest".
Sort string
Sort string `url:"sort,omitempty"`
}
// ListForks lists the forks of the specified repository.
@ -23,11 +20,9 @@ type RepositoryListForksOptions struct {
// GitHub API docs: http://developer.github.com/v3/repos/forks/#list-forks
func (s *RepositoriesService) ListForks(owner, repo string, opt *RepositoryListForksOptions) ([]Repository, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/forks", owner, repo)
if opt != nil {
params := url.Values{
"sort": []string{opt.Sort},
}
u += "?" + params.Encode()
u, err := addOptions(u, opt)
if err != nil {
return nil, nil, err
}
req, err := s.client.NewRequest("GET", u, nil)
@ -48,7 +43,7 @@ func (s *RepositoriesService) ListForks(owner, repo string, opt *RepositoryListF
// RepositoriesService.CreateFork method.
type RepositoryCreateForkOptions struct {
// The organization to fork the repository into.
Organization string
Organization string `url:"organization,omitempty"`
}
// CreateFork creates a fork of the specified repository.
@ -56,11 +51,9 @@ type RepositoryCreateForkOptions struct {
// GitHub API docs: http://developer.github.com/v3/repos/forks/#list-forks
func (s *RepositoriesService) CreateFork(owner, repo string, opt *RepositoryCreateForkOptions) (*Repository, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/forks", owner, repo)
if opt != nil {
params := url.Values{
"organization": []string{opt.Organization},
}
u += "?" + params.Encode()
u, err := addOptions(u, opt)
if err != nil {
return nil, nil, err
}
req, err := s.client.NewRequest("POST", u, nil)


+ 3
- 8
github/repos_hooks.go View File

@ -7,8 +7,6 @@ package github
import (
"fmt"
"net/url"
"strconv"
"time"
)
@ -107,12 +105,9 @@ func (s *RepositoriesService) CreateHook(owner, repo string, hook *Hook) (*Hook,
// GitHub API docs: http://developer.github.com/v3/repos/hooks/#list
func (s *RepositoriesService) ListHooks(owner, repo string, opt *ListOptions) ([]Hook, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/hooks", owner, repo)
if opt != nil {
params := url.Values{
"page": []string{strconv.Itoa(opt.Page)},
}
u += "?" + params.Encode()
u, err := addOptions(u, opt)
if err != nil {
return nil, nil, err
}
req, err := s.client.NewRequest("GET", u, nil)


+ 9
- 16
github/search.go View File

@ -7,8 +7,8 @@ package github
import (
"fmt"
"net/url"
"strconv"
qs "github.com/google/go-querystring/query"
)
// SearchService provides access to the search related functions
@ -28,18 +28,13 @@ type SearchOptions struct {
// - for users: followers, repositories, joined
//
// Default is to sort by best match.
Sort string
Sort string `url:"sort,omitempty"`
// Sort order if sort parameter is provided. Possible values are: asc,
// desc. Default is desc.
Order string
// Page of results to retrieve.
Page int
Order string `url:"order,omitempty"`
// Number of results to show per page. This can be up to 100
// according to GitHub.
PerPage int
ListOptions
}
// RepositoriesSearchResult represents the result of a repositories search.
@ -118,13 +113,11 @@ func (s *SearchService) Code(query string, opt *SearchOptions) (*CodeSearchResul
// Helper function that executes search queries against different
// GitHub search types (repositories, code, issues, users)
func (s *SearchService) search(searchType string, query string, opt *SearchOptions, result interface{}) (*Response, error) {
params := url.Values{"q": []string{query}}
if opt != nil {
params.Add("sort", opt.Sort)
params.Add("order", opt.Order)
params.Add("page", strconv.Itoa(opt.Page))
params.Add("per_page", strconv.Itoa(opt.PerPage))
params, err := qs.Values(opt)
if err != nil {
return nil, err
}
params.Add("q", query)
u := fmt.Sprintf("search/%s?%s", searchType, params.Encode())
req, err := s.client.NewRequest("GET", u, nil)


+ 4
- 9
github/search_test.go View File

@ -26,7 +26,7 @@ func TestSearchService_Repositories(t *testing.T) {
fmt.Fprint(w, `{"total_count": 4, "items": [{"id":1},{"id":2}]}`)
})
opts := &SearchOptions{Sort: "forks", Order: "desc", Page: 2, PerPage: 2}
opts := &SearchOptions{Sort: "forks", Order: "desc", ListOptions: ListOptions{Page: 2, PerPage: 2}}
result, _, err := client.Search.Repositories("blah", opts)
if err != nil {
t.Errorf("Search.Repositories returned error: %v", err)
@ -59,7 +59,7 @@ func TestSearchService_Issues(t *testing.T) {
fmt.Fprint(w, `{"total_count": 4, "items": [{"number":1},{"number":2}]}`)
})
opts := &SearchOptions{Sort: "forks", Order: "desc", Page: 2, PerPage: 2}
opts := &SearchOptions{Sort: "forks", Order: "desc", ListOptions: ListOptions{Page: 2, PerPage: 2}}
result, _, err := client.Search.Issues("blah", opts)
if err != nil {
t.Errorf("Search.Issues returned error: %v", err)
@ -92,7 +92,7 @@ func TestSearchService_Users(t *testing.T) {
fmt.Fprint(w, `{"total_count": 4, "items": [{"id":1},{"id":2}]}`)
})
opts := &SearchOptions{Sort: "forks", Order: "desc", Page: 2, PerPage: 2}
opts := &SearchOptions{Sort: "forks", Order: "desc", ListOptions: ListOptions{Page: 2, PerPage: 2}}
result, _, err := client.Search.Users("blah", opts)
if err != nil {
t.Errorf("Search.Issues returned error: %v", err)
@ -125,7 +125,7 @@ func TestSearchService_Code(t *testing.T) {
fmt.Fprint(w, `{"total_count": 4, "items": [{"name":"1"},{"name":"2"}]}`)
})
opts := &SearchOptions{Sort: "forks", Order: "desc", Page: 2, PerPage: 2}
opts := &SearchOptions{Sort: "forks", Order: "desc", ListOptions: ListOptions{Page: 2, PerPage: 2}}
result, _, err := client.Search.Code("blah", opts)
if err != nil {
t.Errorf("Search.Code returned error: %v", err)
@ -139,8 +139,3 @@ func TestSearchService_Code(t *testing.T) {
t.Errorf("Search.Code returned %+v, want %+v", result, want)
}
}
func TestSearchService_invalidQuery(t *testing.T) {
_, err := client.Search.search("%", "", nil, nil)
testURLParseError(t, err)
}

+ 3
- 8
github/users_followers.go View File

@ -6,8 +6,6 @@
package github
import "fmt"
import "net/url"
import "strconv"
// ListFollowers lists the followers for a user. Passing the empty string will
// fetch followers for the authenticated user.
@ -46,12 +44,9 @@ func (s *UsersService) ListFollowing(user string, opt *ListOptions) ([]User, *Re
} else {
u = "user/following"
}
if opt != nil {
params := url.Values{
"page": []string{strconv.Itoa(opt.Page)},
}
u += "?" + params.Encode()
u, err := addOptions(u, opt)
if err != nil {
return nil, nil, err
}
req, err := s.client.NewRequest("GET", u, nil)


Loading…
Cancel
Save