Browse Source

return Response object from all API functions

The truth is, this change makes me sad.  It's a breaking change
for all clients and it adds more complexity to the library surface.  In
most cases, clients will simply drop the Response object on the floor
(which is actually all the library itself was doing before this
change... now we're just pushing that off to the client).

Initially, the Response object will be primarily of interest for
functions that return paginated result sets, since the Response.NextPage
field is the only way to know for sure if there are more pages that
should be fetched.  And this is really the cleanest way to get at that
data, so in that respect this change isn't so bad.

It's also worth noting that returning the raw Response object makes a
lot more since in a GitHub library than it may in others, given how
GitHub makes liberal (read: proper) use of HTTP request and response
headers.  Other APIs, like Google's various APIs for example, tend to
push things like pagination links into the response body.  While this is
certainly less of a purist view in terms of REST, it does make the lives
of client developers a lot easier, since then the response body contains
everything you need to know.  But whatever; this is how GitHub rolls, so
we'll roll right along with them.  (Somewhat ironically we are ignoring
the RESTful links in the GitHub response bodies, since we're actually
calling the API in an RPC style and don't do anything with those links.)

We still don't have an easy way to set arbitrary request headers, but
that's a problem for another day.

Fixes #22
Will Norris 13 years ago
parent
commit
a51d6b4303
40 changed files with 494 additions and 512 deletions
  1. +4
    -4
      github/activity_events.go
  2. +2
    -2
      github/activity_events_test.go
  3. +4
    -4
      github/activity_star.go
  4. +2
    -2
      github/activity_star_test.go
  5. +42
    -44
      github/gists.go
  6. +13
    -13
      github/gists_test.go
  7. +8
    -8
      github/git_commits.go
  8. +2
    -2
      github/git_commits_test.go
  9. +9
    -11
      github/git_trees.go
  10. +2
    -2
      github/git_trees_test.go
  11. +5
    -5
      github/github.go
  12. +1
    -1
      github/github_test.go
  13. +22
    -22
      github/issues.go
  14. +10
    -11
      github/issues_assignees.go
  15. +6
    -6
      github/issues_assignees_test.go
  16. +19
    -20
      github/issues_comments.go
  17. +11
    -11
      github/issues_comments_test.go
  18. +12
    -12
      github/issues_test.go
  19. +12
    -12
      github/orgs.go
  20. +28
    -31
      github/orgs_members.go
  21. +14
    -14
      github/orgs_members_test.go
  22. +50
    -55
      github/orgs_teams.go
  23. +30
    -30
      github/orgs_teams_test.go
  24. +7
    -7
      github/orgs_test.go
  25. +16
    -16
      github/pulls.go
  26. +19
    -20
      github/pulls_comments.go
  27. +11
    -11
      github/pulls_comments_test.go
  28. +8
    -8
      github/pulls_test.go
  29. +28
    -28
      github/repos.go
  30. +8
    -8
      github/repos_forks.go
  31. +4
    -4
      github/repos_forks_test.go
  32. +22
    -24
      github/repos_hooks.go
  33. +6
    -6
      github/repos_hooks_test.go
  34. +8
    -8
      github/repos_statuses.go
  35. +4
    -4
      github/repos_statuses_test.go
  36. +14
    -14
      github/repos_test.go
  37. +12
    -12
      github/users.go
  38. +11
    -12
      github/users_emails.go
  39. +3
    -3
      github/users_emails_test.go
  40. +5
    -5
      github/users_test.go

+ 4
- 4
github/activity_events.go View File

@ -62,7 +62,7 @@ type PushEventCommit struct {
// true, only public events will be returned. // true, only public events will be returned.
// //
// GitHub API docs: http://developer.github.com/v3/activity/events/#list-events-performed-by-a-user // GitHub API docs: http://developer.github.com/v3/activity/events/#list-events-performed-by-a-user
func (s *ActivityService) ListEventsPerformedByUser(user string, publicOnly bool, opt *ListOptions) ([]Event, error) {
func (s *ActivityService) ListEventsPerformedByUser(user string, publicOnly bool, opt *ListOptions) ([]Event, *Response, error) {
var u string var u string
if publicOnly { if publicOnly {
u = fmt.Sprintf("users/%v/events/public", user) u = fmt.Sprintf("users/%v/events/public", user)
@ -79,10 +79,10 @@ func (s *ActivityService) ListEventsPerformedByUser(user string, publicOnly bool
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
if err != nil { if err != nil {
return nil, err
return nil, nil, err
} }
events := new([]Event) events := new([]Event)
_, err = s.client.Do(req, events)
return *events, err
resp, err := s.client.Do(req, events)
return *events, resp, err
} }

+ 2
- 2
github/activity_events_test.go View File

@ -26,7 +26,7 @@ func TestActivityService_ListEventsPerformedByUser_all(t *testing.T) {
}) })
opt := &ListOptions{Page: 2} opt := &ListOptions{Page: 2}
events, err := client.Activity.ListEventsPerformedByUser("u", false, opt)
events, _, err := client.Activity.ListEventsPerformedByUser("u", false, opt)
if err != nil { if err != nil {
t.Errorf("Events.ListPerformedByUser returned error: %v", err) t.Errorf("Events.ListPerformedByUser returned error: %v", err)
} }
@ -46,7 +46,7 @@ func TestActivityService_ListEventsPerformedByUser_publicOnly(t *testing.T) {
fmt.Fprint(w, `[{"id":"1"},{"id":"2"}]`) fmt.Fprint(w, `[{"id":"1"},{"id":"2"}]`)
}) })
events, err := client.Activity.ListEventsPerformedByUser("u", true, nil)
events, _, err := client.Activity.ListEventsPerformedByUser("u", true, nil)
if err != nil { if err != nil {
t.Errorf("Events.ListPerformedByUser returned error: %v", err) t.Errorf("Events.ListPerformedByUser returned error: %v", err)
} }


+ 4
- 4
github/activity_star.go View File

@ -30,7 +30,7 @@ type ActivityListStarredOptions struct {
// will list the starred repositories for the authenticated user. // will list the starred repositories for the authenticated user.
// //
// GitHub API docs: http://developer.github.com/v3/activity/starring/#list-repositories-being-starred // GitHub API docs: http://developer.github.com/v3/activity/starring/#list-repositories-being-starred
func (s *ActivityService) ListStarred(user string, opt *ActivityListStarredOptions) ([]Repository, error) {
func (s *ActivityService) ListStarred(user string, opt *ActivityListStarredOptions) ([]Repository, *Response, error) {
var u string var u string
if user != "" { if user != "" {
u = fmt.Sprintf("users/%v/starred", user) u = fmt.Sprintf("users/%v/starred", user)
@ -47,10 +47,10 @@ func (s *ActivityService) ListStarred(user string, opt *ActivityListStarredOptio
} }
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
if err != nil { if err != nil {
return nil, err
return nil, nil, err
} }
repos := new([]Repository) repos := new([]Repository)
_, err = s.client.Do(req, repos)
return *repos, err
resp, err := s.client.Do(req, repos)
return *repos, resp, err
} }

+ 2
- 2
github/activity_star_test.go View File

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


+ 42
- 44
github/gists.go View File

@ -57,7 +57,7 @@ type GistListOptions struct {
// user. // user.
// //
// GitHub API docs: http://developer.github.com/v3/gists/#list-gists // GitHub API docs: http://developer.github.com/v3/gists/#list-gists
func (s *GistsService) List(user string, opt *GistListOptions) ([]Gist, error) {
func (s *GistsService) List(user string, opt *GistListOptions) ([]Gist, *Response, error) {
var u string var u string
if user != "" { if user != "" {
u = fmt.Sprintf("users/%v/gists", user) u = fmt.Sprintf("users/%v/gists", user)
@ -74,18 +74,18 @@ func (s *GistsService) List(user string, opt *GistListOptions) ([]Gist, error) {
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
if err != nil { if err != nil {
return nil, err
return nil, nil, err
} }
gists := new([]Gist) gists := new([]Gist)
_, err = s.client.Do(req, gists)
return *gists, err
resp, err := s.client.Do(req, gists)
return *gists, resp, err
} }
// ListAll lists all public gists. // ListAll lists all public gists.
// //
// GitHub API docs: http://developer.github.com/v3/gists/#list-gists // GitHub API docs: http://developer.github.com/v3/gists/#list-gists
func (s *GistsService) ListAll(opt *GistListOptions) ([]Gist, error) {
func (s *GistsService) ListAll(opt *GistListOptions) ([]Gist, *Response, error) {
u := "gists/public" u := "gists/public"
if opt != nil { if opt != nil {
params := url.Values{} params := url.Values{}
@ -97,18 +97,18 @@ func (s *GistsService) ListAll(opt *GistListOptions) ([]Gist, error) {
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
if err != nil { if err != nil {
return nil, err
return nil, nil, err
} }
gists := new([]Gist) gists := new([]Gist)
_, err = s.client.Do(req, gists)
return *gists, err
resp, err := s.client.Do(req, gists)
return *gists, resp, err
} }
// ListStarred lists starred gists of authenticated user. // ListStarred lists starred gists of authenticated user.
// //
// GitHub API docs: http://developer.github.com/v3/gists/#list-gists // GitHub API docs: http://developer.github.com/v3/gists/#list-gists
func (s *GistsService) ListStarred(opt *GistListOptions) ([]Gist, error) {
func (s *GistsService) ListStarred(opt *GistListOptions) ([]Gist, *Response, error) {
u := "gists/starred" u := "gists/starred"
if opt != nil { if opt != nil {
params := url.Values{} params := url.Values{}
@ -120,118 +120,116 @@ func (s *GistsService) ListStarred(opt *GistListOptions) ([]Gist, error) {
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
if err != nil { if err != nil {
return nil, err
return nil, nil, err
} }
gists := new([]Gist) gists := new([]Gist)
_, err = s.client.Do(req, gists)
return *gists, err
resp, err := s.client.Do(req, gists)
return *gists, resp, err
} }
// Get a single gist. // Get a single gist.
// //
// GitHub API docs: http://developer.github.com/v3/gists/#get-a-single-gist // GitHub API docs: http://developer.github.com/v3/gists/#get-a-single-gist
func (s *GistsService) Get(id string) (*Gist, error) {
func (s *GistsService) Get(id string) (*Gist, *Response, error) {
u := fmt.Sprintf("gists/%v", id) u := fmt.Sprintf("gists/%v", id)
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
if err != nil { if err != nil {
return nil, err
return nil, nil, err
} }
gist := new(Gist) gist := new(Gist)
_, err = s.client.Do(req, gist)
return gist, err
resp, err := s.client.Do(req, gist)
return gist, resp, err
} }
// Create a gist for authenticated user. // Create a gist for authenticated user.
// //
// GitHub API docs: http://developer.github.com/v3/gists/#create-a-gist // GitHub API docs: http://developer.github.com/v3/gists/#create-a-gist
func (s *GistsService) Create(gist *Gist) (*Gist, error) {
func (s *GistsService) Create(gist *Gist) (*Gist, *Response, error) {
u := "gists" u := "gists"
req, err := s.client.NewRequest("POST", u, gist) req, err := s.client.NewRequest("POST", u, gist)
if err != nil { if err != nil {
return nil, err
return nil, nil, err
} }
g := new(Gist) g := new(Gist)
_, err = s.client.Do(req, g)
return g, err
resp, err := s.client.Do(req, g)
return g, resp, err
} }
// Edit a gist. // Edit a gist.
// //
// GitHub API docs: http://developer.github.com/v3/gists/#edit-a-gist // GitHub API docs: http://developer.github.com/v3/gists/#edit-a-gist
func (s *GistsService) Edit(id string, gist *Gist) (*Gist, error) {
func (s *GistsService) Edit(id string, gist *Gist) (*Gist, *Response, error) {
u := fmt.Sprintf("gists/%v", id) u := fmt.Sprintf("gists/%v", id)
req, err := s.client.NewRequest("PATCH", u, gist) req, err := s.client.NewRequest("PATCH", u, gist)
if err != nil { if err != nil {
return nil, err
return nil, nil, err
} }
g := new(Gist) g := new(Gist)
_, err = s.client.Do(req, g)
return g, err
resp, err := s.client.Do(req, g)
return g, resp, err
} }
// Delete a gist. // Delete a gist.
// //
// GitHub API docs: http://developer.github.com/v3/gists/#delete-a-gist // GitHub API docs: http://developer.github.com/v3/gists/#delete-a-gist
func (s *GistsService) Delete(id string) error {
func (s *GistsService) Delete(id string) (*Response, error) {
u := fmt.Sprintf("gists/%v", id) u := fmt.Sprintf("gists/%v", id)
req, err := s.client.NewRequest("DELETE", u, nil) req, err := s.client.NewRequest("DELETE", u, nil)
if err != nil { if err != nil {
return err
return nil, err
} }
_, err = s.client.Do(req, nil)
return err
return s.client.Do(req, nil)
} }
// Star a gist on behalf of authenticated user. // Star a gist on behalf of authenticated user.
// //
// GitHub API docs: http://developer.github.com/v3/gists/#star-a-gist // GitHub API docs: http://developer.github.com/v3/gists/#star-a-gist
func (s *GistsService) Star(id string) error {
func (s *GistsService) Star(id string) (*Response, error) {
u := fmt.Sprintf("gists/%v/star", id) u := fmt.Sprintf("gists/%v/star", id)
req, err := s.client.NewRequest("PUT", u, nil) req, err := s.client.NewRequest("PUT", u, nil)
if err != nil { if err != nil {
return err
return nil, err
} }
_, err = s.client.Do(req, nil)
return err
return s.client.Do(req, nil)
} }
// Unstar a gist on a behalf of authenticated user. // Unstar a gist on a behalf of authenticated user.
// //
// Github API docs: http://developer.github.com/v3/gists/#unstar-a-gist // Github API docs: http://developer.github.com/v3/gists/#unstar-a-gist
func (s *GistsService) Unstar(id string) error {
func (s *GistsService) Unstar(id string) (*Response, error) {
u := fmt.Sprintf("gists/%v/star", id) u := fmt.Sprintf("gists/%v/star", id)
req, err := s.client.NewRequest("DELETE", u, nil) req, err := s.client.NewRequest("DELETE", u, nil)
if err != nil { if err != nil {
return err
return nil, err
} }
_, err = s.client.Do(req, nil)
return err
return s.client.Do(req, nil)
} }
// Starred checks if a gist is starred by authenticated user. // Starred checks if a gist is starred by authenticated user.
// //
// GitHub API docs: http://developer.github.com/v3/gists/#check-if-a-gist-is-starred // GitHub API docs: http://developer.github.com/v3/gists/#check-if-a-gist-is-starred
func (s *GistsService) Starred(id string) (bool, error) {
func (s *GistsService) Starred(id string) (bool, *Response, error) {
u := fmt.Sprintf("gists/%v/star", id) u := fmt.Sprintf("gists/%v/star", id)
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
if err != nil { if err != nil {
return false, err
return false, nil, err
} }
_, err = s.client.Do(req, nil)
return parseBoolResponse(err)
resp, err := s.client.Do(req, nil)
starred, err := parseBoolResponse(err)
return starred, resp, err
} }
// Fork a gist. // Fork a gist.
// //
// GitHub API docs: http://developer.github.com/v3/gists/#fork-a-gist // GitHub API docs: http://developer.github.com/v3/gists/#fork-a-gist
func (s *GistsService) Fork(id string) (*Gist, error) {
func (s *GistsService) Fork(id string) (*Gist, *Response, error) {
u := fmt.Sprintf("gists/%v/forks", id) u := fmt.Sprintf("gists/%v/forks", id)
req, err := s.client.NewRequest("POST", u, nil) req, err := s.client.NewRequest("POST", u, nil)
if err != nil { if err != nil {
return nil, err
return nil, nil, err
} }
g := new(Gist) g := new(Gist)
_, err = s.client.Do(req, g)
return g, err
resp, err := s.client.Do(req, g)
return g, resp, err
} }

+ 13
- 13
github/gists_test.go View File

@ -29,7 +29,7 @@ func TestGistsService_List(t *testing.T) {
}) })
opt := &GistListOptions{Since: time.Date(2013, time.January, 1, 0, 0, 0, 0, time.UTC)} opt := &GistListOptions{Since: time.Date(2013, time.January, 1, 0, 0, 0, 0, time.UTC)}
gists, err := client.Gists.List("u", opt)
gists, _, err := client.Gists.List("u", opt)
if err != nil { if err != nil {
t.Errorf("Gists.List returned error: %v", err) t.Errorf("Gists.List returned error: %v", err)
@ -50,7 +50,7 @@ func TestGistsService_List_withEmptyUser(t *testing.T) {
fmt.Fprint(w, `[{"id": "1"}]`) fmt.Fprint(w, `[{"id": "1"}]`)
}) })
gists, err := client.Gists.List("", nil)
gists, _, err := client.Gists.List("", nil)
if err != nil { if err != nil {
t.Errorf("Gists.List returned error: %v", err) t.Errorf("Gists.List returned error: %v", err)
} }
@ -76,7 +76,7 @@ func TestGistsService_ListAll(t *testing.T) {
}) })
opt := &GistListOptions{Since: time.Date(2013, time.January, 1, 0, 0, 0, 0, time.UTC)} opt := &GistListOptions{Since: time.Date(2013, time.January, 1, 0, 0, 0, 0, time.UTC)}
gists, err := client.Gists.ListAll(opt)
gists, _, err := client.Gists.ListAll(opt)
if err != nil { if err != nil {
t.Errorf("Gists.ListAll returned error: %v", err) t.Errorf("Gists.ListAll returned error: %v", err)
@ -103,7 +103,7 @@ func TestGistsService_ListStarred(t *testing.T) {
}) })
opt := &GistListOptions{Since: time.Date(2013, time.January, 1, 0, 0, 0, 0, time.UTC)} opt := &GistListOptions{Since: time.Date(2013, time.January, 1, 0, 0, 0, 0, time.UTC)}
gists, err := client.Gists.ListStarred(opt)
gists, _, err := client.Gists.ListStarred(opt)
if err != nil { if err != nil {
t.Errorf("Gists.ListStarred returned error: %v", err) t.Errorf("Gists.ListStarred returned error: %v", err)
@ -124,7 +124,7 @@ func TestGistsService_Get(t *testing.T) {
fmt.Fprint(w, `{"id": "1"}`) fmt.Fprint(w, `{"id": "1"}`)
}) })
gist, err := client.Gists.Get("1")
gist, _, err := client.Gists.Get("1")
if err != nil { if err != nil {
t.Errorf("Gists.Get returned error: %v", err) t.Errorf("Gists.Get returned error: %v", err)
@ -171,7 +171,7 @@ func TestGistsService_Create(t *testing.T) {
}`) }`)
}) })
gist, err := client.Gists.Create(input)
gist, _, err := client.Gists.Create(input)
if err != nil { if err != nil {
t.Errorf("Gists.Create returned error: %v", err) t.Errorf("Gists.Create returned error: %v", err)
} }
@ -226,7 +226,7 @@ func TestGistsService_Edit(t *testing.T) {
}`) }`)
}) })
gist, err := client.Gists.Edit("1", input)
gist, _, err := client.Gists.Edit("1", input)
if err != nil { if err != nil {
t.Errorf("Gists.Edit returned error: %v", err) t.Errorf("Gists.Edit returned error: %v", err)
} }
@ -253,7 +253,7 @@ func TestGistsService_Delete(t *testing.T) {
testMethod(t, r, "DELETE") testMethod(t, r, "DELETE")
}) })
err := client.Gists.Delete("1")
_, err := client.Gists.Delete("1")
if err != nil { if err != nil {
t.Errorf("Gists.Delete returned error: %v", err) t.Errorf("Gists.Delete returned error: %v", err)
} }
@ -267,7 +267,7 @@ func TestGistsService_Star(t *testing.T) {
testMethod(t, r, "PUT") testMethod(t, r, "PUT")
}) })
err := client.Gists.Star("1")
_, err := client.Gists.Star("1")
if err != nil { if err != nil {
t.Errorf("Gists.Star returned error: %v", err) t.Errorf("Gists.Star returned error: %v", err)
} }
@ -281,7 +281,7 @@ func TestGistsService_Unstar(t *testing.T) {
testMethod(t, r, "DELETE") testMethod(t, r, "DELETE")
}) })
err := client.Gists.Unstar("1")
_, err := client.Gists.Unstar("1")
if err != nil { if err != nil {
t.Errorf("Gists.Unstar returned error: %v", err) t.Errorf("Gists.Unstar returned error: %v", err)
} }
@ -296,7 +296,7 @@ func TestGistsService_Starred_hasStar(t *testing.T) {
w.WriteHeader(http.StatusNoContent) w.WriteHeader(http.StatusNoContent)
}) })
star, err := client.Gists.Starred("1")
star, _, err := client.Gists.Starred("1")
if err != nil { if err != nil {
t.Errorf("Gists.Starred returned error: %v", err) t.Errorf("Gists.Starred returned error: %v", err)
} }
@ -314,7 +314,7 @@ func TestGistsService_Starred_noStar(t *testing.T) {
w.WriteHeader(http.StatusNotFound) w.WriteHeader(http.StatusNotFound)
}) })
star, err := client.Gists.Starred("1")
star, _, err := client.Gists.Starred("1")
if err != nil { if err != nil {
t.Errorf("Gists.Starred returned error: %v", err) t.Errorf("Gists.Starred returned error: %v", err)
} }
@ -332,7 +332,7 @@ func TestGistsService_Fork(t *testing.T) {
fmt.Fprint(w, `{"id": "2"}`) fmt.Fprint(w, `{"id": "2"}`)
}) })
gist, err := client.Gists.Fork("1")
gist, _, err := client.Gists.Fork("1")
if err != nil { if err != nil {
t.Errorf("Gists.Fork returned error: %v", err) t.Errorf("Gists.Fork returned error: %v", err)


+ 8
- 8
github/git_commits.go View File

@ -31,16 +31,16 @@ type CommitAuthor struct {
// GetCommit fetchs the Commit object for a given SHA. // GetCommit fetchs the Commit object for a given SHA.
// //
// GitHub API docs: http://developer.github.com/v3/git/commits/#get-a-commit // GitHub API docs: http://developer.github.com/v3/git/commits/#get-a-commit
func (s *GitService) GetCommit(owner string, repo string, sha string) (*Commit, error) {
func (s *GitService) GetCommit(owner string, repo string, sha string) (*Commit, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/git/commits/%v", owner, repo, sha) u := fmt.Sprintf("repos/%v/%v/git/commits/%v", owner, repo, sha)
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
if err != nil { if err != nil {
return nil, err
return nil, nil, err
} }
c := new(Commit) c := new(Commit)
_, err = s.client.Do(req, c)
return c, err
resp, err := s.client.Do(req, c)
return c, resp, err
} }
// CreateCommit creates a new commit in a repository. // CreateCommit creates a new commit in a repository.
@ -50,14 +50,14 @@ func (s *GitService) GetCommit(owner string, repo string, sha string) (*Commit,
// the authenticated user’s information and the current date. // the authenticated user’s information and the current date.
// //
// GitHub API docs: http://developer.github.com/v3/git/commits/#create-a-commit // GitHub API docs: http://developer.github.com/v3/git/commits/#create-a-commit
func (s *GitService) CreateCommit(owner string, repo string, commit *Commit) (*Commit, error) {
func (s *GitService) CreateCommit(owner string, repo string, commit *Commit) (*Commit, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/git/commits", owner, repo) u := fmt.Sprintf("repos/%v/%v/git/commits", owner, repo)
req, err := s.client.NewRequest("POST", u, commit) req, err := s.client.NewRequest("POST", u, commit)
if err != nil { if err != nil {
return nil, err
return nil, nil, err
} }
c := new(Commit) c := new(Commit)
_, err = s.client.Do(req, c)
return c, err
resp, err := s.client.Do(req, c)
return c, resp, err
} }

+ 2
- 2
github/git_commits_test.go View File

@ -22,7 +22,7 @@ func TestGitService_GetCommit(t *testing.T) {
fmt.Fprint(w, `{"sha":"s","message":"m","author":{"name":"n"}}`) fmt.Fprint(w, `{"sha":"s","message":"m","author":{"name":"n"}}`)
}) })
commit, err := client.Git.GetCommit("o", "r", "s")
commit, _, err := client.Git.GetCommit("o", "r", "s")
if err != nil { if err != nil {
t.Errorf("Git.GetCommit returned error: %v", err) t.Errorf("Git.GetCommit returned error: %v", err)
} }
@ -50,7 +50,7 @@ func TestGitService_CreateCommit(t *testing.T) {
fmt.Fprint(w, `{"sha":"s"}`) fmt.Fprint(w, `{"sha":"s"}`)
}) })
commit, err := client.Git.CreateCommit("o", "r", input)
commit, _, err := client.Git.CreateCommit("o", "r", input)
if err != nil { if err != nil {
t.Errorf("Git.CreateCommit returned error: %v", err) t.Errorf("Git.CreateCommit returned error: %v", err)
} }


