1
0
Fork 0
mirror of https://github.com/documize/community.git synced 2025-07-20 21:59:42 +02:00
Migrated from plain /vendor to go dep
This commit is contained in:
Harvey Kandola 2018-02-14 15:23:46 +00:00
parent 0262763c95
commit fd693f4ff4
957 changed files with 36866 additions and 177595 deletions

View file

@ -5,20 +5,21 @@
package github
import "fmt"
import (
"context"
"fmt"
)
// UsersService handles communication with the user related
// methods of the GitHub API.
//
// GitHub API docs: http://developer.github.com/v3/users/
type UsersService struct {
client *Client
}
// GitHub API docs: https://developer.github.com/v3/users/
type UsersService service
// User represents a GitHub user.
type User struct {
Login *string `json:"login,omitempty"`
ID *int `json:"id,omitempty"`
ID *int64 `json:"id,omitempty"`
AvatarURL *string `json:"avatar_url,omitempty"`
HTMLURL *string `json:"html_url,omitempty"`
GravatarID *string `json:"gravatar_id,omitempty"`
@ -70,11 +71,11 @@ func (u User) String() string {
return Stringify(u)
}
// Get fetches a user. Passing the empty string will fetch the authenticated
// Get fetches a user. Passing the empty string will fetch the authenticated
// user.
//
// GitHub API docs: http://developer.github.com/v3/users/#get-a-single-user
func (s *UsersService) Get(user string) (*User, *Response, error) {
// GitHub API docs: https://developer.github.com/v3/users/#get-a-single-user
func (s *UsersService) Get(ctx context.Context, user string) (*User, *Response, error) {
var u string
if user != "" {
u = fmt.Sprintf("users/%v", user)
@ -87,18 +88,18 @@ func (s *UsersService) Get(user string) (*User, *Response, error) {
}
uResp := new(User)
resp, err := s.client.Do(req, uResp)
resp, err := s.client.Do(ctx, req, uResp)
if err != nil {
return nil, resp, err
}
return uResp, resp, err
return uResp, resp, nil
}
// GetByID fetches a user.
//
// Note: GetByID uses the undocumented GitHub API endpoint /user/:id.
func (s *UsersService) GetByID(id int) (*User, *Response, error) {
func (s *UsersService) GetByID(ctx context.Context, id int64) (*User, *Response, error) {
u := fmt.Sprintf("user/%d", id)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
@ -106,18 +107,18 @@ func (s *UsersService) GetByID(id int) (*User, *Response, error) {
}
user := new(User)
resp, err := s.client.Do(req, user)
resp, err := s.client.Do(ctx, req, user)
if err != nil {
return nil, resp, err
}
return user, resp, err
return user, resp, nil
}
// Edit the authenticated user.
//
// GitHub API docs: http://developer.github.com/v3/users/#update-the-authenticated-user
func (s *UsersService) Edit(user *User) (*User, *Response, error) {
// GitHub API docs: https://developer.github.com/v3/users/#update-the-authenticated-user
func (s *UsersService) Edit(ctx context.Context, user *User) (*User, *Response, error) {
u := "user"
req, err := s.client.NewRequest("PATCH", u, user)
if err != nil {
@ -125,19 +126,19 @@ func (s *UsersService) Edit(user *User) (*User, *Response, error) {
}
uResp := new(User)
resp, err := s.client.Do(req, uResp)
resp, err := s.client.Do(ctx, req, uResp)
if err != nil {
return nil, resp, err
}
return uResp, resp, err
return uResp, resp, nil
}
// UserListOptions specifies optional parameters to the UsersService.ListAll
// method.
type UserListOptions struct {
// ID of the last user seen
Since int `url:"since,omitempty"`
Since int64 `url:"since,omitempty"`
ListOptions
}
@ -146,8 +147,8 @@ type UserListOptions struct {
//
// To paginate through all users, populate 'Since' with the ID of the last user.
//
// GitHub API docs: http://developer.github.com/v3/users/#get-all-users
func (s *UsersService) ListAll(opt *UserListOptions) ([]*User, *Response, error) {
// GitHub API docs: https://developer.github.com/v3/users/#get-all-users
func (s *UsersService) ListAll(ctx context.Context, opt *UserListOptions) ([]*User, *Response, error) {
u, err := addOptions("users", opt)
if err != nil {
return nil, nil, err
@ -158,21 +159,26 @@ func (s *UsersService) ListAll(opt *UserListOptions) ([]*User, *Response, error)
return nil, nil, err
}
users := new([]*User)
resp, err := s.client.Do(req, users)
var users []*User
resp, err := s.client.Do(ctx, req, &users)
if err != nil {
return nil, resp, err
}
return *users, resp, err
return users, resp, nil
}
// ListInvitations lists all currently-open repository invitations for the
// authenticated user.
//
// GitHub API docs: https://developer.github.com/v3/repos/invitations/#list-a-users-repository-invitations
func (s *UsersService) ListInvitations() ([]*RepositoryInvitation, *Response, error) {
req, err := s.client.NewRequest("GET", "user/repository_invitations", nil)
func (s *UsersService) ListInvitations(ctx context.Context, opt *ListOptions) ([]*RepositoryInvitation, *Response, error) {
u, err := addOptions("user/repository_invitations", opt)
if err != nil {
return nil, nil, err
}
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}
@ -181,19 +187,19 @@ func (s *UsersService) ListInvitations() ([]*RepositoryInvitation, *Response, er
req.Header.Set("Accept", mediaTypeRepositoryInvitationsPreview)
invites := []*RepositoryInvitation{}
resp, err := s.client.Do(req, &invites)
resp, err := s.client.Do(ctx, req, &invites)
if err != nil {
return nil, resp, err
}
return invites, resp, err
return invites, resp, nil
}
// AcceptInvitation accepts the currently-open repository invitation for the
// authenticated user.
//
// GitHub API docs: https://developer.github.com/v3/repos/invitations/#accept-a-repository-invitation
func (s *UsersService) AcceptInvitation(invitationID int) (*Response, error) {
func (s *UsersService) AcceptInvitation(ctx context.Context, invitationID int64) (*Response, error) {
u := fmt.Sprintf("user/repository_invitations/%v", invitationID)
req, err := s.client.NewRequest("PATCH", u, nil)
if err != nil {
@ -203,14 +209,14 @@ func (s *UsersService) AcceptInvitation(invitationID int) (*Response, error) {
// TODO: remove custom Accept header when this API fully launches.
req.Header.Set("Accept", mediaTypeRepositoryInvitationsPreview)
return s.client.Do(req, nil)
return s.client.Do(ctx, req, nil)
}
// DeclineInvitation declines the currently-open repository invitation for the
// authenticated user.
//
// GitHub API docs: https://developer.github.com/v3/repos/invitations/#decline-a-repository-invitation
func (s *UsersService) DeclineInvitation(invitationID int) (*Response, error) {
func (s *UsersService) DeclineInvitation(ctx context.Context, invitationID int64) (*Response, error) {
u := fmt.Sprintf("user/repository_invitations/%v", invitationID)
req, err := s.client.NewRequest("DELETE", u, nil)
if err != nil {
@ -220,5 +226,5 @@ func (s *UsersService) DeclineInvitation(invitationID int) (*Response, error) {
// TODO: remove custom Accept header when this API fully launches.
req.Header.Set("Accept", mediaTypeRepositoryInvitationsPreview)
return s.client.Do(req, nil)
return s.client.Do(ctx, req, nil)
}