+ 9
- 11
github/git_trees.go View File

@ -5,9 +5,7 @@
package github package github
import (
"fmt"
)
import "fmt"
// Tree represents a GitHub tree. // Tree represents a GitHub tree.
type Tree struct { type Tree struct {
@ -29,7 +27,7 @@ type TreeEntry struct {
// GetTree fetches the Tree object for a given sha hash from a repository. // GetTree fetches the Tree object for a given sha hash from a repository.
// //
// GitHub API docs: http://developer.github.com/v3/git/trees/#get-a-tree // GitHub API docs: http://developer.github.com/v3/git/trees/#get-a-tree
func (s *GitService) GetTree(owner string, repo string, sha string, recursive bool) (*Tree, error) {
func (s *GitService) GetTree(owner string, repo string, sha string, recursive bool) (*Tree, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/git/trees/%v", owner, repo, sha) u := fmt.Sprintf("repos/%v/%v/git/trees/%v", owner, repo, sha)
if recursive { if recursive {
u += "?recursive=1" u += "?recursive=1"
@ -37,12 +35,12 @@ func (s *GitService) GetTree(owner string, repo string, sha string, recursive bo
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
if err != nil { if err != nil {
return nil, err
return nil, nil, err
} }
t := new(Tree) t := new(Tree)
_, err = s.client.Do(req, t)
return t, err
resp, err := s.client.Do(req, t)
return t, resp, err
} }
// createTree represents the body of a CreateTree request. // createTree represents the body of a CreateTree request.
@ -56,7 +54,7 @@ type createTree struct {
// that tree with the new path contents and write a new tree out. // that tree with the new path contents and write a new tree out.
// //
// GitHub API docs: http://developer.github.com/v3/git/trees/#create-a-tree // GitHub API docs: http://developer.github.com/v3/git/trees/#create-a-tree
func (s *GitService) CreateTree(owner string, repo string, baseTree string, entries []TreeEntry) (*Tree, error) {
func (s *GitService) CreateTree(owner string, repo string, baseTree string, entries []TreeEntry) (*Tree, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/git/trees", owner, repo) u := fmt.Sprintf("repos/%v/%v/git/trees", owner, repo)
body := &createTree{ body := &createTree{
@ -65,10 +63,10 @@ func (s *GitService) CreateTree(owner string, repo string, baseTree string, entr
} }
req, err := s.client.NewRequest("POST", u, body) req, err := s.client.NewRequest("POST", u, body)
if err != nil { if err != nil {
return nil, err
return nil, nil, err
} }
t := new(Tree) t := new(Tree)
_, err = s.client.Do(req, t)
return t, err
resp, err := s.client.Do(req, t)
return t, resp, err
} }

+ 2
- 2
github/git_trees_test.go View File

@ -27,7 +27,7 @@ func TestGitService_GetTree(t *testing.T) {
}`) }`)
}) })
tree, err := client.Git.GetTree("o", "r", "s", true)
tree, _, err := client.Git.GetTree("o", "r", "s", true)
if err != nil { if err != nil {
t.Errorf("Git.GetTree returned error: %v", err) t.Errorf("Git.GetTree returned error: %v", err)
} }
@ -88,7 +88,7 @@ func TestGitService_CreateTree(t *testing.T) {
}`) }`)
}) })
tree, err := client.Git.CreateTree("o", "r", "b", input)
tree, _, err := client.Git.CreateTree("o", "r", "b", input)
if err != nil { if err != nil {
t.Errorf("Git.CreateTree returned error: %v", err) t.Errorf("Git.CreateTree returned error: %v", err)
} }


+ 5
- 5
github/github.go View File

@ -374,16 +374,16 @@ type Rate struct {
} }
// RateLimit returns the rate limit for the current client. // RateLimit returns the rate limit for the current client.
func (c *Client) RateLimit() (*Rate, error) {
func (c *Client) RateLimit() (*Rate, *Response, error) {
req, err := c.NewRequest("GET", "rate_limit", nil) req, err := c.NewRequest("GET", "rate_limit", nil)
if err != nil { if err != nil {
return nil, err
return nil, nil, err
} }
response := new(rateResponse) response := new(rateResponse)
_, err = c.Do(req, response)
resp, err := c.Do(req, response)
if err != nil { if err != nil {
return nil, err
return nil, nil, err
} }
rate := &Rate{ rate := &Rate{
@ -391,7 +391,7 @@ func (c *Client) RateLimit() (*Rate, error) {
Remaining: response.Rate.Remaining, Remaining: response.Rate.Remaining,
Reset: time.Unix(response.Rate.Reset, 0), Reset: time.Unix(response.Rate.Reset, 0),
} }
return rate, err
return rate, resp, err
} }
/* /*


+ 1
- 1
github/github_test.go View File

@ -420,7 +420,7 @@ func TestRateLimit(t *testing.T) {
fmt.Fprint(w, `{"rate":{"limit":2,"remaining":1,"reset":1372700873}}`) fmt.Fprint(w, `{"rate":{"limit":2,"remaining":1,"reset":1372700873}}`)
}) })
rate, err := client.RateLimit()
rate, _, err := client.RateLimit()
if err != nil { if err != nil {
t.Errorf("Rate limit returned error: %v", err) t.Errorf("Rate limit returned error: %v", err)
} }


+ 22
- 22
github/issues.go View File

@ -72,7 +72,7 @@ type IssueListOptions struct {
// repositories. // repositories.
// //
// GitHub API docs: http://developer.github.com/v3/issues/#list-issues // GitHub API docs: http://developer.github.com/v3/issues/#list-issues
func (s *IssuesService) List(all bool, opt *IssueListOptions) ([]Issue, error) {
func (s *IssuesService) List(all bool, opt *IssueListOptions) ([]Issue, *Response, error) {
var u string var u string
if all { if all {
u = "issues" u = "issues"
@ -86,12 +86,12 @@ func (s *IssuesService) List(all bool, opt *IssueListOptions) ([]Issue, error) {
// authenticated user. // authenticated user.
// //
// GitHub API docs: http://developer.github.com/v3/issues/#list-issues // GitHub API docs: http://developer.github.com/v3/issues/#list-issues
func (s *IssuesService) ListByOrg(org string, opt *IssueListOptions) ([]Issue, error) {
func (s *IssuesService) ListByOrg(org string, opt *IssueListOptions) ([]Issue, *Response, error) {
u := fmt.Sprintf("orgs/%v/issues", org) u := fmt.Sprintf("orgs/%v/issues", org)
return s.listIssues(u, opt) return s.listIssues(u, opt)
} }
func (s *IssuesService) listIssues(u string, opt *IssueListOptions) ([]Issue, error) {
func (s *IssuesService) listIssues(u string, opt *IssueListOptions) ([]Issue, *Response, error) {
if opt != nil { if opt != nil {
params := url.Values{ params := url.Values{
"filter": {opt.Filter}, "filter": {opt.Filter},
@ -109,12 +109,12 @@ func (s *IssuesService) listIssues(u string, opt *IssueListOptions) ([]Issue, er
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
if err != nil { if err != nil {
return nil, err
return nil, nil, err
} }
issues := new([]Issue) issues := new([]Issue)
_, err = s.client.Do(req, issues)
return *issues, err
resp, err := s.client.Do(req, issues)
return *issues, resp, err
} }
// IssueListByRepoOptions specifies the optional parameters to the // IssueListByRepoOptions specifies the optional parameters to the
@ -158,7 +158,7 @@ type IssueListByRepoOptions struct {
// ListByRepo lists the issues for the specified repository. // ListByRepo lists the issues for the specified repository.
// //
// GitHub API docs: http://developer.github.com/v3/issues/#list-issues-for-a-repository // GitHub API docs: http://developer.github.com/v3/issues/#list-issues-for-a-repository
func (s *IssuesService) ListByRepo(owner string, repo string, opt *IssueListByRepoOptions) ([]Issue, error) {
func (s *IssuesService) ListByRepo(owner string, repo string, opt *IssueListByRepoOptions) ([]Issue, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/issues", owner, repo) u := fmt.Sprintf("repos/%v/%v/issues", owner, repo)
if opt != nil { if opt != nil {
params := url.Values{ params := url.Values{
@ -179,52 +179,52 @@ func (s *IssuesService) ListByRepo(owner string, repo string, opt *IssueListByRe
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
if err != nil { if err != nil {
return nil, err
return nil, nil, err
} }
issues := new([]Issue) issues := new([]Issue)
_, err = s.client.Do(req, issues)
return *issues, err
resp, err := s.client.Do(req, issues)
return *issues, resp, err
} }
// Get a single issue. // Get a single issue.
// //
// GitHub API docs: http://developer.github.com/v3/issues/#get-a-single-issue // GitHub API docs: http://developer.github.com/v3/issues/#get-a-single-issue
func (s *IssuesService) Get(owner string, repo string, number int) (*Issue, error) {
func (s *IssuesService) Get(owner string, repo string, number int) (*Issue, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/issues/%d", owner, repo, number) u := fmt.Sprintf("repos/%v/%v/issues/%d", owner, repo, number)
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
if err != nil { if err != nil {
return nil, err
return nil, nil, err
} }
issue := new(Issue) issue := new(Issue)
_, err = s.client.Do(req, issue)
return issue, err
resp, err := s.client.Do(req, issue)
return issue, resp, err
} }
// Create a new issue on the specified repository. // Create a new issue on the specified repository.
// //
// GitHub API docs: http://developer.github.com/v3/issues/#create-an-issue // GitHub API docs: http://developer.github.com/v3/issues/#create-an-issue
func (s *IssuesService) Create(owner string, repo string, issue *Issue) (*Issue, error) {
func (s *IssuesService) Create(owner string, repo string, issue *Issue) (*Issue, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/issues", owner, repo) u := fmt.Sprintf("repos/%v/%v/issues", owner, repo)
req, err := s.client.NewRequest("POST", u, issue) req, err := s.client.NewRequest("POST", u, issue)
if err != nil { if err != nil {
return nil, err
return nil, nil, err
} }
i := new(Issue) i := new(Issue)
_, err = s.client.Do(req, i)
return i, err
resp, err := s.client.Do(req, i)
return i, resp, err
} }
// Edit an issue. // Edit an issue.
// //
// GitHub API docs: http://developer.github.com/v3/issues/#edit-an-issue // GitHub API docs: http://developer.github.com/v3/issues/#edit-an-issue
func (s *IssuesService) Edit(owner string, repo string, number int, issue *Issue) (*Issue, error) {
func (s *IssuesService) Edit(owner string, repo string, number int, issue *Issue) (*Issue, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/issues/%d", owner, repo, number) u := fmt.Sprintf("repos/%v/%v/issues/%d", owner, repo, number)
req, err := s.client.NewRequest("PATCH", u, issue) req, err := s.client.NewRequest("PATCH", u, issue)
if err != nil { if err != nil {
return nil, err
return nil, nil, err
} }
i := new(Issue) i := new(Issue)
_, err = s.client.Do(req, i)
return i, err
resp, err := s.client.Do(req, i)
return i, resp, err
} }

+ 10
- 11
github/issues_assignees.go View File

@ -5,34 +5,33 @@
package github package github
import (
"fmt"
)
import "fmt"
// ListAssignees fetches all available assignees (owners and collaborators) to // ListAssignees fetches all available assignees (owners and collaborators) to
// 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, error) {
func (s *IssuesService) ListAssignees(owner string, repo string) ([]User, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/assignees", owner, repo) u := fmt.Sprintf("repos/%v/%v/assignees", owner, repo)
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
if err != nil { if err != nil {
return nil, err
return nil, nil, err
} }
assignees := new([]User) assignees := new([]User)
_, err = s.client.Do(req, assignees)
return *assignees, err
resp, err := s.client.Do(req, assignees)
return *assignees, resp, err
} }
// CheckAssignee checks if a user is an assignee for the specified repository. // CheckAssignee checks if a user is an assignee for the specified repository.
// //
// GitHub API docs: http://developer.github.com/v3/issues/assignees/#check-assignee // GitHub API docs: http://developer.github.com/v3/issues/assignees/#check-assignee
func (s *IssuesService) CheckAssignee(owner string, repo string, user string) (bool, error) {
func (s *IssuesService) CheckAssignee(owner string, repo string, user string) (bool, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/assignees/%v", owner, repo, user) u := fmt.Sprintf("repos/%v/%v/assignees/%v", owner, repo, user)
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
if err != nil { if err != nil {
return false, err
return false, nil, err
} }
_, err = s.client.Do(req, nil)
return parseBoolResponse(err)
resp, err := s.client.Do(req, nil)
assignee, err := parseBoolResponse(err)
return assignee, resp, err
} }

+ 6
- 6
github/issues_assignees_test.go View File

@ -21,7 +21,7 @@ func TestIssuesService_ListAssignees(t *testing.T) {
fmt.Fprint(w, `[{"id":1}]`) fmt.Fprint(w, `[{"id":1}]`)
}) })
assignees, err := client.Issues.ListAssignees("o", "r")
assignees, _, err := client.Issues.ListAssignees("o", "r")
if err != nil { if err != nil {
t.Errorf("Issues.List returned error: %v", err) t.Errorf("Issues.List returned error: %v", err)
} }
@ -33,7 +33,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")
testURLParseError(t, err) testURLParseError(t, err)
} }
@ -45,7 +45,7 @@ func TestIssuesService_CheckAssignee_true(t *testing.T) {
testMethod(t, r, "GET") testMethod(t, r, "GET")
}) })
assignee, err := client.Issues.CheckAssignee("o", "r", "u")
assignee, _, err := client.Issues.CheckAssignee("o", "r", "u")
if err != nil { if err != nil {
t.Errorf("Issues.CheckAssignee returned error: %v", err) t.Errorf("Issues.CheckAssignee returned error: %v", err)
} }
@ -63,7 +63,7 @@ func TestIssuesService_CheckAssignee_false(t *testing.T) {
w.WriteHeader(http.StatusNotFound) w.WriteHeader(http.StatusNotFound)
}) })
assignee, err := client.Issues.CheckAssignee("o", "r", "u")
assignee, _, err := client.Issues.CheckAssignee("o", "r", "u")
if err != nil { if err != nil {
t.Errorf("Issues.CheckAssignee returned error: %v", err) t.Errorf("Issues.CheckAssignee returned error: %v", err)
} }
@ -81,7 +81,7 @@ func TestIssuesService_CheckAssignee_error(t *testing.T) {
http.Error(w, "BadRequest", http.StatusBadRequest) http.Error(w, "BadRequest", http.StatusBadRequest)
}) })
assignee, err := client.Issues.CheckAssignee("o", "r", "u")
assignee, _, err := client.Issues.CheckAssignee("o", "r", "u")
if err == nil { if err == nil {
t.Errorf("Expected HTTP 400 response") t.Errorf("Expected HTTP 400 response")
} }
@ -91,6 +91,6 @@ func TestIssuesService_CheckAssignee_error(t *testing.T) {
} }
func TestIssuesService_CheckAssignee_invalidOwner(t *testing.T) { func TestIssuesService_CheckAssignee_invalidOwner(t *testing.T) {
_, err := client.Issues.CheckAssignee("%", "r", "u")
_, _, err := client.Issues.CheckAssignee("%", "r", "u")
testURLParseError(t, err) testURLParseError(t, err)
} }

+ 19
- 20
github/issues_comments.go View File

@ -37,7 +37,7 @@ type IssueListCommentsOptions struct {
// number of 0 will return all comments on all issues for the repository. // number of 0 will return all comments on all issues for the repository.
// //
// GitHub API docs: http://developer.github.com/v3/issues/comments/#list-comments-on-an-issue // GitHub API docs: http://developer.github.com/v3/issues/comments/#list-comments-on-an-issue
func (s *IssuesService) ListComments(owner string, repo string, number int, opt *IssueListCommentsOptions) ([]IssueComment, error) {
func (s *IssuesService) ListComments(owner string, repo string, number int, opt *IssueListCommentsOptions) ([]IssueComment, *Response, error) {
var u string var u string
if number == 0 { if number == 0 {
u = fmt.Sprintf("repos/%v/%v/issues/comments", owner, repo) u = fmt.Sprintf("repos/%v/%v/issues/comments", owner, repo)
@ -58,65 +58,64 @@ func (s *IssuesService) ListComments(owner string, repo string, number int, opt
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
if err != nil { if err != nil {
return nil, err
return nil, nil, err
} }
comments := new([]IssueComment) comments := new([]IssueComment)
_, err = s.client.Do(req, comments)
return *comments, err
resp, err := s.client.Do(req, comments)
return *comments, resp, err
} }
// GetComment fetches the specified issue comment. // GetComment fetches the specified issue comment.
// //
// GitHub API docs: http://developer.github.com/v3/issues/comments/#get-a-single-comment // GitHub API docs: http://developer.github.com/v3/issues/comments/#get-a-single-comment
func (s *IssuesService) GetComment(owner string, repo string, id int) (*IssueComment, error) {
func (s *IssuesService) GetComment(owner string, repo string, id int) (*IssueComment, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/issues/comments/%d", owner, repo, id) u := fmt.Sprintf("repos/%v/%v/issues/comments/%d", owner, repo, id)
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
if err != nil { if err != nil {
return nil, err
return nil, nil, err
} }
comment := new(IssueComment) comment := new(IssueComment)
_, err = s.client.Do(req, comment)
return comment, err
resp, err := s.client.Do(req, comment)
return comment, resp, err
} }
// CreateComment creates a new comment on the specified issue. // CreateComment creates a new comment on the specified issue.
// //
// GitHub API docs: http://developer.github.com/v3/issues/comments/#create-a-comment // GitHub API docs: http://developer.github.com/v3/issues/comments/#create-a-comment
func (s *IssuesService) CreateComment(owner string, repo string, number int, comment *IssueComment) (*IssueComment, error) {
func (s *IssuesService) CreateComment(owner string, repo string, number int, comment *IssueComment) (*IssueComment, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/issues/%d/comments", owner, repo, number) u := fmt.Sprintf("repos/%v/%v/issues/%d/comments", owner, repo, number)
req, err := s.client.NewRequest("POST", u, comment) req, err := s.client.NewRequest("POST", u, comment)
if err != nil { if err != nil {
return nil, err
return nil, nil, err
} }
c := new(IssueComment) c := new(IssueComment)
_, err = s.client.Do(req, c)
return c, err
resp, err := s.client.Do(req, c)
return c, resp, err
} }
// EditComment updates an issue comment. // EditComment updates an issue comment.
// //
// GitHub API docs: http://developer.github.com/v3/issues/comments/#edit-a-comment // GitHub API docs: http://developer.github.com/v3/issues/comments/#edit-a-comment
func (s *IssuesService) EditComment(owner string, repo string, id int, comment *IssueComment) (*IssueComment, error) {
func (s *IssuesService) EditComment(owner string, repo string, id int, comment *IssueComment) (*IssueComment, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/issues/comments/%d", owner, repo, id) u := fmt.Sprintf("repos/%v/%v/issues/comments/%d", owner, repo, id)
req, err := s.client.NewRequest("PATCH", u, comment) req, err := s.client.NewRequest("PATCH", u, comment)
if err != nil { if err != nil {
return nil, err
return nil, nil, err
} }
c := new(IssueComment) c := new(IssueComment)
_, err = s.client.Do(req, c)
return c, err
resp, err := s.client.Do(req, c)
return c, resp, err
} }
// DeleteComment deletes an issue comment. // DeleteComment deletes an issue comment.
// //
// GitHub API docs: http://developer.github.com/v3/issues/comments/#delete-a-comment // GitHub API docs: http://developer.github.com/v3/issues/comments/#delete-a-comment
func (s *IssuesService) DeleteComment(owner string, repo string, id int) error {
func (s *IssuesService) DeleteComment(owner string, repo string, id int) (*Response, error) {
u := fmt.Sprintf("repos/%v/%v/issues/comments/%d", owner, repo, id) u := fmt.Sprintf("repos/%v/%v/issues/comments/%d", owner, repo, id)
req, err := s.client.NewRequest("DELETE", u, nil) req, err := s.client.NewRequest("DELETE", u, nil)
if err != nil { if err != nil {
return err
return nil, err
} }
_, err = s.client.Do(req, nil)
return err
return s.client.Do(req, nil)
} }

+ 11
- 11
github/issues_comments_test.go View File

@ -31,7 +31,7 @@ func TestIssuesService_ListComments_allIssues(t *testing.T) {
opt := &IssueListCommentsOptions{"updated", "desc", opt := &IssueListCommentsOptions{"updated", "desc",
time.Date(2002, time.February, 10, 15, 30, 0, 0, time.UTC), time.Date(2002, time.February, 10, 15, 30, 0, 0, time.UTC),
} }
comments, err := client.Issues.ListComments("o", "r", 0, opt)
comments, _, err := client.Issues.ListComments("o", "r", 0, opt)
if err != nil { if err != nil {
t.Errorf("Issues.ListComments returned error: %v", err) t.Errorf("Issues.ListComments returned error: %v", err)
} }
@ -51,7 +51,7 @@ func TestIssuesService_ListComments_specificIssue(t *testing.T) {
fmt.Fprint(w, `[{"id":1}]`) fmt.Fprint(w, `[{"id":1}]`)
}) })
comments, err := client.Issues.ListComments("o", "r", 1, nil)
comments, _, err := client.Issues.ListComments("o", "r", 1, nil)
if err != nil { if err != nil {
t.Errorf("Issues.ListComments returned error: %v", err) t.Errorf("Issues.ListComments returned error: %v", err)
} }
@ -63,7 +63,7 @@ func TestIssuesService_ListComments_specificIssue(t *testing.T) {
} }
func TestIssuesService_ListComments_invalidOwner(t *testing.T) { func TestIssuesService_ListComments_invalidOwner(t *testing.T) {
_, err := client.Issues.ListComments("%", "r", 1, nil)
_, _, err := client.Issues.ListComments("%", "r", 1, nil)
testURLParseError(t, err) testURLParseError(t, err)
} }
@ -76,7 +76,7 @@ func TestIssuesService_GetComment(t *testing.T) {
fmt.Fprint(w, `{"id":1}`) fmt.Fprint(w, `{"id":1}`)
}) })
comment, err := client.Issues.GetComment("o", "r", 1)
comment, _, err := client.Issues.GetComment("o", "r", 1)
if err != nil { if err != nil {
t.Errorf("Issues.GetComment returned error: %v", err) t.Errorf("Issues.GetComment returned error: %v", err)
} }
@ -88,7 +88,7 @@ func TestIssuesService_GetComment(t *testing.T) {
} }
func TestIssuesService_GetComment_invalidOrg(t *testing.T) { func TestIssuesService_GetComment_invalidOrg(t *testing.T) {
_, err := client.Issues.GetComment("%", "r", 1)
_, _, err := client.Issues.GetComment("%", "r", 1)
testURLParseError(t, err) testURLParseError(t, err)
} }
@ -110,7 +110,7 @@ func TestIssuesService_CreateComment(t *testing.T) {
fmt.Fprint(w, `{"id":1}`) fmt.Fprint(w, `{"id":1}`)
}) })
comment, err := client.Issues.CreateComment("o", "r", 1, input)
comment, _, err := client.Issues.CreateComment("o", "r", 1, input)
if err != nil { if err != nil {
t.Errorf("Issues.CreateComment returned error: %v", err) t.Errorf("Issues.CreateComment returned error: %v", err)
} }
@ -122,7 +122,7 @@ func TestIssuesService_CreateComment(t *testing.T) {
} }
func TestIssuesService_CreateComment_invalidOrg(t *testing.T) { func TestIssuesService_CreateComment_invalidOrg(t *testing.T) {
_, err := client.Issues.CreateComment("%", "r", 1, nil)
_, _, err := client.Issues.CreateComment("%", "r", 1, nil)
testURLParseError(t, err) testURLParseError(t, err)
} }
@ -144,7 +144,7 @@ func TestIssuesService_EditComment(t *testing.T) {
fmt.Fprint(w, `{"id":1}`) fmt.Fprint(w, `{"id":1}`)
}) })
comment, err := client.Issues.EditComment("o", "r", 1, input)
comment, _, err := client.Issues.EditComment("o", "r", 1, input)
if err != nil { if err != nil {
t.Errorf("Issues.EditComment returned error: %v", err) t.Errorf("Issues.EditComment returned error: %v", err)
} }
@ -156,7 +156,7 @@ func TestIssuesService_EditComment(t *testing.T) {
} }
func TestIssuesService_EditComment_invalidOwner(t *testing.T) { func TestIssuesService_EditComment_invalidOwner(t *testing.T) {
_, err := client.Issues.EditComment("%", "r", 1, nil)
_, _, err := client.Issues.EditComment("%", "r", 1, nil)
testURLParseError(t, err) testURLParseError(t, err)
} }
@ -168,13 +168,13 @@ func TestIssuesService_DeleteComment(t *testing.T) {
testMethod(t, r, "DELETE") testMethod(t, r, "DELETE")
}) })
err := client.Issues.DeleteComment("o", "r", 1)
_, err := client.Issues.DeleteComment("o", "r", 1)
if err != nil { if err != nil {
t.Errorf("Issues.DeleteComments returned error: %v", err) t.Errorf("Issues.DeleteComments returned error: %v", err)
} }
} }
func TestIssuesService_DeleteComment_invalidOwner(t *testing.T) { func TestIssuesService_DeleteComment_invalidOwner(t *testing.T) {
err := client.Issues.DeleteComment("%", "r", 1)
_, err := client.Issues.DeleteComment("%", "r", 1)
testURLParseError(t, err) testURLParseError(t, err)
} }

+ 12
- 12
github/issues_test.go View File

@ -37,7 +37,7 @@ func TestIssuesService_List_all(t *testing.T) {
time.Date(2002, time.February, 10, 15, 30, 0, 0, time.UTC), time.Date(2002, time.February, 10, 15, 30, 0, 0, time.UTC),
1, 1,
} }
issues, err := client.Issues.List(true, opt)
issues, _, err := client.Issues.List(true, opt)
if err != nil { if err != nil {
t.Errorf("Issues.List returned error: %v", err) t.Errorf("Issues.List returned error: %v", err)
@ -58,7 +58,7 @@ func TestIssuesService_List_owned(t *testing.T) {
fmt.Fprint(w, `[{"number":1}]`) fmt.Fprint(w, `[{"number":1}]`)
}) })
issues, err := client.Issues.List(false, nil)
issues, _, err := client.Issues.List(false, nil)
if err != nil { if err != nil {
t.Errorf("Issues.List returned error: %v", err) t.Errorf("Issues.List returned error: %v", err)
} }
@ -78,7 +78,7 @@ func TestIssuesService_ListByOrg(t *testing.T) {
fmt.Fprint(w, `[{"number":1}]`) fmt.Fprint(w, `[{"number":1}]`)
}) })
issues, err := client.Issues.ListByOrg("o", nil)
issues, _, err := client.Issues.ListByOrg("o", nil)
if err != nil { if err != nil {
t.Errorf("Issues.ListByOrg returned error: %v", err) t.Errorf("Issues.ListByOrg returned error: %v", err)
} }
@ -90,7 +90,7 @@ func TestIssuesService_ListByOrg(t *testing.T) {
} }
func TestIssuesService_ListByOrg_invalidOrg(t *testing.T) { func TestIssuesService_ListByOrg_invalidOrg(t *testing.T) {
_, err := client.Issues.ListByOrg("%", nil)
_, _, err := client.Issues.ListByOrg("%", nil)
testURLParseError(t, err) testURLParseError(t, err)
} }
@ -118,7 +118,7 @@ func TestIssuesService_ListByRepo(t *testing.T) {
"*", "closed", "a", "c", "m", []string{"a", "b"}, "updated", "asc", "*", "closed", "a", "c", "m", []string{"a", "b"}, "updated", "asc",
time.Date(2002, time.February, 10, 15, 30, 0, 0, time.UTC), time.Date(2002, time.February, 10, 15, 30, 0, 0, time.UTC),
} }
issues, err := client.Issues.ListByRepo("o", "r", opt)
issues, _, err := client.Issues.ListByRepo("o", "r", opt)
if err != nil { if err != nil {
t.Errorf("Issues.ListByOrg returned error: %v", err) t.Errorf("Issues.ListByOrg returned error: %v", err)
} }
@ -130,7 +130,7 @@ func TestIssuesService_ListByRepo(t *testing.T) {
} }
func TestIssuesService_ListByRepo_invalidOwner(t *testing.T) { func TestIssuesService_ListByRepo_invalidOwner(t *testing.T) {
_, err := client.Issues.ListByRepo("%", "r", nil)
_, _, err := client.Issues.ListByRepo("%", "r", nil)
testURLParseError(t, err) testURLParseError(t, err)
} }
@ -143,7 +143,7 @@ func TestIssuesService_Get(t *testing.T) {
fmt.Fprint(w, `{"number":1}`) fmt.Fprint(w, `{"number":1}`)
}) })
issue, err := client.Issues.Get("o", "r", 1)
issue, _, err := client.Issues.Get("o", "r", 1)
if err != nil { if err != nil {
t.Errorf("Issues.Get returned error: %v", err) t.Errorf("Issues.Get returned error: %v", err)
} }
@ -155,7 +155,7 @@ func TestIssuesService_Get(t *testing.T) {
} }
func TestIssuesService_Get_invalidOwner(t *testing.T) { func TestIssuesService_Get_invalidOwner(t *testing.T) {
_, err := client.Issues.Get("%", "r", 1)
_, _, err := client.Issues.Get("%", "r", 1)
testURLParseError(t, err) testURLParseError(t, err)
} }
@ -177,7 +177,7 @@ func TestIssuesService_Create(t *testing.T) {
fmt.Fprint(w, `{"number":1}`) fmt.Fprint(w, `{"number":1}`)
}) })
issue, err := client.Issues.Create("o", "r", input)
issue, _, err := client.Issues.Create("o", "r", input)
if err != nil { if err != nil {
t.Errorf("Issues.Create returned error: %v", err) t.Errorf("Issues.Create returned error: %v", err)
} }
@ -189,7 +189,7 @@ func TestIssuesService_Create(t *testing.T) {
} }
func TestIssuesService_Create_invalidOwner(t *testing.T) { func TestIssuesService_Create_invalidOwner(t *testing.T) {
_, err := client.Issues.Create("%", "r", nil)
_, _, err := client.Issues.Create("%", "r", nil)
testURLParseError(t, err) testURLParseError(t, err)
} }
@ -211,7 +211,7 @@ func TestIssuesService_Edit(t *testing.T) {
fmt.Fprint(w, `{"number":1}`) fmt.Fprint(w, `{"number":1}`)
}) })
issue, err := client.Issues.Edit("o", "r", 1, input)
issue, _, err := client.Issues.Edit("o", "r", 1, input)
if err != nil { if err != nil {
t.Errorf("Issues.Edit returned error: %v", err) t.Errorf("Issues.Edit returned error: %v", err)
} }
@ -223,6 +223,6 @@ func TestIssuesService_Edit(t *testing.T) {
} }
func TestIssuesService_Edit_invalidOwner(t *testing.T) { func TestIssuesService_Edit_invalidOwner(t *testing.T) {
_, err := client.Issues.Edit("%", "r", 1, nil)
_, _, err := client.Issues.Edit("%", "r", 1, nil)
testURLParseError(t, err) testURLParseError(t, err)
} }

+ 12
- 12
github/orgs.go View File

@ -34,7 +34,7 @@ type Organization struct {
// organizations for the authenticated user. // organizations for the authenticated user.
// //
// GitHub API docs: http://developer.github.com/v3/orgs/#list-user-organizations // GitHub API docs: http://developer.github.com/v3/orgs/#list-user-organizations
func (s *OrganizationsService) List(user string, opt *ListOptions) ([]Organization, error) {
func (s *OrganizationsService) List(user string, opt *ListOptions) ([]Organization, *Response, error) {
var u string var u string
if user != "" { if user != "" {
u = fmt.Sprintf("users/%v/orgs", user) u = fmt.Sprintf("users/%v/orgs", user)
@ -50,40 +50,40 @@ func (s *OrganizationsService) List(user string, opt *ListOptions) ([]Organizati
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
if err != nil { if err != nil {
return nil, err
return nil, nil, err
} }
orgs := new([]Organization) orgs := new([]Organization)
_, err = s.client.Do(req, orgs)
return *orgs, err
resp, err := s.client.Do(req, orgs)
return *orgs, resp, err
} }
// Get fetches an organization by name. // Get fetches an organization by name.
// //
// GitHub API docs: http://developer.github.com/v3/orgs/#get-an-organization // GitHub API docs: http://developer.github.com/v3/orgs/#get-an-organization
func (s *OrganizationsService) Get(org string) (*Organization, error) {
func (s *OrganizationsService) Get(org string) (*Organization, *Response, error) {
u := fmt.Sprintf("orgs/%v", org) u := fmt.Sprintf("orgs/%v", org)
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
if err != nil { if err != nil {
return nil, err
return nil, nil, err
} }
organization := new(Organization) organization := new(Organization)
_, err = s.client.Do(req, organization)
return organization, err
resp, err := s.client.Do(req, organization)
return organization, resp, err
} }
// Edit an organization. // Edit an organization.
// //
// GitHub API docs: http://developer.github.com/v3/orgs/#edit-an-organization // GitHub API docs: http://developer.github.com/v3/orgs/#edit-an-organization
func (s *OrganizationsService) Edit(name string, org *Organization) (*Organization, error) {
func (s *OrganizationsService) Edit(name string, org *Organization) (*Organization, *Response, error) {
u := fmt.Sprintf("orgs/%v", name) u := fmt.Sprintf("orgs/%v", name)
req, err := s.client.NewRequest("PATCH", u, org) req, err := s.client.NewRequest("PATCH", u, org)
if err != nil { if err != nil {
return nil, err
return nil, nil, err
} }
o := new(Organization) o := new(Organization)
_, err = s.client.Do(req, o)
return o, err
resp, err := s.client.Do(req, o)
return o, resp, err
} }

+ 28
- 31
github/orgs_members.go View File

@ -5,108 +5,105 @@
package github package github
import (
"fmt"
)
import "fmt"
// ListMembers lists the members for an organization. If the authenticated // ListMembers lists the members for an organization. If the authenticated
// user is an owner of the organization, this will return both concealed and // user is an owner of the organization, this will return both concealed and
// public members, otherwise it will only return public members. // public members, otherwise it will only return public members.
// //
// GitHub API docs: http://developer.github.com/v3/orgs/members/#members-list // GitHub API docs: http://developer.github.com/v3/orgs/members/#members-list
func (s *OrganizationsService) ListMembers(org string) ([]User, error) {
func (s *OrganizationsService) ListMembers(org string) ([]User, *Response, error) {
u := fmt.Sprintf("orgs/%v/members", org) u := fmt.Sprintf("orgs/%v/members", org)
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
if err != nil { if err != nil {
return nil, err
return nil, nil, err
} }
members := new([]User) members := new([]User)
_, err = s.client.Do(req, members)
return *members, err
resp, err := s.client.Do(req, members)
return *members, resp, err
} }
// ListPublicMembers lists the public members for an organization. // ListPublicMembers lists the public members for an organization.
// //
// GitHub API docs: http://developer.github.com/v3/orgs/members/#public-members-list // GitHub API docs: http://developer.github.com/v3/orgs/members/#public-members-list
func (s *OrganizationsService) ListPublicMembers(org string) ([]User, error) {
func (s *OrganizationsService) ListPublicMembers(org string) ([]User, *Response, error) {
u := fmt.Sprintf("orgs/%v/public_members", org) u := fmt.Sprintf("orgs/%v/public_members", org)
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
if err != nil { if err != nil {
return nil, err
return nil, nil, err
} }
members := new([]User) members := new([]User)
_, err = s.client.Do(req, members)
return *members, err
resp, err := s.client.Do(req, members)
return *members, resp, err
} }
// CheckMembership checks if a user is a member of an organization. // CheckMembership checks if a user is a member of an organization.
// //
// GitHub API docs: http://developer.github.com/v3/orgs/members/#check-membership // GitHub API docs: http://developer.github.com/v3/orgs/members/#check-membership
func (s *OrganizationsService) CheckMembership(org, user string) (bool, error) {
func (s *OrganizationsService) CheckMembership(org, user string) (bool, *Response, error) {
u := fmt.Sprintf("orgs/%v/members/%v", org, user) u := fmt.Sprintf("orgs/%v/members/%v", org, user)
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
if err != nil { if err != nil {
return false, err
return false, nil, err
} }
_, err = s.client.Do(req, nil)
return parseBoolResponse(err)
resp, err := s.client.Do(req, nil)
member, err := parseBoolResponse(err)
return member, resp, err
} }
// CheckPublicMembership checks if a user is a public member of an organization. // CheckPublicMembership checks if a user is a public member of an organization.
// //
// GitHub API docs: http://developer.github.com/v3/orgs/members/#check-public-membership // GitHub API docs: http://developer.github.com/v3/orgs/members/#check-public-membership
func (s *OrganizationsService) CheckPublicMembership(org, user string) (bool, error) {
func (s *OrganizationsService) CheckPublicMembership(org, user string) (bool, *Response, error) {
u := fmt.Sprintf("orgs/%v/public_members/%v", org, user) u := fmt.Sprintf("orgs/%v/public_members/%v", org, user)
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
if err != nil { if err != nil {
return false, err
return false, nil, err
} }
_, err = s.client.Do(req, nil)
return parseBoolResponse(err)
resp, err := s.client.Do(req, nil)
member, err := parseBoolResponse(err)
return member, resp, err
} }
// RemoveMember removes a user from all teams of an organization. // RemoveMember removes a user from all teams of an organization.
// //
// GitHub API docs: http://developer.github.com/v3/orgs/members/#remove-a-member // GitHub API docs: http://developer.github.com/v3/orgs/members/#remove-a-member
func (s *OrganizationsService) RemoveMember(org, user string) error {
func (s *OrganizationsService) RemoveMember(org, user string) (*Response, error) {
u := fmt.Sprintf("orgs/%v/members/%v", org, user) u := fmt.Sprintf("orgs/%v/members/%v", org, user)
req, err := s.client.NewRequest("DELETE", u, nil) req, err := s.client.NewRequest("DELETE", u, nil)
if err != nil { if err != nil {
return err
return nil, err
} }
_, err = s.client.Do(req, nil)
return err
return s.client.Do(req, nil)
} }
// PublicizeMembership publicizes a user's membership in an organization. // PublicizeMembership publicizes a user's membership in an organization.
// //
// GitHub API docs: http://developer.github.com/v3/orgs/members/#publicize-a-users-membership // GitHub API docs: http://developer.github.com/v3/orgs/members/#publicize-a-users-membership
func (s *OrganizationsService) PublicizeMembership(org, user string) error {
func (s *OrganizationsService) PublicizeMembership(org, user string) (*Response, error) {
u := fmt.Sprintf("orgs/%v/public_members/%v", org, user) u := fmt.Sprintf("orgs/%v/public_members/%v", org, user)
req, err := s.client.NewRequest("PUT", u, nil) req, err := s.client.NewRequest("PUT", u, nil)
if err != nil { if err != nil {
return err
return nil, err
} }
_, err = s.client.Do(req, nil)
return err
return s.client.Do(req, nil)
} }
// ConcealMembership conceals a user's membership in an organization. // ConcealMembership conceals a user's membership in an organization.
// //
// GitHub API docs: http://developer.github.com/v3/orgs/members/#conceal-a-users-membership // GitHub API docs: http://developer.github.com/v3/orgs/members/#conceal-a-users-membership
func (s *OrganizationsService) ConcealMembership(org, user string) error {
func (s *OrganizationsService) ConcealMembership(org, user string) (*Response, error) {
u := fmt.Sprintf("orgs/%v/public_members/%v", org, user) u := fmt.Sprintf("orgs/%v/public_members/%v", org, user)
req, err := s.client.NewRequest("DELETE", u, nil) req, err := s.client.NewRequest("DELETE", u, nil)
if err != nil { if err != nil {
return err
return nil, err
} }
_, err = s.client.Do(req, nil)
return err
return s.client.Do(req, nil)
} }

+ 14
- 14
github/orgs_members_test.go View File

@ -21,7 +21,7 @@ func TestOrganizationsService_ListMembers(t *testing.T) {
fmt.Fprint(w, `[{"id":1}]`) fmt.Fprint(w, `[{"id":1}]`)
}) })
members, err := client.Organizations.ListMembers("o")
members, _, err := client.Organizations.ListMembers("o")
if err != nil { if err != nil {
t.Errorf("Organizations.ListMembers returned error: %v", err) t.Errorf("Organizations.ListMembers returned error: %v", err)
} }
@ -33,7 +33,7 @@ func TestOrganizationsService_ListMembers(t *testing.T) {
} }
func TestOrganizationsService_ListMembers_invalidOrg(t *testing.T) { func TestOrganizationsService_ListMembers_invalidOrg(t *testing.T) {
_, err := client.Organizations.ListMembers("%")
_, _, err := client.Organizations.ListMembers("%")
testURLParseError(t, err) testURLParseError(t, err)
} }
@ -46,7 +46,7 @@ func TestOrganizationsService_ListPublicMembers(t *testing.T) {
fmt.Fprint(w, `[{"id":1}]`) fmt.Fprint(w, `[{"id":1}]`)
}) })
members, err := client.Organizations.ListPublicMembers("o")
members, _, err := client.Organizations.ListPublicMembers("o")
if err != nil { if err != nil {
t.Errorf("Organizations.ListPublicMembers returned error: %v", err) t.Errorf("Organizations.ListPublicMembers returned error: %v", err)
} }
@ -58,7 +58,7 @@ func TestOrganizationsService_ListPublicMembers(t *testing.T) {
} }
func TestOrganizationsService_ListPublicMembers_invalidOrg(t *testing.T) { func TestOrganizationsService_ListPublicMembers_invalidOrg(t *testing.T) {
_, err := client.Organizations.ListPublicMembers("%")
_, _, err := client.Organizations.ListPublicMembers("%")
testURLParseError(t, err) testURLParseError(t, err)
} }
@ -71,7 +71,7 @@ func TestOrganizationsService_CheckMembership(t *testing.T) {
w.WriteHeader(http.StatusNoContent) w.WriteHeader(http.StatusNoContent)
}) })
member, err := client.Organizations.CheckMembership("o", "u")
member, _, err := client.Organizations.CheckMembership("o", "u")
if err != nil { if err != nil {
t.Errorf("Organizations.CheckMembership returned error: %v", err) t.Errorf("Organizations.CheckMembership returned error: %v", err)
} }
@ -90,7 +90,7 @@ func TestOrganizationsService_CheckMembership_notMember(t *testing.T) {
w.WriteHeader(http.StatusNotFound) w.WriteHeader(http.StatusNotFound)
}) })
member, err := client.Organizations.CheckMembership("o", "u")
member, _, err := client.Organizations.CheckMembership("o", "u")
if err != nil { if err != nil {
t.Errorf("Organizations.CheckMembership returned error: %+v", err) t.Errorf("Organizations.CheckMembership returned error: %+v", err)
} }
@ -110,7 +110,7 @@ func TestOrganizationsService_CheckMembership_error(t *testing.T) {
http.Error(w, "BadRequest", http.StatusBadRequest) http.Error(w, "BadRequest", http.StatusBadRequest)
}) })
member, err := client.Organizations.CheckMembership("o", "u")
member, _, err := client.Organizations.CheckMembership("o", "u")
if err == nil { if err == nil {
t.Errorf("Expected HTTP 400 response") t.Errorf("Expected HTTP 400 response")
} }
@ -120,7 +120,7 @@ func TestOrganizationsService_CheckMembership_error(t *testing.T) {
} }
func TestOrganizationsService_CheckMembership_invalidOrg(t *testing.T) { func TestOrganizationsService_CheckMembership_invalidOrg(t *testing.T) {
_, err := client.Organizations.CheckMembership("%", "u")
_, _, err := client.Organizations.CheckMembership("%", "u")
testURLParseError(t, err) testURLParseError(t, err)
} }
@ -133,7 +133,7 @@ func TestOrganizationsService_CheckPublicMembership(t *testing.T) {
w.WriteHeader(http.StatusNoContent) w.WriteHeader(http.StatusNoContent)
}) })
member, err := client.Organizations.CheckPublicMembership("o", "u")
member, _, err := client.Organizations.CheckPublicMembership("o", "u")
if err != nil { if err != nil {
t.Errorf("Organizations.CheckPublicMembership returned error: %v", err) t.Errorf("Organizations.CheckPublicMembership returned error: %v", err)
} }
@ -152,7 +152,7 @@ func TestOrganizationsService_CheckPublicMembership_notMember(t *testing.T) {
w.WriteHeader(http.StatusNotFound) w.WriteHeader(http.StatusNotFound)
}) })
member, err := client.Organizations.CheckPublicMembership("o", "u")
member, _, err := client.Organizations.CheckPublicMembership("o", "u")
if err != nil { if err != nil {
t.Errorf("Organizations.CheckPublicMembership returned error: %v", err) t.Errorf("Organizations.CheckPublicMembership returned error: %v", err)
} }
@ -172,7 +172,7 @@ func TestOrganizationsService_CheckPublicMembership_error(t *testing.T) {
http.Error(w, "BadRequest", http.StatusBadRequest) http.Error(w, "BadRequest", http.StatusBadRequest)
}) })
member, err := client.Organizations.CheckPublicMembership("o", "u")
member, _, err := client.Organizations.CheckPublicMembership("o", "u")
if err == nil { if err == nil {
t.Errorf("Expected HTTP 400 response") t.Errorf("Expected HTTP 400 response")
} }
@ -182,7 +182,7 @@ func TestOrganizationsService_CheckPublicMembership_error(t *testing.T) {
} }
func TestOrganizationsService_CheckPublicMembership_invalidOrg(t *testing.T) { func TestOrganizationsService_CheckPublicMembership_invalidOrg(t *testing.T) {
_, err := client.Organizations.CheckPublicMembership("%", "u")
_, _, err := client.Organizations.CheckPublicMembership("%", "u")
testURLParseError(t, err) testURLParseError(t, err)
} }
@ -194,13 +194,13 @@ func TestOrganizationsService_RemoveMember(t *testing.T) {
testMethod(t, r, "DELETE") testMethod(t, r, "DELETE")
}) })
err := client.Organizations.RemoveMember("o", "u")
_, err := client.Organizations.RemoveMember("o", "u")
if err != nil { if err != nil {
t.Errorf("Organizations.RemoveMember returned error: %v", err) t.Errorf("Organizations.RemoveMember returned error: %v", err)
} }
} }
func TestOrganizationsService_RemoveMember_invalidOrg(t *testing.T) { func TestOrganizationsService_RemoveMember_invalidOrg(t *testing.T) {
err := client.Organizations.RemoveMember("%", "u")
_, err := client.Organizations.RemoveMember("%", "u")
testURLParseError(t, err) testURLParseError(t, err)
} }

+ 50
- 55
github/orgs_teams.go View File

@ -5,9 +5,7 @@
package github package github
import (
"fmt"
)
import "fmt"
// Team represents a team within a GitHub organization. Teams are used to // Team represents a team within a GitHub organization. Teams are used to
// manage access to an organization's repositories. // manage access to an organization's repositories.
@ -24,162 +22,161 @@ type Team struct {
// 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, error) {
func (s *OrganizationsService) ListTeams(org string) ([]Team, *Response, error) {
u := fmt.Sprintf("orgs/%v/teams", org) u := fmt.Sprintf("orgs/%v/teams", org)
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
if err != nil { if err != nil {
return nil, err
return nil, nil, err
} }
teams := new([]Team) teams := new([]Team)
_, err = s.client.Do(req, teams)
return *teams, err
resp, err := s.client.Do(req, teams)
return *teams, resp, err
} }
// GetTeam fetches a team by ID. // GetTeam fetches a team by ID.
// //
// GitHub API docs: http://developer.github.com/v3/orgs/teams/#get-team // GitHub API docs: http://developer.github.com/v3/orgs/teams/#get-team
func (s *OrganizationsService) GetTeam(team int) (*Team, error) {
func (s *OrganizationsService) GetTeam(team int) (*Team, *Response, error) {
u := fmt.Sprintf("teams/%v", team) u := fmt.Sprintf("teams/%v", team)
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
if err != nil { if err != nil {
return nil, err
return nil, nil, err
} }
t := new(Team) t := new(Team)
_, err = s.client.Do(req, t)
return t, err
resp, err := s.client.Do(req, t)
return t, resp, err
} }
// CreateTeam creates a new team within an organization. // CreateTeam creates a new team within an organization.
// //
// GitHub API docs: http://developer.github.com/v3/orgs/teams/#create-team // GitHub API docs: http://developer.github.com/v3/orgs/teams/#create-team
func (s *OrganizationsService) CreateTeam(org string, team *Team) (*Team, error) {
func (s *OrganizationsService) CreateTeam(org string, team *Team) (*Team, *Response, error) {
u := fmt.Sprintf("orgs/%v/teams", org) u := fmt.Sprintf("orgs/%v/teams", org)
req, err := s.client.NewRequest("POST", u, team) req, err := s.client.NewRequest("POST", u, team)
if err != nil { if err != nil {
return nil, err
return nil, nil, err
} }
t := new(Team) t := new(Team)
_, err = s.client.Do(req, t)
return t, err
resp, err := s.client.Do(req, t)
return t, resp, err
} }
// EditTeam edits a team. // EditTeam edits a team.
// //
// GitHub API docs: http://developer.github.com/v3/orgs/teams/#edit-team // GitHub API docs: http://developer.github.com/v3/orgs/teams/#edit-team
func (s *OrganizationsService) EditTeam(id int, team *Team) (*Team, error) {
func (s *OrganizationsService) EditTeam(id int, team *Team) (*Team, *Response, error) {
u := fmt.Sprintf("teams/%v", id) u := fmt.Sprintf("teams/%v", id)
req, err := s.client.NewRequest("PATCH", u, team) req, err := s.client.NewRequest("PATCH", u, team)
if err != nil { if err != nil {
return nil, err
return nil, nil, err
} }
t := new(Team) t := new(Team)
_, err = s.client.Do(req, t)
return t, err
resp, err := s.client.Do(req, t)
return t, resp, err
} }
// DeleteTeam deletes a team. // DeleteTeam deletes a team.
// //
// GitHub API docs: http://developer.github.com/v3/orgs/teams/#delete-team // GitHub API docs: http://developer.github.com/v3/orgs/teams/#delete-team
func (s *OrganizationsService) DeleteTeam(team int) error {
func (s *OrganizationsService) DeleteTeam(team int) (*Response, error) {
u := fmt.Sprintf("teams/%v", team) u := fmt.Sprintf("teams/%v", team)
req, err := s.client.NewRequest("DELETE", u, nil) req, err := s.client.NewRequest("DELETE", u, nil)
if err != nil { if err != nil {
return err
return nil, err
} }
_, err = s.client.Do(req, nil)
return err
return s.client.Do(req, nil)
} }
// ListTeamMembers lists all of the users who are members of the specified // ListTeamMembers lists all of the users who are members of the specified
// 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, error) {
func (s *OrganizationsService) ListTeamMembers(team int) ([]User, *Response, error) {
u := fmt.Sprintf("teams/%v/members", team) u := fmt.Sprintf("teams/%v/members", team)
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
if err != nil { if err != nil {
return nil, err
return nil, nil, err
} }
members := new([]User) members := new([]User)
_, err = s.client.Do(req, members)
return *members, err
resp, err := s.client.Do(req, members)
return *members, resp, err
} }
// CheckTeamMembership checks if a user is a member of the specified team. // CheckTeamMembership checks if a user is a member of the specified team.
// //
// GitHub API docs: http://developer.github.com/v3/orgs/teams/#get-team-member // GitHub API docs: http://developer.github.com/v3/orgs/teams/#get-team-member
func (s *OrganizationsService) CheckTeamMembership(team int, user string) (bool, error) {
func (s *OrganizationsService) CheckTeamMembership(team int, user string) (bool, *Response, error) {
u := fmt.Sprintf("teams/%v/members/%v", team, user) u := fmt.Sprintf("teams/%v/members/%v", team, user)
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
if err != nil { if err != nil {
return false, err
return false, nil, err
} }
_, err = s.client.Do(req, nil)
return parseBoolResponse(err)
resp, err := s.client.Do(req, nil)
member, err := parseBoolResponse(err)
return member, resp, err
} }
// AddTeamMember adds a user to a team. // AddTeamMember adds a user to a team.
// //
// GitHub API docs: http://developer.github.com/v3/orgs/teams/#add-team-member // GitHub API docs: http://developer.github.com/v3/orgs/teams/#add-team-member
func (s *OrganizationsService) AddTeamMember(team int, user string) error {
func (s *OrganizationsService) AddTeamMember(team int, user string) (*Response, error) {
u := fmt.Sprintf("teams/%v/members/%v", team, user) u := fmt.Sprintf("teams/%v/members/%v", team, user)
req, err := s.client.NewRequest("PUT", u, nil) req, err := s.client.NewRequest("PUT", u, nil)
if err != nil { if err != nil {
return err
return nil, err
} }
_, err = s.client.Do(req, nil)
return err
return s.client.Do(req, nil)
} }
// RemoveTeamMember removes a user from a team. // RemoveTeamMember removes a user from a team.
// //
// GitHub API docs: http://developer.github.com/v3/orgs/teams/#remove-team-member // GitHub API docs: http://developer.github.com/v3/orgs/teams/#remove-team-member
func (s *OrganizationsService) RemoveTeamMember(team int, user string) error {
func (s *OrganizationsService) RemoveTeamMember(team int, user string) (*Response, error) {
u := fmt.Sprintf("teams/%v/members/%v", team, user) u := fmt.Sprintf("teams/%v/members/%v", team, user)
req, err := s.client.NewRequest("DELETE", u, nil) req, err := s.client.NewRequest("DELETE", u, nil)
if err != nil { if err != nil {
return err
return nil, err
} }
_, err = s.client.Do(req, nil)
return err
return s.client.Do(req, nil)
} }
// 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, error) {
func (s *OrganizationsService) ListTeamRepos(team int) ([]Repository, *Response, error) {
u := fmt.Sprintf("teams/%v/repos", team) u := fmt.Sprintf("teams/%v/repos", team)
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
if err != nil { if err != nil {
return nil, err
return nil, nil, err
} }
repos := new([]Repository) repos := new([]Repository)
_, err = s.client.Do(req, repos)
return *repos, err
resp, err := s.client.Do(req, repos)
return *repos, resp, err
} }
// CheckTeamRepo checks if a team manages the specified repository. // CheckTeamRepo checks if a team manages the specified repository.
// //
// GitHub API docs: http://developer.github.com/v3/orgs/teams/#get-team-repo // GitHub API docs: http://developer.github.com/v3/orgs/teams/#get-team-repo
func (s *OrganizationsService) CheckTeamRepo(team int, owner string, repo string) (bool, error) {
func (s *OrganizationsService) CheckTeamRepo(team int, owner string, repo string) (bool, *Response, error) {
u := fmt.Sprintf("teams/%v/repos/%v/%v", team, owner, repo) u := fmt.Sprintf("teams/%v/repos/%v/%v", team, owner, repo)
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
if err != nil { if err != nil {
return false, err
return false, nil, err
} }
_, err = s.client.Do(req, nil)
return parseBoolResponse(err)
resp, err := s.client.Do(req, nil)
manages, err := parseBoolResponse(err)
return manages, resp, err
} }
// AddTeamRepo adds a repository to be managed by the specified team. The // AddTeamRepo adds a repository to be managed by the specified team. The
@ -187,15 +184,14 @@ func (s *OrganizationsService) CheckTeamRepo(team int, owner string, repo string
// belongs, or a direct fork of a repository owned by the organization. // belongs, or a direct fork of a repository owned by the organization.
// //
// GitHub API docs: http://developer.github.com/v3/orgs/teams/#add-team-repo // GitHub API docs: http://developer.github.com/v3/orgs/teams/#add-team-repo
func (s *OrganizationsService) AddTeamRepo(team int, owner string, repo string) error {
func (s *OrganizationsService) AddTeamRepo(team int, owner string, repo string) (*Response, error) {
u := fmt.Sprintf("teams/%v/repos/%v/%v", team, owner, repo) u := fmt.Sprintf("teams/%v/repos/%v/%v", team, owner, repo)
req, err := s.client.NewRequest("PUT", u, nil) req, err := s.client.NewRequest("PUT", u, nil)
if err != nil { if err != nil {
return err
return nil, err
} }
_, err = s.client.Do(req, nil)
return err
return s.client.Do(req, nil)
} }
// RemoveTeamRepo removes a repository from being managed by the specified // RemoveTeamRepo removes a repository from being managed by the specified
@ -203,13 +199,12 @@ func (s *OrganizationsService) AddTeamRepo(team int, owner string, repo string)
// from the team. // from the team.
// //
// GitHub API docs: http://developer.github.com/v3/orgs/teams/#remove-team-repo // GitHub API docs: http://developer.github.com/v3/orgs/teams/#remove-team-repo
func (s *OrganizationsService) RemoveTeamRepo(team int, owner string, repo string) error {
func (s *OrganizationsService) RemoveTeamRepo(team int, owner string, repo string) (*Response, error) {
u := fmt.Sprintf("teams/%v/repos/%v/%v", team, owner, repo) u := fmt.Sprintf("teams/%v/repos/%v/%v", team, owner, repo)
req, err := s.client.NewRequest("DELETE", u, nil) req, err := s.client.NewRequest("DELETE", u, nil)
if err != nil { if err != nil {
return err
return nil, err
} }
_, err = s.client.Do(req, nil)
return err
return s.client.Do(req, nil)
} }

+ 30
- 30
github/orgs_teams_test.go View File

@ -22,7 +22,7 @@ func TestOrganizationsService_ListTeams(t *testing.T) {
fmt.Fprint(w, `[{"id":1}]`) fmt.Fprint(w, `[{"id":1}]`)
}) })
teams, err := client.Organizations.ListTeams("o")
teams, _, err := client.Organizations.ListTeams("o")
if err != nil { if err != nil {
t.Errorf("Organizations.ListTeams returned error: %v", err) t.Errorf("Organizations.ListTeams returned error: %v", err)
} }
@ -34,7 +34,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("%")
testURLParseError(t, err) testURLParseError(t, err)
} }
@ -47,7 +47,7 @@ func TestOrganizationsService_GetTeam(t *testing.T) {
fmt.Fprint(w, `{"id":1, "name":"n", "url":"u", "slug": "s", "permission":"p"}`) fmt.Fprint(w, `{"id":1, "name":"n", "url":"u", "slug": "s", "permission":"p"}`)
}) })
team, err := client.Organizations.GetTeam(1)
team, _, err := client.Organizations.GetTeam(1)
if err != nil { if err != nil {
t.Errorf("Organizations.GetTeam returned error: %v", err) t.Errorf("Organizations.GetTeam returned error: %v", err)
} }
@ -76,7 +76,7 @@ func TestOrganizationsService_CreateTeam(t *testing.T) {
fmt.Fprint(w, `{"id":1}`) fmt.Fprint(w, `{"id":1}`)
}) })
team, err := client.Organizations.CreateTeam("o", input)
team, _, err := client.Organizations.CreateTeam("o", input)
if err != nil { if err != nil {
t.Errorf("Organizations.CreateTeam returned error: %v", err) t.Errorf("Organizations.CreateTeam returned error: %v", err)
} }
@ -88,7 +88,7 @@ func TestOrganizationsService_CreateTeam(t *testing.T) {
} }
func TestOrganizationsService_CreateTeam_invalidOrg(t *testing.T) { func TestOrganizationsService_CreateTeam_invalidOrg(t *testing.T) {
_, err := client.Organizations.CreateTeam("%", nil)
_, _, err := client.Organizations.CreateTeam("%", nil)
testURLParseError(t, err) testURLParseError(t, err)
} }
@ -110,7 +110,7 @@ func TestOrganizationsService_EditTeam(t *testing.T) {
fmt.Fprint(w, `{"id":1}`) fmt.Fprint(w, `{"id":1}`)
}) })
team, err := client.Organizations.EditTeam(1, input)
team, _, err := client.Organizations.EditTeam(1, input)
if err != nil { if err != nil {
t.Errorf("Organizations.EditTeam returned error: %v", err) t.Errorf("Organizations.EditTeam returned error: %v", err)
} }
@ -129,7 +129,7 @@ func TestOrganizationsService_DeleteTeam(t *testing.T) {
testMethod(t, r, "DELETE") testMethod(t, r, "DELETE")
}) })
err := client.Organizations.DeleteTeam(1)
_, err := client.Organizations.DeleteTeam(1)
if err != nil { if err != nil {
t.Errorf("Organizations.DeleteTeam returned error: %v", err) t.Errorf("Organizations.DeleteTeam returned error: %v", err)
} }
@ -144,7 +144,7 @@ func TestOrganizationsService_ListTeamMembers(t *testing.T) {
fmt.Fprint(w, `[{"id":1}]`) fmt.Fprint(w, `[{"id":1}]`)
}) })
members, err := client.Organizations.ListTeamMembers(1)
members, _, err := client.Organizations.ListTeamMembers(1)
if err != nil { if err != nil {
t.Errorf("Organizations.ListTeamMembers returned error: %v", err) t.Errorf("Organizations.ListTeamMembers returned error: %v", err)
} }
@ -163,7 +163,7 @@ func TestOrganizationsService_CheckTeamMembership_true(t *testing.T) {
testMethod(t, r, "GET") testMethod(t, r, "GET")
}) })
member, err := client.Organizations.CheckTeamMembership(1, "u")
member, _, err := client.Organizations.CheckTeamMembership(1, "u")
if err != nil { if err != nil {
t.Errorf("Organizations.CheckTeamMembership returned error: %v", err) t.Errorf("Organizations.CheckTeamMembership returned error: %v", err)
} }
@ -182,7 +182,7 @@ func TestOrganizationsService_CheckTeamMembership_false(t *testing.T) {
w.WriteHeader(http.StatusNotFound) w.WriteHeader(http.StatusNotFound)
}) })
member, err := client.Organizations.CheckTeamMembership(1, "u")
member, _, err := client.Organizations.CheckTeamMembership(1, "u")
if err != nil { if err != nil {
t.Errorf("Organizations.CheckTeamMembership returned error: %+v", err) t.Errorf("Organizations.CheckTeamMembership returned error: %+v", err)
} }
@ -202,7 +202,7 @@ func TestOrganizationsService_CheckTeamMembership_error(t *testing.T) {
http.Error(w, "BadRequest", http.StatusBadRequest) http.Error(w, "BadRequest", http.StatusBadRequest)
}) })
member, err := client.Organizations.CheckTeamMembership(1, "u")
member, _, err := client.Organizations.CheckTeamMembership(1, "u")
if err == nil { if err == nil {
t.Errorf("Expected HTTP 400 response") t.Errorf("Expected HTTP 400 response")
} }
@ -212,7 +212,7 @@ func TestOrganizationsService_CheckTeamMembership_error(t *testing.T) {
} }
func TestOrganizationsService_CheckMembership_invalidUser(t *testing.T) { func TestOrganizationsService_CheckMembership_invalidUser(t *testing.T) {
_, err := client.Organizations.CheckTeamMembership(1, "%")
_, _, err := client.Organizations.CheckTeamMembership(1, "%")
testURLParseError(t, err) testURLParseError(t, err)
} }
@ -225,14 +225,14 @@ func TestOrganizationsService_AddTeamMember(t *testing.T) {
w.WriteHeader(http.StatusNoContent) w.WriteHeader(http.StatusNoContent)
}) })
err := client.Organizations.AddTeamMember(1, "u")
_, err := client.Organizations.AddTeamMember(1, "u")
if err != nil { if err != nil {
t.Errorf("Organizations.AddTeamMember returned error: %v", err) t.Errorf("Organizations.AddTeamMember returned error: %v", err)
} }
} }
func TestOrganizationsService_AddTeamMember_invalidUser(t *testing.T) { func TestOrganizationsService_AddTeamMember_invalidUser(t *testing.T) {
err := client.Organizations.AddTeamMember(1, "%")
_, err := client.Organizations.AddTeamMember(1, "%")
testURLParseError(t, err) testURLParseError(t, err)
} }
@ -245,14 +245,14 @@ func TestOrganizationsService_RemoveTeamMember(t *testing.T) {
w.WriteHeader(http.StatusNoContent) w.WriteHeader(http.StatusNoContent)
}) })
err := client.Organizations.RemoveTeamMember(1, "u")
_, err := client.Organizations.RemoveTeamMember(1, "u")
if err != nil { if err != nil {
t.Errorf("Organizations.RemoveTeamMember returned error: %v", err) t.Errorf("Organizations.RemoveTeamMember returned error: %v", err)
} }
} }
func TestOrganizationsService_RemoveTeamMember_invalidUser(t *testing.T) { func TestOrganizationsService_RemoveTeamMember_invalidUser(t *testing.T) {
err := client.Organizations.RemoveTeamMember(1, "%")
_, err := client.Organizations.RemoveTeamMember(1, "%")
testURLParseError(t, err) testURLParseError(t, err)
} }
@ -265,14 +265,14 @@ func TestOrganizationsService_PublicizeMembership(t *testing.T) {
w.WriteHeader(http.StatusNoContent) w.WriteHeader(http.StatusNoContent)
}) })
err := client.Organizations.PublicizeMembership("o", "u")
_, err := client.Organizations.PublicizeMembership("o", "u")
if err != nil { if err != nil {
t.Errorf("Organizations.PublicizeMembership returned error: %v", err) t.Errorf("Organizations.PublicizeMembership returned error: %v", err)
} }
} }
func TestOrganizationsService_PublicizeMembership_invalidOrg(t *testing.T) { func TestOrganizationsService_PublicizeMembership_invalidOrg(t *testing.T) {
err := client.Organizations.PublicizeMembership("%", "u")
_, err := client.Organizations.PublicizeMembership("%", "u")
testURLParseError(t, err) testURLParseError(t, err)
} }
@ -285,14 +285,14 @@ func TestOrganizationsService_ConcealMembership(t *testing.T) {
w.WriteHeader(http.StatusNoContent) w.WriteHeader(http.StatusNoContent)
}) })
err := client.Organizations.ConcealMembership("o", "u")
_, err := client.Organizations.ConcealMembership("o", "u")
if err != nil { if err != nil {
t.Errorf("Organizations.ConcealMembership returned error: %v", err) t.Errorf("Organizations.ConcealMembership returned error: %v", err)
} }
} }
func TestOrganizationsService_ConcealMembership_invalidOrg(t *testing.T) { func TestOrganizationsService_ConcealMembership_invalidOrg(t *testing.T) {
err := client.Organizations.ConcealMembership("%", "u")
_, err := client.Organizations.ConcealMembership("%", "u")
testURLParseError(t, err) testURLParseError(t, err)
} }
@ -305,7 +305,7 @@ func TestOrganizationsService_ListTeamRepos(t *testing.T) {
fmt.Fprint(w, `[{"id":1}]`) fmt.Fprint(w, `[{"id":1}]`)
}) })
members, err := client.Organizations.ListTeamRepos(1)
members, _, err := client.Organizations.ListTeamRepos(1)
if err != nil { if err != nil {
t.Errorf("Organizations.ListTeamRepos returned error: %v", err) t.Errorf("Organizations.ListTeamRepos returned error: %v", err)
} }
@ -325,7 +325,7 @@ func TestOrganizationsService_CheckTeamRepo_true(t *testing.T) {
w.WriteHeader(http.StatusNoContent) w.WriteHeader(http.StatusNoContent)
}) })
managed, err := client.Organizations.CheckTeamRepo(1, "o", "r")
managed, _, err := client.Organizations.CheckTeamRepo(1, "o", "r")
if err != nil { if err != nil {
t.Errorf("Organizations.CheckTeamRepo returned error: %v", err) t.Errorf("Organizations.CheckTeamRepo returned error: %v", err)
} }
@ -343,7 +343,7 @@ func TestOrganizationsService_CheckTeamRepo_false(t *testing.T) {
w.WriteHeader(http.StatusNotFound) w.WriteHeader(http.StatusNotFound)
}) })
managed, err := client.Organizations.CheckTeamRepo(1, "o", "r")
managed, _, err := client.Organizations.CheckTeamRepo(1, "o", "r")
if err != nil { if err != nil {
t.Errorf("Organizations.CheckTeamRepo returned error: %v", err) t.Errorf("Organizations.CheckTeamRepo returned error: %v", err)
} }
@ -361,7 +361,7 @@ func TestOrganizationsService_CheckTeamRepo_error(t *testing.T) {
http.Error(w, "BadRequest", http.StatusBadRequest) http.Error(w, "BadRequest", http.StatusBadRequest)
}) })
managed, err := client.Organizations.CheckTeamRepo(1, "o", "r")
managed, _, err := client.Organizations.CheckTeamRepo(1, "o", "r")
if err == nil { if err == nil {
t.Errorf("Expected HTTP 400 response") t.Errorf("Expected HTTP 400 response")
} }
@ -371,7 +371,7 @@ func TestOrganizationsService_CheckTeamRepo_error(t *testing.T) {
} }
func TestOrganizationsService_CheckTeamRepo_invalidOwner(t *testing.T) { func TestOrganizationsService_CheckTeamRepo_invalidOwner(t *testing.T) {
_, err := client.Organizations.CheckTeamRepo(1, "%", "r")
_, _, err := client.Organizations.CheckTeamRepo(1, "%", "r")
testURLParseError(t, err) testURLParseError(t, err)
} }
@ -384,7 +384,7 @@ func TestOrganizationsService_AddTeamRepo(t *testing.T) {
w.WriteHeader(http.StatusNoContent) w.WriteHeader(http.StatusNoContent)
}) })
err := client.Organizations.AddTeamRepo(1, "o", "r")
_, err := client.Organizations.AddTeamRepo(1, "o", "r")
if err != nil { if err != nil {
t.Errorf("Organizations.AddTeamRepo returned error: %v", err) t.Errorf("Organizations.AddTeamRepo returned error: %v", err)
} }
@ -399,14 +399,14 @@ func TestOrganizationsService_AddTeamRepo_noAccess(t *testing.T) {
w.WriteHeader(422) w.WriteHeader(422)
}) })
err := client.Organizations.AddTeamRepo(1, "o", "r")
_, err := client.Organizations.AddTeamRepo(1, "o", "r")
if err == nil { if err == nil {
t.Errorf("Expcted error to be returned") t.Errorf("Expcted error to be returned")
} }
} }
func TestOrganizationsService_AddTeamRepo_invalidOwner(t *testing.T) { func TestOrganizationsService_AddTeamRepo_invalidOwner(t *testing.T) {
err := client.Organizations.AddTeamRepo(1, "%", "r")
_, err := client.Organizations.AddTeamRepo(1, "%", "r")
testURLParseError(t, err) testURLParseError(t, err)
} }
@ -419,13 +419,13 @@ func TestOrganizationsService_RemoveTeamRepo(t *testing.T) {
w.WriteHeader(http.StatusNoContent) w.WriteHeader(http.StatusNoContent)
}) })
err := client.Organizations.RemoveTeamRepo(1, "o", "r")
_, err := client.Organizations.RemoveTeamRepo(1, "o", "r")
if err != nil { if err != nil {
t.Errorf("Organizations.RemoveTeamRepo returned error: %v", err) t.Errorf("Organizations.RemoveTeamRepo returned error: %v", err)
} }
} }
func TestOrganizationsService_RemoveTeamRepo_invalidOwner(t *testing.T) { func TestOrganizationsService_RemoveTeamRepo_invalidOwner(t *testing.T) {
err := client.Organizations.RemoveTeamRepo(1, "%", "r")
_, err := client.Organizations.RemoveTeamRepo(1, "%", "r")
testURLParseError(t, err) testURLParseError(t, err)
} }

+ 7
- 7
github/orgs_test.go View File

@ -22,7 +22,7 @@ func TestOrganizationsService_List_authenticatedUser(t *testing.T) {
fmt.Fprint(w, `[{"id":1},{"id":2}]`) fmt.Fprint(w, `[{"id":1},{"id":2}]`)
}) })
orgs, err := client.Organizations.List("", nil)
orgs, _, err := client.Organizations.List("", nil)
if err != nil { if err != nil {
t.Errorf("Organizations.List returned error: %v", err) t.Errorf("Organizations.List returned error: %v", err)
} }
@ -44,7 +44,7 @@ func TestOrganizationsService_List_specifiedUser(t *testing.T) {
}) })
opt := &ListOptions{2} opt := &ListOptions{2}
orgs, err := client.Organizations.List("u", opt)
orgs, _, err := client.Organizations.List("u", opt)
if err != nil { if err != nil {
t.Errorf("Organizations.List returned error: %v", err) t.Errorf("Organizations.List returned error: %v", err)
} }
@ -56,7 +56,7 @@ func TestOrganizationsService_List_specifiedUser(t *testing.T) {
} }
func TestOrganizationsService_List_invalidUser(t *testing.T) { func TestOrganizationsService_List_invalidUser(t *testing.T) {
_, err := client.Organizations.List("%", nil)
_, _, err := client.Organizations.List("%", nil)
testURLParseError(t, err) testURLParseError(t, err)
} }
@ -69,7 +69,7 @@ func TestOrganizationsService_Get(t *testing.T) {
fmt.Fprint(w, `{"id":1, "login":"l", "url":"u", "avatar_url": "a", "location":"l"}`) fmt.Fprint(w, `{"id":1, "login":"l", "url":"u", "avatar_url": "a", "location":"l"}`)
}) })
org, err := client.Organizations.Get("o")
org, _, err := client.Organizations.Get("o")
if err != nil { if err != nil {
t.Errorf("Organizations.Get returned error: %v", err) t.Errorf("Organizations.Get returned error: %v", err)
} }
@ -81,7 +81,7 @@ func TestOrganizationsService_Get(t *testing.T) {
} }
func TestOrganizationsService_Get_invalidOrg(t *testing.T) { func TestOrganizationsService_Get_invalidOrg(t *testing.T) {
_, err := client.Organizations.Get("%")
_, _, err := client.Organizations.Get("%")
testURLParseError(t, err) testURLParseError(t, err)
} }
@ -103,7 +103,7 @@ func TestOrganizationsService_Edit(t *testing.T) {
fmt.Fprint(w, `{"id":1}`) fmt.Fprint(w, `{"id":1}`)
}) })
org, err := client.Organizations.Edit("o", input)
org, _, err := client.Organizations.Edit("o", input)
if err != nil { if err != nil {
t.Errorf("Organizations.Edit returned error: %v", err) t.Errorf("Organizations.Edit returned error: %v", err)
} }
@ -115,6 +115,6 @@ func TestOrganizationsService_Edit(t *testing.T) {
} }
func TestOrganizationsService_Edit_invalidOrg(t *testing.T) { func TestOrganizationsService_Edit_invalidOrg(t *testing.T) {
_, err := client.Organizations.Edit("%", nil)
_, _, err := client.Organizations.Edit("%", nil)
testURLParseError(t, err) testURLParseError(t, err)
} }

+ 16
- 16
github/pulls.go View File

@ -60,7 +60,7 @@ type PullRequestListOptions struct {
// List the pull requests for the specified repository. // List the pull requests for the specified repository.
// //
// GitHub API docs: http://developer.github.com/v3/pulls/#list-pull-requests // GitHub API docs: http://developer.github.com/v3/pulls/#list-pull-requests
func (s *PullRequestsService) List(owner string, repo string, opt *PullRequestListOptions) ([]PullRequest, error) {
func (s *PullRequestsService) List(owner string, repo string, opt *PullRequestListOptions) ([]PullRequest, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/pulls", owner, repo) u := fmt.Sprintf("repos/%v/%v/pulls", owner, repo)
if opt != nil { if opt != nil {
params := url.Values{ params := url.Values{
@ -73,52 +73,52 @@ func (s *PullRequestsService) List(owner string, repo string, opt *PullRequestLi
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
if err != nil { if err != nil {
return nil, err
return nil, nil, err
} }
pulls := new([]PullRequest) pulls := new([]PullRequest)
_, err = s.client.Do(req, pulls)
return *pulls, err
resp, err := s.client.Do(req, pulls)
return *pulls, resp, err
} }
// Get a single pull request. // Get a single pull request.
// //
// GitHub API docs: https://developer.github.com/v3/pulls/#get-a-single-pull-request // GitHub API docs: https://developer.github.com/v3/pulls/#get-a-single-pull-request
func (s *PullRequestsService) Get(owner string, repo string, number int) (*PullRequest, error) {
func (s *PullRequestsService) Get(owner string, repo string, number int) (*PullRequest, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/pulls/%d", owner, repo, number) u := fmt.Sprintf("repos/%v/%v/pulls/%d", owner, repo, number)
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
if err != nil { if err != nil {
return nil, err
return nil, nil, err
} }
pull := new(PullRequest) pull := new(PullRequest)
_, err = s.client.Do(req, pull)
return pull, err
resp, err := s.client.Do(req, pull)
return pull, resp, err
} }
// Create a new pull request on the specified repository. // Create a new pull request on the specified repository.
// //
// GitHub API docs: https://developer.github.com/v3/pulls/#create-a-pull-request // GitHub API docs: https://developer.github.com/v3/pulls/#create-a-pull-request
func (s *PullRequestsService) Create(owner string, repo string, pull *PullRequest) (*PullRequest, error) {
func (s *PullRequestsService) Create(owner string, repo string, pull *PullRequest) (*PullRequest, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/pulls", owner, repo) u := fmt.Sprintf("repos/%v/%v/pulls", owner, repo)
req, err := s.client.NewRequest("POST", u, pull) req, err := s.client.NewRequest("POST", u, pull)
if err != nil { if err != nil {
return nil, err
return nil, nil, err
} }
p := new(PullRequest) p := new(PullRequest)
_, err = s.client.Do(req, p)
return p, err
resp, err := s.client.Do(req, p)
return p, resp, err
} }
// Edit a pull request. // Edit a pull request.
// //
// GitHub API docs: https://developer.github.com/v3/pulls/#update-a-pull-request // GitHub API docs: https://developer.github.com/v3/pulls/#update-a-pull-request
func (s *PullRequestsService) Edit(owner string, repo string, number int, pull *PullRequest) (*PullRequest, error) {
func (s *PullRequestsService) Edit(owner string, repo string, number int, pull *PullRequest) (*PullRequest, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/pulls/%d", owner, repo, number) u := fmt.Sprintf("repos/%v/%v/pulls/%d", owner, repo, number)
req, err := s.client.NewRequest("PATCH", u, pull) req, err := s.client.NewRequest("PATCH", u, pull)
if err != nil { if err != nil {
return nil, err
return nil, nil, err
} }
p := new(PullRequest) p := new(PullRequest)
_, err = s.client.Do(req, p)
return p, err
resp, err := s.client.Do(req, p)
return p, resp, err
} }

+ 19
- 20
github/pulls_comments.go View File

@ -41,7 +41,7 @@ type PullRequestListCommentsOptions struct {
// the repository. // the repository.
// //
// GitHub API docs: https://developer.github.com/v3/pulls/comments/#list-comments-on-a-pull-request // GitHub API docs: https://developer.github.com/v3/pulls/comments/#list-comments-on-a-pull-request
func (s *PullRequestsService) ListComments(owner string, repo string, number int, opt *PullRequestListCommentsOptions) ([]PullRequestComment, error) {
func (s *PullRequestsService) ListComments(owner string, repo string, number int, opt *PullRequestListCommentsOptions) ([]PullRequestComment, *Response, error) {
var u string var u string
if number == 0 { if number == 0 {
u = fmt.Sprintf("repos/%v/%v/pulls/comments", owner, repo) u = fmt.Sprintf("repos/%v/%v/pulls/comments", owner, repo)
@ -62,64 +62,63 @@ func (s *PullRequestsService) ListComments(owner string, repo string, number int
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
if err != nil { if err != nil {
return nil, err
return nil, nil, err
} }
comments := new([]PullRequestComment) comments := new([]PullRequestComment)
_, err = s.client.Do(req, comments)
return *comments, err
resp, err := s.client.Do(req, comments)
return *comments, resp, err
} }
// GetComment fetches the specified pull request comment. // GetComment fetches the specified pull request comment.
// //
// GitHub API docs: https://developer.github.com/v3/pulls/comments/#get-a-single-comment // GitHub API docs: https://developer.github.com/v3/pulls/comments/#get-a-single-comment
func (s *PullRequestsService) GetComment(owner string, repo string, number int) (*PullRequestComment, error) {
func (s *PullRequestsService) GetComment(owner string, repo string, number int) (*PullRequestComment, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/pulls/comments/%d", owner, repo, number) u := fmt.Sprintf("repos/%v/%v/pulls/comments/%d", owner, repo, number)
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
if err != nil { if err != nil {
return nil, err
return nil, nil, err
} }
comment := new(PullRequestComment) comment := new(PullRequestComment)
_, err = s.client.Do(req, comment)
return comment, err
resp, err := s.client.Do(req, comment)
return comment, resp, err
} }
// CreateComment creates a new comment on the specified pull request. // CreateComment creates a new comment on the specified pull request.
// //
// GitHub API docs: https://developer.github.com/v3/pulls/comments/#get-a-single-comment // GitHub API docs: https://developer.github.com/v3/pulls/comments/#get-a-single-comment
func (s *PullRequestsService) CreateComment(owner string, repo string, number int, comment *PullRequestComment) (*PullRequestComment, error) {
func (s *PullRequestsService) CreateComment(owner string, repo string, number int, comment *PullRequestComment) (*PullRequestComment, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/pulls/%d/comments", owner, repo, number) u := fmt.Sprintf("repos/%v/%v/pulls/%d/comments", owner, repo, number)
req, err := s.client.NewRequest("POST", u, comment) req, err := s.client.NewRequest("POST", u, comment)
if err != nil { if err != nil {
return nil, err
return nil, nil, err
} }
c := new(PullRequestComment) c := new(PullRequestComment)
_, err = s.client.Do(req, c)
return c, err
resp, err := s.client.Do(req, c)
return c, resp, err
} }
// EditComment updates a pull request comment. // EditComment updates a pull request comment.
// //
// GitHub API docs: https://developer.github.com/v3/pulls/comments/#edit-a-comment // GitHub API docs: https://developer.github.com/v3/pulls/comments/#edit-a-comment
func (s *PullRequestsService) EditComment(owner string, repo string, number int, comment *PullRequestComment) (*PullRequestComment, error) {
func (s *PullRequestsService) EditComment(owner string, repo string, number int, comment *PullRequestComment) (*PullRequestComment, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/pulls/comments/%d", owner, repo, number) u := fmt.Sprintf("repos/%v/%v/pulls/comments/%d", owner, repo, number)
req, err := s.client.NewRequest("PATCH", u, comment) req, err := s.client.NewRequest("PATCH", u, comment)
if err != nil { if err != nil {
return nil, err
return nil, nil, err
} }
c := new(PullRequestComment) c := new(PullRequestComment)
_, err = s.client.Do(req, c)
return c, err
resp, err := s.client.Do(req, c)
return c, resp, err
} }
// DeleteComment deletes a pull request comment. // DeleteComment deletes a pull request comment.
// //
// GitHub API docs: https://developer.github.com/v3/pulls/comments/#delete-a-comment // GitHub API docs: https://developer.github.com/v3/pulls/comments/#delete-a-comment
func (s *PullRequestsService) DeleteComment(owner string, repo string, number int) error {
func (s *PullRequestsService) DeleteComment(owner string, repo string, number int) (*Response, error) {
u := fmt.Sprintf("repos/%v/%v/pulls/comments/%d", owner, repo, number) u := fmt.Sprintf("repos/%v/%v/pulls/comments/%d", owner, repo, number)
req, err := s.client.NewRequest("DELETE", u, nil) req, err := s.client.NewRequest("DELETE", u, nil)
if err != nil { if err != nil {
return err
return nil, err
} }
_, err = s.client.Do(req, nil)
return err
return s.client.Do(req, nil)
} }

+ 11
- 11
github/pulls_comments_test.go View File

@ -31,7 +31,7 @@ func TestPullRequestsService_ListComments_allPulls(t *testing.T) {
opt := &PullRequestListCommentsOptions{"updated", "desc", opt := &PullRequestListCommentsOptions{"updated", "desc",
time.Date(2002, time.February, 10, 15, 30, 0, 0, time.UTC), time.Date(2002, time.February, 10, 15, 30, 0, 0, time.UTC),
} }
pulls, err := client.PullRequests.ListComments("o", "r", 0, opt)
pulls, _, err := client.PullRequests.ListComments("o", "r", 0, opt)
if err != nil { if err != nil {
t.Errorf("PullRequests.ListComments returned error: %v", err) t.Errorf("PullRequests.ListComments returned error: %v", err)
@ -52,7 +52,7 @@ func TestPullRequestsService_ListComments_specificPull(t *testing.T) {
fmt.Fprint(w, `[{"id":1}]`) fmt.Fprint(w, `[{"id":1}]`)
}) })
pulls, err := client.PullRequests.ListComments("o", "r", 1, nil)
pulls, _, err := client.PullRequests.ListComments("o", "r", 1, nil)
if err != nil { if err != nil {
t.Errorf("PullRequests.ListComments returned error: %v", err) t.Errorf("PullRequests.ListComments returned error: %v", err)
@ -65,7 +65,7 @@ func TestPullRequestsService_ListComments_specificPull(t *testing.T) {
} }
func TestPullRequestsService_ListComments_invalidOwner(t *testing.T) { func TestPullRequestsService_ListComments_invalidOwner(t *testing.T) {
_, err := client.PullRequests.ListComments("%", "r", 1, nil)
_, _, err := client.PullRequests.ListComments("%", "r", 1, nil)
testURLParseError(t, err) testURLParseError(t, err)
} }
@ -78,7 +78,7 @@ func TestPullRequestsService_GetComment(t *testing.T) {
fmt.Fprint(w, `{"id":1}`) fmt.Fprint(w, `{"id":1}`)
}) })
comment, err := client.PullRequests.GetComment("o", "r", 1)
comment, _, err := client.PullRequests.GetComment("o", "r", 1)
if err != nil { if err != nil {
t.Errorf("PullRequests.GetComment returned error: %v", err) t.Errorf("PullRequests.GetComment returned error: %v", err)
@ -91,7 +91,7 @@ func TestPullRequestsService_GetComment(t *testing.T) {
} }
func TestPullRequestsService_GetComment_invalidOwner(t *testing.T) { func TestPullRequestsService_GetComment_invalidOwner(t *testing.T) {
_, err := client.PullRequests.GetComment("%", "r", 1)
_, _, err := client.PullRequests.GetComment("%", "r", 1)
testURLParseError(t, err) testURLParseError(t, err)
} }
@ -113,7 +113,7 @@ func TestPullRequestsService_CreateComment(t *testing.T) {
fmt.Fprint(w, `{"id":1}`) fmt.Fprint(w, `{"id":1}`)
}) })
comment, err := client.PullRequests.CreateComment("o", "r", 1, input)
comment, _, err := client.PullRequests.CreateComment("o", "r", 1, input)
if err != nil { if err != nil {
t.Errorf("PullRequests.CreateComment returned error: %v", err) t.Errorf("PullRequests.CreateComment returned error: %v", err)
@ -126,7 +126,7 @@ func TestPullRequestsService_CreateComment(t *testing.T) {
} }
func TestPullRequestsService_CreateComment_invalidOwner(t *testing.T) { func TestPullRequestsService_CreateComment_invalidOwner(t *testing.T) {
_, err := client.PullRequests.CreateComment("%", "r", 1, nil)
_, _, err := client.PullRequests.CreateComment("%", "r", 1, nil)
testURLParseError(t, err) testURLParseError(t, err)
} }
@ -148,7 +148,7 @@ func TestPullRequestsService_EditComment(t *testing.T) {
fmt.Fprint(w, `{"id":1}`) fmt.Fprint(w, `{"id":1}`)
}) })
comment, err := client.PullRequests.EditComment("o", "r", 1, input)
comment, _, err := client.PullRequests.EditComment("o", "r", 1, input)
if err != nil { if err != nil {
t.Errorf("PullRequests.EditComment returned error: %v", err) t.Errorf("PullRequests.EditComment returned error: %v", err)
@ -161,7 +161,7 @@ func TestPullRequestsService_EditComment(t *testing.T) {
} }
func TestPullRequestsService_EditComment_invalidOwner(t *testing.T) { func TestPullRequestsService_EditComment_invalidOwner(t *testing.T) {
_, err := client.PullRequests.EditComment("%", "r", 1, nil)
_, _, err := client.PullRequests.EditComment("%", "r", 1, nil)
testURLParseError(t, err) testURLParseError(t, err)
} }
@ -173,13 +173,13 @@ func TestPullRequestsService_DeleteComment(t *testing.T) {
testMethod(t, r, "DELETE") testMethod(t, r, "DELETE")
}) })
err := client.PullRequests.DeleteComment("o", "r", 1)
_, err := client.PullRequests.DeleteComment("o", "r", 1)
if err != nil { if err != nil {
t.Errorf("PullRequests.DeleteComment returned error: %v", err) t.Errorf("PullRequests.DeleteComment returned error: %v", err)
} }
} }
func TestPullRequestsService_DeleteComment_invalidOwner(t *testing.T) { func TestPullRequestsService_DeleteComment_invalidOwner(t *testing.T) {
err := client.PullRequests.DeleteComment("%", "r", 1)
_, err := client.PullRequests.DeleteComment("%", "r", 1)
testURLParseError(t, err) testURLParseError(t, err)
} }

+ 8
- 8
github/pulls_test.go View File

@ -28,7 +28,7 @@ func TestPullRequestsService_List(t *testing.T) {
}) })
opt := &PullRequestListOptions{"closed", "h", "b"} opt := &PullRequestListOptions{"closed", "h", "b"}
pulls, err := client.PullRequests.List("o", "r", opt)
pulls, _, err := client.PullRequests.List("o", "r", opt)
if err != nil { if err != nil {
t.Errorf("PullRequests.List returned error: %v", err) t.Errorf("PullRequests.List returned error: %v", err)
@ -41,7 +41,7 @@ func TestPullRequestsService_List(t *testing.T) {
} }
func TestPullRequestsService_List_invalidOwner(t *testing.T) { func TestPullRequestsService_List_invalidOwner(t *testing.T) {
_, err := client.PullRequests.List("%", "r", nil)
_, _, err := client.PullRequests.List("%", "r", nil)
testURLParseError(t, err) testURLParseError(t, err)
} }
@ -54,7 +54,7 @@ func TestPullRequestsService_Get(t *testing.T) {
fmt.Fprint(w, `{"number":1}`) fmt.Fprint(w, `{"number":1}`)
}) })
pull, err := client.PullRequests.Get("o", "r", 1)
pull, _, err := client.PullRequests.Get("o", "r", 1)
if err != nil { if err != nil {
t.Errorf("PullRequests.Get returned error: %v", err) t.Errorf("PullRequests.Get returned error: %v", err)
@ -67,7 +67,7 @@ func TestPullRequestsService_Get(t *testing.T) {
} }
func TestPullRequestsService_Get_invalidOwner(t *testing.T) { func TestPullRequestsService_Get_invalidOwner(t *testing.T) {
_, err := client.PullRequests.Get("%", "r", 1)
_, _, err := client.PullRequests.Get("%", "r", 1)
testURLParseError(t, err) testURLParseError(t, err)
} }
@ -89,7 +89,7 @@ func TestPullRequestsService_Create(t *testing.T) {
fmt.Fprint(w, `{"number":1}`) fmt.Fprint(w, `{"number":1}`)
}) })
pull, err := client.PullRequests.Create("o", "r", input)
pull, _, err := client.PullRequests.Create("o", "r", input)
if err != nil { if err != nil {
t.Errorf("PullRequests.Create returned error: %v", err) t.Errorf("PullRequests.Create returned error: %v", err)
} }
@ -101,7 +101,7 @@ func TestPullRequestsService_Create(t *testing.T) {
} }
func TestPullRequestsService_Create_invalidOwner(t *testing.T) { func TestPullRequestsService_Create_invalidOwner(t *testing.T) {
_, err := client.PullRequests.Create("%", "r", nil)
_, _, err := client.PullRequests.Create("%", "r", nil)
testURLParseError(t, err) testURLParseError(t, err)
} }
@ -123,7 +123,7 @@ func TestPullRequestsService_Edit(t *testing.T) {
fmt.Fprint(w, `{"number":1}`) fmt.Fprint(w, `{"number":1}`)
}) })
pull, err := client.PullRequests.Edit("o", "r", 1, input)
pull, _, err := client.PullRequests.Edit("o", "r", 1, input)
if err != nil { if err != nil {
t.Errorf("PullRequests.Edit returned error: %v", err) t.Errorf("PullRequests.Edit returned error: %v", err)
} }
@ -135,6 +135,6 @@ func TestPullRequestsService_Edit(t *testing.T) {
} }
func TestPullRequestsService_Edit_invalidOwner(t *testing.T) { func TestPullRequestsService_Edit_invalidOwner(t *testing.T) {
_, err := client.PullRequests.Edit("%", "r", 1, nil)
_, _, err := client.PullRequests.Edit("%", "r", 1, nil)
testURLParseError(t, err) testURLParseError(t, err)
} }

+ 28
- 28
github/repos.go View File

@ -57,7 +57,7 @@ type RepositoryListOptions struct {
// repositories for the authenticated user. // repositories for the authenticated user.
// //
// GitHub API docs: http://developer.github.com/v3/repos/#list-user-repositories // GitHub API docs: http://developer.github.com/v3/repos/#list-user-repositories
func (s *RepositoriesService) List(user string, opt *RepositoryListOptions) ([]Repository, error) {
func (s *RepositoriesService) List(user string, opt *RepositoryListOptions) ([]Repository, *Response, error) {
var u string var u string
if user != "" { if user != "" {
u = fmt.Sprintf("users/%v/repos", user) u = fmt.Sprintf("users/%v/repos", user)
@ -76,12 +76,12 @@ func (s *RepositoriesService) List(user string, opt *RepositoryListOptions) ([]R
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
if err != nil { if err != nil {
return nil, err
return nil, nil, err
} }
repos := new([]Repository) repos := new([]Repository)
_, err = s.client.Do(req, repos)
return *repos, err
resp, err := s.client.Do(req, repos)
return *repos, resp, err
} }
// RepositoryListByOrgOptions specifies the optional parameters to the // RepositoryListByOrgOptions specifies the optional parameters to the
@ -98,7 +98,7 @@ type RepositoryListByOrgOptions struct {
// ListByOrg lists the repositories for an organization. // ListByOrg lists the repositories for an organization.
// //
// GitHub API docs: http://developer.github.com/v3/repos/#list-organization-repositories // GitHub API docs: http://developer.github.com/v3/repos/#list-organization-repositories
func (s *RepositoriesService) ListByOrg(org string, opt *RepositoryListByOrgOptions) ([]Repository, error) {
func (s *RepositoriesService) ListByOrg(org string, opt *RepositoryListByOrgOptions) ([]Repository, *Response, error) {
u := fmt.Sprintf("orgs/%v/repos", org) u := fmt.Sprintf("orgs/%v/repos", org)
if opt != nil { if opt != nil {
params := url.Values{ params := url.Values{
@ -110,12 +110,12 @@ func (s *RepositoriesService) ListByOrg(org string, opt *RepositoryListByOrgOpti
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
if err != nil { if err != nil {
return nil, err
return nil, nil, err
} }
repos := new([]Repository) repos := new([]Repository)
_, err = s.client.Do(req, repos)
return *repos, err
resp, err := s.client.Do(req, repos)
return *repos, resp, err
} }
// RepositoryListAllOptions specifies the optional parameters to the // RepositoryListAllOptions specifies the optional parameters to the
@ -128,7 +128,7 @@ type RepositoryListAllOptions struct {
// ListAll lists all GitHub repositories in the order that they were created. // ListAll lists all GitHub repositories in the order that they were created.
// //
// GitHub API docs: http://developer.github.com/v3/repos/#list-all-repositories // GitHub API docs: http://developer.github.com/v3/repos/#list-all-repositories
func (s *RepositoriesService) ListAll(opt *RepositoryListAllOptions) ([]Repository, error) {
func (s *RepositoriesService) ListAll(opt *RepositoryListAllOptions) ([]Repository, *Response, error) {
u := "repositories" u := "repositories"
if opt != nil { if opt != nil {
params := url.Values{ params := url.Values{
@ -139,12 +139,12 @@ func (s *RepositoriesService) ListAll(opt *RepositoryListAllOptions) ([]Reposito
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
if err != nil { if err != nil {
return nil, err
return nil, nil, err
} }
repos := new([]Repository) repos := new([]Repository)
_, err = s.client.Do(req, repos)
return *repos, err
resp, err := s.client.Do(req, repos)
return *repos, resp, err
} }
// Create a new repository. If an organization is specified, the new // Create a new repository. If an organization is specified, the new
@ -152,7 +152,7 @@ func (s *RepositoriesService) ListAll(opt *RepositoryListAllOptions) ([]Reposito
// specified, it will be created for the authenticated user. // specified, it will be created for the authenticated user.
// //
// GitHub API docs: http://developer.github.com/v3/repos/#create // GitHub API docs: http://developer.github.com/v3/repos/#create
func (s *RepositoriesService) Create(org string, repo *Repository) (*Repository, error) {
func (s *RepositoriesService) Create(org string, repo *Repository) (*Repository, *Response, error) {
var u string var u string
if org != "" { if org != "" {
u = fmt.Sprintf("orgs/%v/repos", org) u = fmt.Sprintf("orgs/%v/repos", org)
@ -162,40 +162,40 @@ func (s *RepositoriesService) Create(org string, repo *Repository) (*Repository,
req, err := s.client.NewRequest("POST", u, repo) req, err := s.client.NewRequest("POST", u, repo)
if err != nil { if err != nil {
return nil, err
return nil, nil, err
} }
r := new(Repository) r := new(Repository)
_, err = s.client.Do(req, r)
return r, err
resp, err := s.client.Do(req, r)
return r, resp, err
} }
// Get fetches a repository. // Get fetches a repository.
// //
// GitHub API docs: http://developer.github.com/v3/repos/#get // GitHub API docs: http://developer.github.com/v3/repos/#get
func (s *RepositoriesService) Get(owner, repo string) (*Repository, error) {
func (s *RepositoriesService) Get(owner, repo string) (*Repository, *Response, error) {
u := fmt.Sprintf("repos/%v/%v", owner, repo) u := fmt.Sprintf("repos/%v/%v", owner, repo)
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
if err != nil { if err != nil {
return nil, err
return nil, nil, err
} }
repository := new(Repository) repository := new(Repository)
_, err = s.client.Do(req, repository)
return repository, err
resp, err := s.client.Do(req, repository)
return repository, resp, err
} }
// Edit updates a repository. // Edit updates a repository.
// //
// GitHub API docs: http://developer.github.com/v3/repos/#edit // GitHub API docs: http://developer.github.com/v3/repos/#edit
func (s *RepositoriesService) Edit(owner, repo string, repository *Repository) (*Repository, error) {
func (s *RepositoriesService) Edit(owner, repo string, repository *Repository) (*Repository, *Response, error) {
u := fmt.Sprintf("repos/%v/%v", owner, repo) u := fmt.Sprintf("repos/%v/%v", owner, repo)
req, err := s.client.NewRequest("PATCH", u, repository) req, err := s.client.NewRequest("PATCH", u, repository)
if err != nil { if err != nil {
return nil, err
return nil, nil, err
} }
r := new(Repository) r := new(Repository)
_, err = s.client.Do(req, r)
return r, err
resp, err := s.client.Do(req, r)
return r, resp, err
} }
// ListLanguages lists languages for the specified repository. The returned map // ListLanguages lists languages for the specified repository. The returned map
@ -208,14 +208,14 @@ func (s *RepositoriesService) Edit(owner, repo string, repository *Repository) (
// } // }
// //
// GitHub API Docs: http://developer.github.com/v3/repos/#list-languages // GitHub API Docs: http://developer.github.com/v3/repos/#list-languages
func (s *RepositoriesService) ListLanguages(owner string, repository string) (map[string]int, error) {
func (s *RepositoriesService) ListLanguages(owner string, repository string) (map[string]int, *Response, error) {
u := fmt.Sprintf("/repos/%v/%v/languages", owner, repository) u := fmt.Sprintf("/repos/%v/%v/languages", owner, repository)
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
if err != nil { if err != nil {
return nil, err
return nil, nil, err
} }
languages := make(map[string]int) languages := make(map[string]int)
_, err = s.client.Do(req, &languages)
return languages, err
resp, err := s.client.Do(req, &languages)
return languages, resp, err
} }

+ 8
- 8
github/repos_forks.go View File

@ -21,7 +21,7 @@ type RepositoryListForksOptions struct {
// ListForks lists the forks of the specified repository. // ListForks lists the forks of the specified repository.
// //
// GitHub API docs: http://developer.github.com/v3/repos/forks/#list-forks // GitHub API docs: http://developer.github.com/v3/repos/forks/#list-forks
func (s *RepositoriesService) ListForks(owner, repo string, opt *RepositoryListForksOptions) ([]Repository, error) {
func (s *RepositoriesService) ListForks(owner, repo string, opt *RepositoryListForksOptions) ([]Repository, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/forks", owner, repo) u := fmt.Sprintf("repos/%v/%v/forks", owner, repo)
if opt != nil { if opt != nil {
params := url.Values{ params := url.Values{
@ -32,12 +32,12 @@ func (s *RepositoriesService) ListForks(owner, repo string, opt *RepositoryListF
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
if err != nil { if err != nil {
return nil, err
return nil, nil, err
} }
repos := new([]Repository) repos := new([]Repository)
_, err = s.client.Do(req, repos)
return *repos, err
resp, err := s.client.Do(req, repos)
return *repos, resp, err
} }
// RepositoryCreateForkOptions specifies the optional parameters to the // RepositoryCreateForkOptions specifies the optional parameters to the
@ -50,7 +50,7 @@ type RepositoryCreateForkOptions struct {
// CreateFork creates a fork of the specified repository. // CreateFork creates a fork of the specified repository.
// //
// GitHub API docs: http://developer.github.com/v3/repos/forks/#list-forks // GitHub API docs: http://developer.github.com/v3/repos/forks/#list-forks
func (s *RepositoriesService) CreateFork(owner, repo string, opt *RepositoryCreateForkOptions) (*Repository, error) {
func (s *RepositoriesService) CreateFork(owner, repo string, opt *RepositoryCreateForkOptions) (*Repository, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/forks", owner, repo) u := fmt.Sprintf("repos/%v/%v/forks", owner, repo)
if opt != nil { if opt != nil {
params := url.Values{ params := url.Values{
@ -61,10 +61,10 @@ func (s *RepositoriesService) CreateFork(owner, repo string, opt *RepositoryCrea
req, err := s.client.NewRequest("POST", u, nil) req, err := s.client.NewRequest("POST", u, nil)
if err != nil { if err != nil {
return nil, err
return nil, nil, err
} }
fork := new(Repository) fork := new(Repository)
_, err = s.client.Do(req, fork)
return fork, err
resp, err := s.client.Do(req, fork)
return fork, resp, err
} }

+ 4
- 4
github/repos_forks_test.go View File

@ -23,7 +23,7 @@ func TestRepositoriesService_ListForks(t *testing.T) {
}) })
opt := &RepositoryListForksOptions{Sort: "newest"} opt := &RepositoryListForksOptions{Sort: "newest"}
repos, err := client.Repositories.ListForks("o", "r", opt)
repos, _, err := client.Repositories.ListForks("o", "r", opt)
if err != nil { if err != nil {
t.Errorf("Repositories.ListForks returned error: %v", err) t.Errorf("Repositories.ListForks returned error: %v", err)
} }
@ -35,7 +35,7 @@ func TestRepositoriesService_ListForks(t *testing.T) {
} }
func TestRepositoriesService_ListForks_invalidOwner(t *testing.T) { func TestRepositoriesService_ListForks_invalidOwner(t *testing.T) {
_, err := client.Repositories.ListForks("%", "r", nil)
_, _, err := client.Repositories.ListForks("%", "r", nil)
testURLParseError(t, err) testURLParseError(t, err)
} }
@ -50,7 +50,7 @@ func TestRepositoriesService_CreateFork(t *testing.T) {
}) })
opt := &RepositoryCreateForkOptions{Organization: "o"} opt := &RepositoryCreateForkOptions{Organization: "o"}
repo, err := client.Repositories.CreateFork("o", "r", opt)
repo, _, err := client.Repositories.CreateFork("o", "r", opt)
if err != nil { if err != nil {
t.Errorf("Repositories.CreateFork returned error: %v", err) t.Errorf("Repositories.CreateFork returned error: %v", err)
} }
@ -62,6 +62,6 @@ func TestRepositoriesService_CreateFork(t *testing.T) {
} }
func TestRepositoriesService_CreateFork_invalidOwner(t *testing.T) { func TestRepositoriesService_CreateFork_invalidOwner(t *testing.T) {
_, err := client.Repositories.CreateFork("%", "r", nil)
_, _, err := client.Repositories.CreateFork("%", "r", nil)
testURLParseError(t, err) testURLParseError(t, err)
} }

+ 22
- 24
github/repos_hooks.go View File

@ -70,21 +70,21 @@ type Hook struct {
// Name and Config are required fields. // Name and Config are required fields.
// //
// GitHub API docs: http://developer.github.com/v3/repos/hooks/#create-a-hook // GitHub API docs: http://developer.github.com/v3/repos/hooks/#create-a-hook
func (s *RepositoriesService) CreateHook(owner, repo string, hook *Hook) (*Hook, error) {
func (s *RepositoriesService) CreateHook(owner, repo string, hook *Hook) (*Hook, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/hooks", owner, repo) u := fmt.Sprintf("repos/%v/%v/hooks", owner, repo)
req, err := s.client.NewRequest("POST", u, hook) req, err := s.client.NewRequest("POST", u, hook)
if err != nil { if err != nil {
return nil, err
return nil, nil, err
} }
h := new(Hook) h := new(Hook)
_, err = s.client.Do(req, h)
return h, err
resp, err := s.client.Do(req, h)
return h, resp, err
} }
// ListHooks lists all Hooks for the specified repository. // ListHooks lists all Hooks for the specified repository.
// //
// GitHub API docs: http://developer.github.com/v3/repos/hooks/#list // GitHub API docs: http://developer.github.com/v3/repos/hooks/#list
func (s *RepositoriesService) ListHooks(owner, repo string, opt *ListOptions) ([]Hook, error) {
func (s *RepositoriesService) ListHooks(owner, repo string, opt *ListOptions) ([]Hook, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/hooks", owner, repo) u := fmt.Sprintf("repos/%v/%v/hooks", owner, repo)
if opt != nil { if opt != nil {
@ -96,64 +96,62 @@ func (s *RepositoriesService) ListHooks(owner, repo string, opt *ListOptions) ([
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
if err != nil { if err != nil {
return nil, err
return nil, nil, err
} }
hooks := new([]Hook) hooks := new([]Hook)
_, err = s.client.Do(req, hooks)
return *hooks, err
resp, err := s.client.Do(req, hooks)
return *hooks, resp, err
} }
// GetHook returns a single specified Hook. // GetHook returns a single specified Hook.
// //
// GitHub API docs: http://developer.github.com/v3/repos/hooks/#get-single-hook // GitHub API docs: http://developer.github.com/v3/repos/hooks/#get-single-hook
func (s *RepositoriesService) GetHook(owner, repo string, id int) (*Hook, error) {
func (s *RepositoriesService) GetHook(owner, repo string, id int) (*Hook, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/hooks/%d", owner, repo, id) u := fmt.Sprintf("repos/%v/%v/hooks/%d", owner, repo, id)
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
if err != nil { if err != nil {
return nil, err
return nil, nil, err
} }
hook := new(Hook) hook := new(Hook)
_, err = s.client.Do(req, hook)
return hook, err
resp, err := s.client.Do(req, hook)
return hook, resp, err
} }
// EditHook updates a specified Hook. // EditHook updates a specified Hook.
// //
// GitHub API docs: http://developer.github.com/v3/repos/hooks/#edit-a-hook // GitHub API docs: http://developer.github.com/v3/repos/hooks/#edit-a-hook
func (s *RepositoriesService) EditHook(owner, repo string, id int, hook *Hook) (*Hook, error) {
func (s *RepositoriesService) EditHook(owner, repo string, id int, hook *Hook) (*Hook, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/hooks/%d", owner, repo, id) u := fmt.Sprintf("repos/%v/%v/hooks/%d", owner, repo, id)
req, err := s.client.NewRequest("PATCH", u, hook) req, err := s.client.NewRequest("PATCH", u, hook)
if err != nil { if err != nil {
return nil, err
return nil, nil, err
} }
h := new(Hook) h := new(Hook)
_, err = s.client.Do(req, h)
return h, err
resp, err := s.client.Do(req, h)
return h, resp, err
} }
// DeleteHook deletes a specified Hook. // DeleteHook deletes a specified Hook.
// //
// GitHub API docs: http://developer.github.com/v3/repos/hooks/#delete-a-hook // GitHub API docs: http://developer.github.com/v3/repos/hooks/#delete-a-hook
func (s *RepositoriesService) DeleteHook(owner, repo string, id int) error {
func (s *RepositoriesService) DeleteHook(owner, repo string, id int) (*Response, error) {
u := fmt.Sprintf("repos/%v/%v/hooks/%d", owner, repo, id) u := fmt.Sprintf("repos/%v/%v/hooks/%d", owner, repo, id)
req, err := s.client.NewRequest("DELETE", u, nil) req, err := s.client.NewRequest("DELETE", u, nil)
if err != nil { if err != nil {
return err
return nil, err
} }
_, err = s.client.Do(req, nil)
return err
return s.client.Do(req, nil)
} }
// TestHook triggers a test Hook by github. // TestHook triggers a test Hook by github.
// //
// GitHub API docs: http://developer.github.com/v3/repos/hooks/#test-a-push-hook // GitHub API docs: http://developer.github.com/v3/repos/hooks/#test-a-push-hook
func (s *RepositoriesService) TestHook(owner, repo string, id int) error {
func (s *RepositoriesService) TestHook(owner, repo string, id int) (*Response, error) {
u := fmt.Sprintf("repos/%v/%v/hooks/%d/tests", owner, repo, id) u := fmt.Sprintf("repos/%v/%v/hooks/%d/tests", owner, repo, id)
req, err := s.client.NewRequest("POST", u, nil) req, err := s.client.NewRequest("POST", u, nil)
if err != nil { if err != nil {
return err
return nil, err
} }
_, err = s.client.Do(req, nil)
return err
return s.client.Do(req, nil)
} }

+ 6
- 6
github/repos_hooks_test.go View File

@ -31,7 +31,7 @@ func TestRepositoriesService_CreateHook(t *testing.T) {
fmt.Fprint(w, `{"id":1}`) fmt.Fprint(w, `{"id":1}`)
}) })
hook, err := client.Repositories.CreateHook("o", "r", input)
hook, _, err := client.Repositories.CreateHook("o", "r", input)
if err != nil { if err != nil {
t.Errorf("Repositories.CreateHook returned error: %v", err) t.Errorf("Repositories.CreateHook returned error: %v", err)
} }
@ -54,7 +54,7 @@ func TestRepositoriesService_ListHooks(t *testing.T) {
opt := &ListOptions{2} opt := &ListOptions{2}
hooks, err := client.Repositories.ListHooks("o", "r", opt)
hooks, _, err := client.Repositories.ListHooks("o", "r", opt)
if err != nil { if err != nil {
t.Errorf("Repositories.ListHooks returned error: %v", err) t.Errorf("Repositories.ListHooks returned error: %v", err)
} }
@ -74,7 +74,7 @@ func TestRepositoriesService_GetHook(t *testing.T) {
fmt.Fprint(w, `{"id":1}`) fmt.Fprint(w, `{"id":1}`)
}) })
hook, err := client.Repositories.GetHook("o", "r", 1)
hook, _, err := client.Repositories.GetHook("o", "r", 1)
if err != nil { if err != nil {
t.Errorf("Repositories.GetHook returned error: %v", err) t.Errorf("Repositories.GetHook returned error: %v", err)
} }
@ -103,7 +103,7 @@ func TestRepositoriesService_EditHook(t *testing.T) {
fmt.Fprint(w, `{"id":1}`) fmt.Fprint(w, `{"id":1}`)
}) })
hook, err := client.Repositories.EditHook("o", "r", 1, input)
hook, _, err := client.Repositories.EditHook("o", "r", 1, input)
if err != nil { if err != nil {
t.Errorf("Repositories.EditHook returned error: %v", err) t.Errorf("Repositories.EditHook returned error: %v", err)
} }
@ -122,7 +122,7 @@ func TestRepositoriesService_DeleteHook(t *testing.T) {
testMethod(t, r, "DELETE") testMethod(t, r, "DELETE")
}) })
err := client.Repositories.DeleteHook("o", "r", 1)
_, err := client.Repositories.DeleteHook("o", "r", 1)
if err != nil { if err != nil {
t.Errorf("Repositories.DeleteHook returned error: %v", err) t.Errorf("Repositories.DeleteHook returned error: %v", err)
} }
@ -136,7 +136,7 @@ func TestRepositoriesService_TestHook(t *testing.T) {
testMethod(t, r, "POST") testMethod(t, r, "POST")
}) })
err := client.Repositories.TestHook("o", "r", 1)
_, err := client.Repositories.TestHook("o", "r", 1)
if err != nil { if err != nil {
t.Errorf("Repositories.TestHook returned error: %v", err) t.Errorf("Repositories.TestHook returned error: %v", err)
} }


+ 8
- 8
github/repos_statuses.go View File

@ -34,30 +34,30 @@ type RepoStatus struct {
// 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, error) {
func (s *RepositoriesService) ListStatuses(owner, repo, ref string) ([]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)
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
if err != nil { if err != nil {
return nil, err
return nil, nil, err
} }
statuses := new([]RepoStatus) statuses := new([]RepoStatus)
_, err = s.client.Do(req, statuses)
return *statuses, err
resp, err := s.client.Do(req, statuses)
return *statuses, resp, err
} }
// CreateStatus creates a new status for a repository at the specified // CreateStatus creates a new status for a repository at the specified
// 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/#create-a-status // GitHub API docs: http://developer.github.com/v3/repos/statuses/#create-a-status
func (s *RepositoriesService) CreateStatus(owner, repo, ref string, status *RepoStatus) (*RepoStatus, error) {
func (s *RepositoriesService) CreateStatus(owner, repo, ref string, status *RepoStatus) (*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)
req, err := s.client.NewRequest("POST", u, status) req, err := s.client.NewRequest("POST", u, status)
if err != nil { if err != nil {
return nil, err
return nil, nil, err
} }
statuses := new(RepoStatus) statuses := new(RepoStatus)
_, err = s.client.Do(req, statuses)
return statuses, err
resp, err := s.client.Do(req, statuses)
return statuses, resp, err
} }

+ 4
- 4
github/repos_statuses_test.go View File

@ -22,7 +22,7 @@ func TestRepositoriesService_ListStatuses(t *testing.T) {
fmt.Fprint(w, `[{"id":1}]`) fmt.Fprint(w, `[{"id":1}]`)
}) })
statuses, err := client.Repositories.ListStatuses("o", "r", "r")
statuses, _, err := client.Repositories.ListStatuses("o", "r", "r")
if err != nil { if err != nil {
t.Errorf("Repositories.ListStatuses returned error: %v", err) t.Errorf("Repositories.ListStatuses returned error: %v", err)
} }
@ -34,7 +34,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")
testURLParseError(t, err) testURLParseError(t, err)
} }
@ -55,7 +55,7 @@ func TestRepositoriesService_CreateStatus(t *testing.T) {
fmt.Fprint(w, `{"id":1}`) fmt.Fprint(w, `{"id":1}`)
}) })
status, err := client.Repositories.CreateStatus("o", "r", "r", input)
status, _, err := client.Repositories.CreateStatus("o", "r", "r", input)
if err != nil { if err != nil {
t.Errorf("Repositories.CreateStatus returned error: %v", err) t.Errorf("Repositories.CreateStatus returned error: %v", err)
} }
@ -67,6 +67,6 @@ func TestRepositoriesService_CreateStatus(t *testing.T) {
} }
func TestRepositoriesService_CreateStatus_invalidOwner(t *testing.T) { func TestRepositoriesService_CreateStatus_invalidOwner(t *testing.T) {
_, err := client.Repositories.CreateStatus("%", "r", "r", nil)
_, _, err := client.Repositories.CreateStatus("%", "r", "r", nil)
testURLParseError(t, err) testURLParseError(t, err)
} }

+ 14
- 14
github/repos_test.go View File

@ -22,7 +22,7 @@ func TestRepositoriesService_List_authenticatedUser(t *testing.T) {
fmt.Fprint(w, `[{"id":1},{"id":2}]`) fmt.Fprint(w, `[{"id":1},{"id":2}]`)
}) })
repos, err := client.Repositories.List("", nil)
repos, _, err := client.Repositories.List("", nil)
if err != nil { if err != nil {
t.Errorf("Repositories.List returned error: %v", err) t.Errorf("Repositories.List returned error: %v", err)
} }
@ -50,7 +50,7 @@ func TestRepositoriesService_List_specifiedUser(t *testing.T) {
}) })
opt := &RepositoryListOptions{"owner", "created", "asc", 2} opt := &RepositoryListOptions{"owner", "created", "asc", 2}
repos, err := client.Repositories.List("u", opt)
repos, _, err := client.Repositories.List("u", opt)
if err != nil { if err != nil {
t.Errorf("Repositories.List returned error: %v", err) t.Errorf("Repositories.List returned error: %v", err)
} }
@ -62,7 +62,7 @@ func TestRepositoriesService_List_specifiedUser(t *testing.T) {
} }
func TestRepositoriesService_List_invalidUser(t *testing.T) { func TestRepositoriesService_List_invalidUser(t *testing.T) {
_, err := client.Repositories.List("%", nil)
_, _, err := client.Repositories.List("%", nil)
testURLParseError(t, err) testURLParseError(t, err)
} }
@ -80,7 +80,7 @@ func TestRepositoriesService_ListByOrg(t *testing.T) {
}) })
opt := &RepositoryListByOrgOptions{"forks", 2} opt := &RepositoryListByOrgOptions{"forks", 2}
repos, err := client.Repositories.ListByOrg("o", opt)
repos, _, err := client.Repositories.ListByOrg("o", opt)
if err != nil { if err != nil {
t.Errorf("Repositories.ListByOrg returned error: %v", err) t.Errorf("Repositories.ListByOrg returned error: %v", err)
} }
@ -92,7 +92,7 @@ func TestRepositoriesService_ListByOrg(t *testing.T) {
} }
func TestRepositoriesService_ListByOrg_invalidOrg(t *testing.T) { func TestRepositoriesService_ListByOrg_invalidOrg(t *testing.T) {
_, err := client.Repositories.ListByOrg("%", nil)
_, _, err := client.Repositories.ListByOrg("%", nil)
testURLParseError(t, err) testURLParseError(t, err)
} }
@ -107,7 +107,7 @@ func TestRepositoriesService_ListAll(t *testing.T) {
}) })
opt := &RepositoryListAllOptions{1} opt := &RepositoryListAllOptions{1}
repos, err := client.Repositories.ListAll(opt)
repos, _, err := client.Repositories.ListAll(opt)
if err != nil { if err != nil {
t.Errorf("Repositories.ListAll returned error: %v", err) t.Errorf("Repositories.ListAll returned error: %v", err)
} }
@ -136,7 +136,7 @@ func TestRepositoriesService_Create_user(t *testing.T) {
fmt.Fprint(w, `{"id":1}`) fmt.Fprint(w, `{"id":1}`)
}) })
repo, err := client.Repositories.Create("", input)
repo, _, err := client.Repositories.Create("", input)
if err != nil { if err != nil {
t.Errorf("Repositories.Create returned error: %v", err) t.Errorf("Repositories.Create returned error: %v", err)
} }
@ -165,7 +165,7 @@ func TestRepositoriesService_Create_org(t *testing.T) {
fmt.Fprint(w, `{"id":1}`) fmt.Fprint(w, `{"id":1}`)
}) })
repo, err := client.Repositories.Create("o", input)
repo, _, err := client.Repositories.Create("o", input)
if err != nil { if err != nil {
t.Errorf("Repositories.Create returned error: %v", err) t.Errorf("Repositories.Create returned error: %v", err)
} }
@ -177,7 +177,7 @@ func TestRepositoriesService_Create_org(t *testing.T) {
} }
func TestRepositoriesService_Create_invalidOrg(t *testing.T) { func TestRepositoriesService_Create_invalidOrg(t *testing.T) {
_, err := client.Repositories.Create("%", nil)
_, _, err := client.Repositories.Create("%", nil)
testURLParseError(t, err) testURLParseError(t, err)
} }
@ -190,7 +190,7 @@ func TestRepositoriesService_Get(t *testing.T) {
fmt.Fprint(w, `{"id":1,"name":"n","description":"d","owner":{"login":"l"}}`) fmt.Fprint(w, `{"id":1,"name":"n","description":"d","owner":{"login":"l"}}`)
}) })
repo, err := client.Repositories.Get("o", "r")
repo, _, err := client.Repositories.Get("o", "r")
if err != nil { if err != nil {
t.Errorf("Repositories.Get returned error: %v", err) t.Errorf("Repositories.Get returned error: %v", err)
} }
@ -219,7 +219,7 @@ func TestRepositoriesService_Edit(t *testing.T) {
fmt.Fprint(w, `{"id":1}`) fmt.Fprint(w, `{"id":1}`)
}) })
repo, err := client.Repositories.Edit("o", "r", input)
repo, _, err := client.Repositories.Edit("o", "r", input)
if err != nil { if err != nil {
t.Errorf("Repositories.Edit returned error: %v", err) t.Errorf("Repositories.Edit returned error: %v", err)
} }
@ -231,12 +231,12 @@ func TestRepositoriesService_Edit(t *testing.T) {
} }
func TestRepositoriesService_Get_invalidOwner(t *testing.T) { func TestRepositoriesService_Get_invalidOwner(t *testing.T) {
_, err := client.Repositories.Get("%", "r")
_, _, err := client.Repositories.Get("%", "r")
testURLParseError(t, err) testURLParseError(t, err)
} }
func TestRepositoriesService_Edit_invalidOwner(t *testing.T) { func TestRepositoriesService_Edit_invalidOwner(t *testing.T) {
_, err := client.Repositories.Edit("%", "r", nil)
_, _, err := client.Repositories.Edit("%", "r", nil)
testURLParseError(t, err) testURLParseError(t, err)
} }
@ -249,7 +249,7 @@ func TestRepositoriesService_ListLanguages(t *testing.T) {
fmt.Fprint(w, `{"go":1}`) fmt.Fprint(w, `{"go":1}`)
}) })
languages, err := client.Repositories.ListLanguages("u", "r")
languages, _, err := client.Repositories.ListLanguages("u", "r")
if err != nil { if err != nil {
t.Errorf("Repositories.ListLanguages returned error: %v", err) t.Errorf("Repositories.ListLanguages returned error: %v", err)
} }


+ 12
- 12
github/users.go View File

@ -43,7 +43,7 @@ type User struct {
// user. // user.
// //
// GitHub API docs: http://developer.github.com/v3/users/#get-a-single-user // GitHub API docs: http://developer.github.com/v3/users/#get-a-single-user
func (s *UsersService) Get(user string) (*User, error) {
func (s *UsersService) Get(user string) (*User, *Response, error) {
var u string var u string
if user != "" { if user != "" {
u = fmt.Sprintf("users/%v", user) u = fmt.Sprintf("users/%v", user)
@ -52,27 +52,27 @@ func (s *UsersService) Get(user string) (*User, error) {
} }
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
if err != nil { if err != nil {
return nil, err
return nil, nil, err
} }
uResp := new(User) uResp := new(User)
_, err = s.client.Do(req, uResp)
return uResp, err
resp, err := s.client.Do(req, uResp)
return uResp, resp, err
} }
// Edit the authenticated user. // Edit the authenticated user.
// //
// GitHub API docs: http://developer.github.com/v3/users/#update-the-authenticated-user // GitHub API docs: http://developer.github.com/v3/users/#update-the-authenticated-user
func (s *UsersService) Edit(user *User) (*User, error) {
func (s *UsersService) Edit(user *User) (*User, *Response, error) {
u := "user" u := "user"
req, err := s.client.NewRequest("PATCH", u, user) req, err := s.client.NewRequest("PATCH", u, user)
if err != nil { if err != nil {
return nil, err
return nil, nil, err
} }
uResp := new(User) uResp := new(User)
_, err = s.client.Do(req, uResp)
return uResp, err
resp, err := s.client.Do(req, uResp)
return uResp, resp, err
} }
// UserListOptions specifies optional parameters to the UsersService.List // UserListOptions specifies optional parameters to the UsersService.List
@ -85,7 +85,7 @@ type UserListOptions struct {
// ListAll lists all GitHub users. // ListAll lists all GitHub users.
// //
// GitHub API docs: http://developer.github.com/v3/users/#get-all-users // GitHub API docs: http://developer.github.com/v3/users/#get-all-users
func (s *UsersService) ListAll(opt *UserListOptions) ([]User, error) {
func (s *UsersService) ListAll(opt *UserListOptions) ([]User, *Response, error) {
u := "users" u := "users"
if opt != nil { if opt != nil {
params := url.Values{ params := url.Values{
@ -96,10 +96,10 @@ func (s *UsersService) ListAll(opt *UserListOptions) ([]User, error) {
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
if err != nil { if err != nil {
return nil, err
return nil, nil, err
} }
users := new([]User) users := new([]User)
_, err = s.client.Do(req, users)
return *users, err
resp, err := s.client.Do(req, users)
return *users, resp, err
} }

+ 11
- 12
github/users_emails.go View File

@ -11,43 +11,42 @@ type UserEmail string
// ListEmails lists all authenticated user email addresses // ListEmails lists all authenticated user email addresses
// //
// 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, error) {
func (s *UsersService) ListEmails() ([]UserEmail, *Response, error) {
u := "user/emails" u := "user/emails"
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
if err != nil { if err != nil {
return nil, err
return nil, nil, err
} }
emails := new([]UserEmail) emails := new([]UserEmail)
_, err = s.client.Do(req, emails)
return *emails, err
resp, err := s.client.Do(req, emails)
return *emails, resp, err
} }
// AddEmails adds email addresses of authenticated user // AddEmails adds email addresses of authenticated user
// //
// GitHub API docs: http://developer.github.com/v3/users/emails/#add-email-addresses // GitHub API docs: http://developer.github.com/v3/users/emails/#add-email-addresses
func (s *UsersService) AddEmails(emails []UserEmail) ([]UserEmail, error) {
func (s *UsersService) AddEmails(emails []UserEmail) ([]UserEmail, *Response, error) {
u := "user/emails" u := "user/emails"
req, err := s.client.NewRequest("POST", u, emails) req, err := s.client.NewRequest("POST", u, emails)
if err != nil { if err != nil {
return nil, err
return nil, nil, err
} }
e := new([]UserEmail) e := new([]UserEmail)
_, err = s.client.Do(req, e)
return *e, err
resp, err := s.client.Do(req, e)
return *e, resp, err
} }
// DeleteEmails deletes email addresses from authenticated user // DeleteEmails deletes email addresses from authenticated user
// //
// GitHub API docs: http://developer.github.com/v3/users/emails/#delete-email-addresses // GitHub API docs: http://developer.github.com/v3/users/emails/#delete-email-addresses
func (s *UsersService) DeleteEmails(emails []UserEmail) error {
func (s *UsersService) DeleteEmails(emails []UserEmail) (*Response, error) {
u := "user/emails" u := "user/emails"
req, err := s.client.NewRequest("DELETE", u, emails) req, err := s.client.NewRequest("DELETE", u, emails)
if err != nil { if err != nil {
return err
return nil, err
} }
_, err = s.client.Do(req, nil)
return err
return s.client.Do(req, nil)
} }

+ 3
- 3
github/users_emails_test.go View File

@ -22,7 +22,7 @@ func TestUsersService_ListEmails(t *testing.T) {
fmt.Fprint(w, `["user@example.com"]`) fmt.Fprint(w, `["user@example.com"]`)
}) })
emails, err := client.Users.ListEmails()
emails, _, err := client.Users.ListEmails()
if err != nil { if err != nil {
t.Errorf("Users.ListEmails returned error: %v", err) t.Errorf("Users.ListEmails returned error: %v", err)
} }
@ -51,7 +51,7 @@ func TestUsersService_AddEmails(t *testing.T) {
fmt.Fprint(w, `["old@example.com", "new@example.com"]`) fmt.Fprint(w, `["old@example.com", "new@example.com"]`)
}) })
emails, err := client.Users.AddEmails(input)
emails, _, err := client.Users.AddEmails(input)
if err != nil { if err != nil {
t.Errorf("Users.AddEmails returned error: %v", err) t.Errorf("Users.AddEmails returned error: %v", err)
} }
@ -78,7 +78,7 @@ func TestUsersService_DeleteEmails(t *testing.T) {
} }
}) })
err := client.Users.DeleteEmails(input)
_, err := client.Users.DeleteEmails(input)
if err != nil { if err != nil {
t.Errorf("Users.DeleteEmails returned error: %v", err) t.Errorf("Users.DeleteEmails returned error: %v", err)
} }


+ 5
- 5
github/users_test.go View File

@ -22,7 +22,7 @@ func TestUsersService_Get_authenticatedUser(t *testing.T) {
fmt.Fprint(w, `{"id":1}`) fmt.Fprint(w, `{"id":1}`)
}) })
user, err := client.Users.Get("")
user, _, err := client.Users.Get("")
if err != nil { if err != nil {
t.Errorf("Users.Get returned error: %v", err) t.Errorf("Users.Get returned error: %v", err)
} }
@ -42,7 +42,7 @@ func TestUsersService_Get_specifiedUser(t *testing.T) {
fmt.Fprint(w, `{"id":1}`) fmt.Fprint(w, `{"id":1}`)
}) })
user, err := client.Users.Get("u")
user, _, err := client.Users.Get("u")
if err != nil { if err != nil {
t.Errorf("Users.Get returned error: %v", err) t.Errorf("Users.Get returned error: %v", err)
} }
@ -54,7 +54,7 @@ func TestUsersService_Get_specifiedUser(t *testing.T) {
} }
func TestUsersService_Get_invalidUser(t *testing.T) { func TestUsersService_Get_invalidUser(t *testing.T) {
_, err := client.Users.Get("%")
_, _, err := client.Users.Get("%")
testURLParseError(t, err) testURLParseError(t, err)
} }
@ -76,7 +76,7 @@ func TestUsersService_Edit(t *testing.T) {
fmt.Fprint(w, `{"id":1}`) fmt.Fprint(w, `{"id":1}`)
}) })
user, err := client.Users.Edit(input)
user, _, err := client.Users.Edit(input)
if err != nil { if err != nil {
t.Errorf("Users.Edit returned error: %v", err) t.Errorf("Users.Edit returned error: %v", err)
} }
@ -98,7 +98,7 @@ func TestUsersService_ListAll(t *testing.T) {
}) })
opt := &UserListOptions{1} opt := &UserListOptions{1}
users, err := client.Users.ListAll(opt)
users, _, err := client.Users.ListAll(opt)
if err != nil { if err != nil {
t.Errorf("Users.Get returned error: %v", err) t.Errorf("Users.Get returned error: %v", err)
} }


Loading…
Cancel
Save