diff --git a/examples/basicauth/main.go b/examples/basicauth/main.go
index c6e58dbfcc4..63f6c05ec52 100644
--- a/examples/basicauth/main.go
+++ b/examples/basicauth/main.go
@@ -10,6 +10,7 @@ package main
import (
"bufio"
+ "context"
"fmt"
"os"
"strings"
@@ -34,14 +35,15 @@ func main() {
}
client := github.NewClient(tp.Client())
- user, _, err := client.Users.Get("")
+ ctx := context.Background()
+ user, _, err := client.Users.Get(ctx, "")
// Is this a two-factor auth error? If so, prompt for OTP and try again.
if _, ok := err.(*github.TwoFactorAuthError); err != nil && ok {
fmt.Print("\nGitHub OTP: ")
otp, _ := r.ReadString('\n')
tp.OTP = strings.TrimSpace(otp)
- user, _, err = client.Users.Get("")
+ user, _, err = client.Users.Get(ctx, "")
}
if err != nil {
diff --git a/github/activity.go b/github/activity.go
index ad6da2bdc07..d6c992c7f50 100644
--- a/github/activity.go
+++ b/github/activity.go
@@ -5,6 +5,8 @@
package github
+import "context"
+
// ActivityService handles communication with the activity related
// methods of the GitHub API.
//
@@ -51,14 +53,14 @@ type Feeds struct {
//
// Note: Private feeds are only returned when authenticating via Basic Auth
// since current feed URIs use the older, non revocable auth tokens.
-func (s *ActivityService) ListFeeds() (*Feeds, *Response, error) {
+func (s *ActivityService) ListFeeds(ctx context.Context) (*Feeds, *Response, error) {
req, err := s.client.NewRequest("GET", "feeds", nil)
if err != nil {
return nil, nil, err
}
f := &Feeds{}
- resp, err := s.client.Do(req, f)
+ resp, err := s.client.Do(ctx, req, f)
if err != nil {
return nil, resp, err
}
diff --git a/github/activity_events.go b/github/activity_events.go
index f749f6df847..4e647859517 100644
--- a/github/activity_events.go
+++ b/github/activity_events.go
@@ -6,6 +6,7 @@
package github
import (
+ "context"
"encoding/json"
"fmt"
"time"
@@ -97,7 +98,7 @@ func (e *Event) Payload() (payload interface{}) {
// ListEvents drinks from the firehose of all public events across GitHub.
//
// GitHub API docs: https://developer.github.com/v3/activity/events/#list-public-events
-func (s *ActivityService) ListEvents(opt *ListOptions) ([]*Event, *Response, error) {
+func (s *ActivityService) ListEvents(ctx context.Context, opt *ListOptions) ([]*Event, *Response, error) {
u, err := addOptions("events", opt)
if err != nil {
return nil, nil, err
@@ -109,7 +110,7 @@ func (s *ActivityService) ListEvents(opt *ListOptions) ([]*Event, *Response, err
}
var events []*Event
- resp, err := s.client.Do(req, &events)
+ resp, err := s.client.Do(ctx, req, &events)
if err != nil {
return nil, resp, err
}
@@ -120,7 +121,7 @@ func (s *ActivityService) ListEvents(opt *ListOptions) ([]*Event, *Response, err
// ListRepositoryEvents lists events for a repository.
//
// GitHub API docs: https://developer.github.com/v3/activity/events/#list-repository-events
-func (s *ActivityService) ListRepositoryEvents(owner, repo string, opt *ListOptions) ([]*Event, *Response, error) {
+func (s *ActivityService) ListRepositoryEvents(ctx context.Context, owner, repo string, opt *ListOptions) ([]*Event, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/events", owner, repo)
u, err := addOptions(u, opt)
if err != nil {
@@ -133,7 +134,7 @@ func (s *ActivityService) ListRepositoryEvents(owner, repo string, opt *ListOpti
}
var events []*Event
- resp, err := s.client.Do(req, &events)
+ resp, err := s.client.Do(ctx, req, &events)
if err != nil {
return nil, resp, err
}
@@ -144,7 +145,7 @@ func (s *ActivityService) ListRepositoryEvents(owner, repo string, opt *ListOpti
// ListIssueEventsForRepository lists issue events for a repository.
//
// GitHub API docs: https://developer.github.com/v3/activity/events/#list-issue-events-for-a-repository
-func (s *ActivityService) ListIssueEventsForRepository(owner, repo string, opt *ListOptions) ([]*IssueEvent, *Response, error) {
+func (s *ActivityService) ListIssueEventsForRepository(ctx context.Context, owner, repo string, opt *ListOptions) ([]*IssueEvent, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/issues/events", owner, repo)
u, err := addOptions(u, opt)
if err != nil {
@@ -157,7 +158,7 @@ func (s *ActivityService) ListIssueEventsForRepository(owner, repo string, opt *
}
var events []*IssueEvent
- resp, err := s.client.Do(req, &events)
+ resp, err := s.client.Do(ctx, req, &events)
if err != nil {
return nil, resp, err
}
@@ -168,7 +169,7 @@ func (s *ActivityService) ListIssueEventsForRepository(owner, repo string, opt *
// ListEventsForRepoNetwork lists public events for a network of repositories.
//
// GitHub API docs: https://developer.github.com/v3/activity/events/#list-public-events-for-a-network-of-repositories
-func (s *ActivityService) ListEventsForRepoNetwork(owner, repo string, opt *ListOptions) ([]*Event, *Response, error) {
+func (s *ActivityService) ListEventsForRepoNetwork(ctx context.Context, owner, repo string, opt *ListOptions) ([]*Event, *Response, error) {
u := fmt.Sprintf("networks/%v/%v/events", owner, repo)
u, err := addOptions(u, opt)
if err != nil {
@@ -181,7 +182,7 @@ func (s *ActivityService) ListEventsForRepoNetwork(owner, repo string, opt *List
}
var events []*Event
- resp, err := s.client.Do(req, &events)
+ resp, err := s.client.Do(ctx, req, &events)
if err != nil {
return nil, resp, err
}
@@ -192,7 +193,7 @@ func (s *ActivityService) ListEventsForRepoNetwork(owner, repo string, opt *List
// ListEventsForOrganization lists public events for an organization.
//
// GitHub API docs: https://developer.github.com/v3/activity/events/#list-public-events-for-an-organization
-func (s *ActivityService) ListEventsForOrganization(org string, opt *ListOptions) ([]*Event, *Response, error) {
+func (s *ActivityService) ListEventsForOrganization(ctx context.Context, org string, opt *ListOptions) ([]*Event, *Response, error) {
u := fmt.Sprintf("orgs/%v/events", org)
u, err := addOptions(u, opt)
if err != nil {
@@ -205,7 +206,7 @@ func (s *ActivityService) ListEventsForOrganization(org string, opt *ListOptions
}
var events []*Event
- resp, err := s.client.Do(req, &events)
+ resp, err := s.client.Do(ctx, req, &events)
if err != nil {
return nil, resp, err
}
@@ -217,7 +218,7 @@ func (s *ActivityService) ListEventsForOrganization(org string, opt *ListOptions
// true, only public events will be returned.
//
// GitHub API docs: https://developer.github.com/v3/activity/events/#list-events-performed-by-a-user
-func (s *ActivityService) ListEventsPerformedByUser(user string, publicOnly bool, opt *ListOptions) ([]*Event, *Response, error) {
+func (s *ActivityService) ListEventsPerformedByUser(ctx context.Context, user string, publicOnly bool, opt *ListOptions) ([]*Event, *Response, error) {
var u string
if publicOnly {
u = fmt.Sprintf("users/%v/events/public", user)
@@ -235,7 +236,7 @@ func (s *ActivityService) ListEventsPerformedByUser(user string, publicOnly bool
}
var events []*Event
- resp, err := s.client.Do(req, &events)
+ resp, err := s.client.Do(ctx, req, &events)
if err != nil {
return nil, resp, err
}
@@ -247,7 +248,7 @@ func (s *ActivityService) ListEventsPerformedByUser(user string, publicOnly bool
// true, only public events will be returned.
//
// GitHub API docs: https://developer.github.com/v3/activity/events/#list-events-that-a-user-has-received
-func (s *ActivityService) ListEventsReceivedByUser(user string, publicOnly bool, opt *ListOptions) ([]*Event, *Response, error) {
+func (s *ActivityService) ListEventsReceivedByUser(ctx context.Context, user string, publicOnly bool, opt *ListOptions) ([]*Event, *Response, error) {
var u string
if publicOnly {
u = fmt.Sprintf("users/%v/received_events/public", user)
@@ -265,7 +266,7 @@ func (s *ActivityService) ListEventsReceivedByUser(user string, publicOnly bool,
}
var events []*Event
- resp, err := s.client.Do(req, &events)
+ resp, err := s.client.Do(ctx, req, &events)
if err != nil {
return nil, resp, err
}
@@ -277,7 +278,7 @@ func (s *ActivityService) ListEventsReceivedByUser(user string, publicOnly bool,
// must be authenticated as the user to view this.
//
// GitHub API docs: https://developer.github.com/v3/activity/events/#list-events-for-an-organization
-func (s *ActivityService) ListUserEventsForOrganization(org, user string, opt *ListOptions) ([]*Event, *Response, error) {
+func (s *ActivityService) ListUserEventsForOrganization(ctx context.Context, org, user string, opt *ListOptions) ([]*Event, *Response, error) {
u := fmt.Sprintf("users/%v/events/orgs/%v", user, org)
u, err := addOptions(u, opt)
if err != nil {
@@ -290,7 +291,7 @@ func (s *ActivityService) ListUserEventsForOrganization(org, user string, opt *L
}
var events []*Event
- resp, err := s.client.Do(req, &events)
+ resp, err := s.client.Do(ctx, req, &events)
if err != nil {
return nil, resp, err
}
diff --git a/github/activity_events_test.go b/github/activity_events_test.go
index 8739dac4e59..9e1d75b825e 100644
--- a/github/activity_events_test.go
+++ b/github/activity_events_test.go
@@ -6,6 +6,7 @@
package github
import (
+ "context"
"encoding/json"
"fmt"
"net/http"
@@ -26,7 +27,7 @@ func TestActivityService_ListEvents(t *testing.T) {
})
opt := &ListOptions{Page: 2}
- events, _, err := client.Activity.ListEvents(opt)
+ events, _, err := client.Activity.ListEvents(context.Background(), opt)
if err != nil {
t.Errorf("Activities.ListEvents returned error: %v", err)
}
@@ -50,7 +51,7 @@ func TestActivityService_ListRepositoryEvents(t *testing.T) {
})
opt := &ListOptions{Page: 2}
- events, _, err := client.Activity.ListRepositoryEvents("o", "r", opt)
+ events, _, err := client.Activity.ListRepositoryEvents(context.Background(), "o", "r", opt)
if err != nil {
t.Errorf("Activities.ListRepositoryEvents returned error: %v", err)
}
@@ -62,7 +63,7 @@ func TestActivityService_ListRepositoryEvents(t *testing.T) {
}
func TestActivityService_ListRepositoryEvents_invalidOwner(t *testing.T) {
- _, _, err := client.Activity.ListRepositoryEvents("%", "%", nil)
+ _, _, err := client.Activity.ListRepositoryEvents(context.Background(), "%", "%", nil)
testURLParseError(t, err)
}
@@ -79,7 +80,7 @@ func TestActivityService_ListIssueEventsForRepository(t *testing.T) {
})
opt := &ListOptions{Page: 2}
- events, _, err := client.Activity.ListIssueEventsForRepository("o", "r", opt)
+ events, _, err := client.Activity.ListIssueEventsForRepository(context.Background(), "o", "r", opt)
if err != nil {
t.Errorf("Activities.ListIssueEventsForRepository returned error: %v", err)
}
@@ -91,7 +92,7 @@ func TestActivityService_ListIssueEventsForRepository(t *testing.T) {
}
func TestActivityService_ListIssueEventsForRepository_invalidOwner(t *testing.T) {
- _, _, err := client.Activity.ListIssueEventsForRepository("%", "%", nil)
+ _, _, err := client.Activity.ListIssueEventsForRepository(context.Background(), "%", "%", nil)
testURLParseError(t, err)
}
@@ -108,7 +109,7 @@ func TestActivityService_ListEventsForRepoNetwork(t *testing.T) {
})
opt := &ListOptions{Page: 2}
- events, _, err := client.Activity.ListEventsForRepoNetwork("o", "r", opt)
+ events, _, err := client.Activity.ListEventsForRepoNetwork(context.Background(), "o", "r", opt)
if err != nil {
t.Errorf("Activities.ListEventsForRepoNetwork returned error: %v", err)
}
@@ -120,7 +121,7 @@ func TestActivityService_ListEventsForRepoNetwork(t *testing.T) {
}
func TestActivityService_ListEventsForRepoNetwork_invalidOwner(t *testing.T) {
- _, _, err := client.Activity.ListEventsForRepoNetwork("%", "%", nil)
+ _, _, err := client.Activity.ListEventsForRepoNetwork(context.Background(), "%", "%", nil)
testURLParseError(t, err)
}
@@ -137,7 +138,7 @@ func TestActivityService_ListEventsForOrganization(t *testing.T) {
})
opt := &ListOptions{Page: 2}
- events, _, err := client.Activity.ListEventsForOrganization("o", opt)
+ events, _, err := client.Activity.ListEventsForOrganization(context.Background(), "o", opt)
if err != nil {
t.Errorf("Activities.ListEventsForOrganization returned error: %v", err)
}
@@ -149,7 +150,7 @@ func TestActivityService_ListEventsForOrganization(t *testing.T) {
}
func TestActivityService_ListEventsForOrganization_invalidOrg(t *testing.T) {
- _, _, err := client.Activity.ListEventsForOrganization("%", nil)
+ _, _, err := client.Activity.ListEventsForOrganization(context.Background(), "%", nil)
testURLParseError(t, err)
}
@@ -166,7 +167,7 @@ func TestActivityService_ListEventsPerformedByUser_all(t *testing.T) {
})
opt := &ListOptions{Page: 2}
- events, _, err := client.Activity.ListEventsPerformedByUser("u", false, opt)
+ events, _, err := client.Activity.ListEventsPerformedByUser(context.Background(), "u", false, opt)
if err != nil {
t.Errorf("Events.ListPerformedByUser returned error: %v", err)
}
@@ -186,7 +187,7 @@ func TestActivityService_ListEventsPerformedByUser_publicOnly(t *testing.T) {
fmt.Fprint(w, `[{"id":"1"},{"id":"2"}]`)
})
- events, _, err := client.Activity.ListEventsPerformedByUser("u", true, nil)
+ events, _, err := client.Activity.ListEventsPerformedByUser(context.Background(), "u", true, nil)
if err != nil {
t.Errorf("Events.ListPerformedByUser returned error: %v", err)
}
@@ -198,7 +199,7 @@ func TestActivityService_ListEventsPerformedByUser_publicOnly(t *testing.T) {
}
func TestActivityService_ListEventsPerformedByUser_invalidUser(t *testing.T) {
- _, _, err := client.Activity.ListEventsPerformedByUser("%", false, nil)
+ _, _, err := client.Activity.ListEventsPerformedByUser(context.Background(), "%", false, nil)
testURLParseError(t, err)
}
@@ -215,7 +216,7 @@ func TestActivityService_ListEventsReceivedByUser_all(t *testing.T) {
})
opt := &ListOptions{Page: 2}
- events, _, err := client.Activity.ListEventsReceivedByUser("u", false, opt)
+ events, _, err := client.Activity.ListEventsReceivedByUser(context.Background(), "u", false, opt)
if err != nil {
t.Errorf("Events.ListReceivedByUser returned error: %v", err)
}
@@ -235,7 +236,7 @@ func TestActivityService_ListEventsReceivedByUser_publicOnly(t *testing.T) {
fmt.Fprint(w, `[{"id":"1"},{"id":"2"}]`)
})
- events, _, err := client.Activity.ListEventsReceivedByUser("u", true, nil)
+ events, _, err := client.Activity.ListEventsReceivedByUser(context.Background(), "u", true, nil)
if err != nil {
t.Errorf("Events.ListReceivedByUser returned error: %v", err)
}
@@ -247,7 +248,7 @@ func TestActivityService_ListEventsReceivedByUser_publicOnly(t *testing.T) {
}
func TestActivityService_ListEventsReceivedByUser_invalidUser(t *testing.T) {
- _, _, err := client.Activity.ListEventsReceivedByUser("%", false, nil)
+ _, _, err := client.Activity.ListEventsReceivedByUser(context.Background(), "%", false, nil)
testURLParseError(t, err)
}
@@ -264,7 +265,7 @@ func TestActivityService_ListUserEventsForOrganization(t *testing.T) {
})
opt := &ListOptions{Page: 2}
- events, _, err := client.Activity.ListUserEventsForOrganization("o", "u", opt)
+ events, _, err := client.Activity.ListUserEventsForOrganization(context.Background(), "o", "u", opt)
if err != nil {
t.Errorf("Activities.ListUserEventsForOrganization returned error: %v", err)
}
diff --git a/github/activity_notifications.go b/github/activity_notifications.go
index 5ae80ad6ce3..771c6264b74 100644
--- a/github/activity_notifications.go
+++ b/github/activity_notifications.go
@@ -6,6 +6,7 @@
package github
import (
+ "context"
"fmt"
"time"
)
@@ -49,7 +50,7 @@ type NotificationListOptions struct {
// ListNotifications lists all notifications for the authenticated user.
//
// GitHub API Docs: https://developer.github.com/v3/activity/notifications/#list-your-notifications
-func (s *ActivityService) ListNotifications(opt *NotificationListOptions) ([]*Notification, *Response, error) {
+func (s *ActivityService) ListNotifications(ctx context.Context, opt *NotificationListOptions) ([]*Notification, *Response, error) {
u := fmt.Sprintf("notifications")
u, err := addOptions(u, opt)
if err != nil {
@@ -62,7 +63,7 @@ func (s *ActivityService) ListNotifications(opt *NotificationListOptions) ([]*No
}
var notifications []*Notification
- resp, err := s.client.Do(req, ¬ifications)
+ resp, err := s.client.Do(ctx, req, ¬ifications)
if err != nil {
return nil, resp, err
}
@@ -74,7 +75,7 @@ func (s *ActivityService) ListNotifications(opt *NotificationListOptions) ([]*No
// for the authenticated user.
//
// GitHub API Docs: https://developer.github.com/v3/activity/notifications/#list-your-notifications-in-a-repository
-func (s *ActivityService) ListRepositoryNotifications(owner, repo string, opt *NotificationListOptions) ([]*Notification, *Response, error) {
+func (s *ActivityService) ListRepositoryNotifications(ctx context.Context, owner, repo string, opt *NotificationListOptions) ([]*Notification, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/notifications", owner, repo)
u, err := addOptions(u, opt)
if err != nil {
@@ -87,7 +88,7 @@ func (s *ActivityService) ListRepositoryNotifications(owner, repo string, opt *N
}
var notifications []*Notification
- resp, err := s.client.Do(req, ¬ifications)
+ resp, err := s.client.Do(ctx, req, ¬ifications)
if err != nil {
return nil, resp, err
}
@@ -102,7 +103,7 @@ type markReadOptions struct {
// MarkNotificationsRead marks all notifications up to lastRead as read.
//
// GitHub API Docs: https://developer.github.com/v3/activity/notifications/#mark-as-read
-func (s *ActivityService) MarkNotificationsRead(lastRead time.Time) (*Response, error) {
+func (s *ActivityService) MarkNotificationsRead(ctx context.Context, lastRead time.Time) (*Response, error) {
opts := &markReadOptions{
LastReadAt: lastRead,
}
@@ -111,14 +112,14 @@ func (s *ActivityService) MarkNotificationsRead(lastRead time.Time) (*Response,
return nil, err
}
- return s.client.Do(req, nil)
+ return s.client.Do(ctx, req, nil)
}
// MarkRepositoryNotificationsRead marks all notifications up to lastRead in
// the specified repository as read.
//
// GitHub API Docs: https://developer.github.com/v3/activity/notifications/#mark-notifications-as-read-in-a-repository
-func (s *ActivityService) MarkRepositoryNotificationsRead(owner, repo string, lastRead time.Time) (*Response, error) {
+func (s *ActivityService) MarkRepositoryNotificationsRead(ctx context.Context, owner, repo string, lastRead time.Time) (*Response, error) {
opts := &markReadOptions{
LastReadAt: lastRead,
}
@@ -128,13 +129,13 @@ func (s *ActivityService) MarkRepositoryNotificationsRead(owner, repo string, la
return nil, err
}
- return s.client.Do(req, nil)
+ return s.client.Do(ctx, req, nil)
}
// GetThread gets the specified notification thread.
//
// GitHub API Docs: https://developer.github.com/v3/activity/notifications/#view-a-single-thread
-func (s *ActivityService) GetThread(id string) (*Notification, *Response, error) {
+func (s *ActivityService) GetThread(ctx context.Context, id string) (*Notification, *Response, error) {
u := fmt.Sprintf("notifications/threads/%v", id)
req, err := s.client.NewRequest("GET", u, nil)
@@ -143,7 +144,7 @@ func (s *ActivityService) GetThread(id string) (*Notification, *Response, error)
}
notification := new(Notification)
- resp, err := s.client.Do(req, notification)
+ resp, err := s.client.Do(ctx, req, notification)
if err != nil {
return nil, resp, err
}
@@ -154,7 +155,7 @@ func (s *ActivityService) GetThread(id string) (*Notification, *Response, error)
// MarkThreadRead marks the specified thread as read.
//
// GitHub API Docs: https://developer.github.com/v3/activity/notifications/#mark-a-thread-as-read
-func (s *ActivityService) MarkThreadRead(id string) (*Response, error) {
+func (s *ActivityService) MarkThreadRead(ctx context.Context, id string) (*Response, error) {
u := fmt.Sprintf("notifications/threads/%v", id)
req, err := s.client.NewRequest("PATCH", u, nil)
@@ -162,14 +163,14 @@ func (s *ActivityService) MarkThreadRead(id string) (*Response, error) {
return nil, err
}
- return s.client.Do(req, nil)
+ return s.client.Do(ctx, req, nil)
}
// GetThreadSubscription checks to see if the authenticated user is subscribed
// to a thread.
//
// GitHub API Docs: https://developer.github.com/v3/activity/notifications/#get-a-thread-subscription
-func (s *ActivityService) GetThreadSubscription(id string) (*Subscription, *Response, error) {
+func (s *ActivityService) GetThreadSubscription(ctx context.Context, id string) (*Subscription, *Response, error) {
u := fmt.Sprintf("notifications/threads/%v/subscription", id)
req, err := s.client.NewRequest("GET", u, nil)
@@ -178,7 +179,7 @@ func (s *ActivityService) GetThreadSubscription(id string) (*Subscription, *Resp
}
sub := new(Subscription)
- resp, err := s.client.Do(req, sub)
+ resp, err := s.client.Do(ctx, req, sub)
if err != nil {
return nil, resp, err
}
@@ -190,7 +191,7 @@ func (s *ActivityService) GetThreadSubscription(id string) (*Subscription, *Resp
// authenticated user.
//
// GitHub API Docs: https://developer.github.com/v3/activity/notifications/#set-a-thread-subscription
-func (s *ActivityService) SetThreadSubscription(id string, subscription *Subscription) (*Subscription, *Response, error) {
+func (s *ActivityService) SetThreadSubscription(ctx context.Context, id string, subscription *Subscription) (*Subscription, *Response, error) {
u := fmt.Sprintf("notifications/threads/%v/subscription", id)
req, err := s.client.NewRequest("PUT", u, subscription)
@@ -199,7 +200,7 @@ func (s *ActivityService) SetThreadSubscription(id string, subscription *Subscri
}
sub := new(Subscription)
- resp, err := s.client.Do(req, sub)
+ resp, err := s.client.Do(ctx, req, sub)
if err != nil {
return nil, resp, err
}
@@ -211,12 +212,12 @@ func (s *ActivityService) SetThreadSubscription(id string, subscription *Subscri
// for the authenticated user.
//
// GitHub API Docs: https://developer.github.com/v3/activity/notifications/#delete-a-thread-subscription
-func (s *ActivityService) DeleteThreadSubscription(id string) (*Response, error) {
+func (s *ActivityService) DeleteThreadSubscription(ctx context.Context, id string) (*Response, error) {
u := fmt.Sprintf("notifications/threads/%v/subscription", id)
req, err := s.client.NewRequest("DELETE", u, nil)
if err != nil {
return nil, err
}
- return s.client.Do(req, nil)
+ return s.client.Do(ctx, req, nil)
}
diff --git a/github/activity_notifications_test.go b/github/activity_notifications_test.go
index 8f6a581a391..cab8f94da8d 100644
--- a/github/activity_notifications_test.go
+++ b/github/activity_notifications_test.go
@@ -6,6 +6,7 @@
package github
import (
+ "context"
"encoding/json"
"fmt"
"net/http"
@@ -36,7 +37,7 @@ func TestActivityService_ListNotification(t *testing.T) {
Since: time.Date(2006, 01, 02, 15, 04, 05, 0, time.UTC),
Before: time.Date(2007, 03, 04, 15, 04, 05, 0, time.UTC),
}
- notifications, _, err := client.Activity.ListNotifications(opt)
+ notifications, _, err := client.Activity.ListNotifications(context.Background(), opt)
if err != nil {
t.Errorf("Activity.ListNotifications returned error: %v", err)
}
@@ -56,7 +57,7 @@ func TestActivityService_ListRepositoryNotification(t *testing.T) {
fmt.Fprint(w, `[{"id":"1"}]`)
})
- notifications, _, err := client.Activity.ListRepositoryNotifications("o", "r", nil)
+ notifications, _, err := client.Activity.ListRepositoryNotifications(context.Background(), "o", "r", nil)
if err != nil {
t.Errorf("Activity.ListRepositoryNotifications returned error: %v", err)
}
@@ -79,7 +80,7 @@ func TestActivityService_MarkNotificationsRead(t *testing.T) {
w.WriteHeader(http.StatusResetContent)
})
- _, err := client.Activity.MarkNotificationsRead(time.Date(2006, 01, 02, 15, 04, 05, 0, time.UTC))
+ _, err := client.Activity.MarkNotificationsRead(context.Background(), time.Date(2006, 01, 02, 15, 04, 05, 0, time.UTC))
if err != nil {
t.Errorf("Activity.MarkNotificationsRead returned error: %v", err)
}
@@ -97,7 +98,7 @@ func TestActivityService_MarkRepositoryNotificationsRead(t *testing.T) {
w.WriteHeader(http.StatusResetContent)
})
- _, err := client.Activity.MarkRepositoryNotificationsRead("o", "r", time.Date(2006, 01, 02, 15, 04, 05, 0, time.UTC))
+ _, err := client.Activity.MarkRepositoryNotificationsRead(context.Background(), "o", "r", time.Date(2006, 01, 02, 15, 04, 05, 0, time.UTC))
if err != nil {
t.Errorf("Activity.MarkRepositoryNotificationsRead returned error: %v", err)
}
@@ -112,7 +113,7 @@ func TestActivityService_GetThread(t *testing.T) {
fmt.Fprint(w, `{"id":"1"}`)
})
- notification, _, err := client.Activity.GetThread("1")
+ notification, _, err := client.Activity.GetThread(context.Background(), "1")
if err != nil {
t.Errorf("Activity.GetThread returned error: %v", err)
}
@@ -132,7 +133,7 @@ func TestActivityService_MarkThreadRead(t *testing.T) {
w.WriteHeader(http.StatusResetContent)
})
- _, err := client.Activity.MarkThreadRead("1")
+ _, err := client.Activity.MarkThreadRead(context.Background(), "1")
if err != nil {
t.Errorf("Activity.MarkThreadRead returned error: %v", err)
}
@@ -147,7 +148,7 @@ func TestActivityService_GetThreadSubscription(t *testing.T) {
fmt.Fprint(w, `{"subscribed":true}`)
})
- sub, _, err := client.Activity.GetThreadSubscription("1")
+ sub, _, err := client.Activity.GetThreadSubscription(context.Background(), "1")
if err != nil {
t.Errorf("Activity.GetThreadSubscription returned error: %v", err)
}
@@ -176,7 +177,7 @@ func TestActivityService_SetThreadSubscription(t *testing.T) {
fmt.Fprint(w, `{"ignored":true}`)
})
- sub, _, err := client.Activity.SetThreadSubscription("1", input)
+ sub, _, err := client.Activity.SetThreadSubscription(context.Background(), "1", input)
if err != nil {
t.Errorf("Activity.SetThreadSubscription returned error: %v", err)
}
@@ -196,7 +197,7 @@ func TestActivityService_DeleteThreadSubscription(t *testing.T) {
w.WriteHeader(http.StatusNoContent)
})
- _, err := client.Activity.DeleteThreadSubscription("1")
+ _, err := client.Activity.DeleteThreadSubscription(context.Background(), "1")
if err != nil {
t.Errorf("Activity.DeleteThreadSubscription returned error: %v", err)
}
diff --git a/github/activity_star.go b/github/activity_star.go
index db9a3099f28..0175719bf05 100644
--- a/github/activity_star.go
+++ b/github/activity_star.go
@@ -5,7 +5,10 @@
package github
-import "fmt"
+import (
+ "context"
+ "fmt"
+)
// StarredRepository is returned by ListStarred.
type StarredRepository struct {
@@ -22,7 +25,7 @@ type Stargazer struct {
// ListStargazers lists people who have starred the specified repo.
//
// GitHub API Docs: https://developer.github.com/v3/activity/starring/#list-stargazers
-func (s *ActivityService) ListStargazers(owner, repo string, opt *ListOptions) ([]*Stargazer, *Response, error) {
+func (s *ActivityService) ListStargazers(ctx context.Context, owner, repo string, opt *ListOptions) ([]*Stargazer, *Response, error) {
u := fmt.Sprintf("repos/%s/%s/stargazers", owner, repo)
u, err := addOptions(u, opt)
if err != nil {
@@ -38,7 +41,7 @@ func (s *ActivityService) ListStargazers(owner, repo string, opt *ListOptions) (
req.Header.Set("Accept", mediaTypeStarringPreview)
var stargazers []*Stargazer
- resp, err := s.client.Do(req, &stargazers)
+ resp, err := s.client.Do(ctx, req, &stargazers)
if err != nil {
return nil, resp, err
}
@@ -64,7 +67,7 @@ type ActivityListStarredOptions struct {
// will list the starred repositories for the authenticated user.
//
// GitHub API docs: https://developer.github.com/v3/activity/starring/#list-repositories-being-starred
-func (s *ActivityService) ListStarred(user string, opt *ActivityListStarredOptions) ([]*StarredRepository, *Response, error) {
+func (s *ActivityService) ListStarred(ctx context.Context, user string, opt *ActivityListStarredOptions) ([]*StarredRepository, *Response, error) {
var u string
if user != "" {
u = fmt.Sprintf("users/%v/starred", user)
@@ -85,7 +88,7 @@ func (s *ActivityService) ListStarred(user string, opt *ActivityListStarredOptio
req.Header.Set("Accept", mediaTypeStarringPreview)
var repos []*StarredRepository
- resp, err := s.client.Do(req, &repos)
+ resp, err := s.client.Do(ctx, req, &repos)
if err != nil {
return nil, resp, err
}
@@ -96,13 +99,13 @@ func (s *ActivityService) ListStarred(user string, opt *ActivityListStarredOptio
// IsStarred checks if a repository is starred by authenticated user.
//
// GitHub API docs: https://developer.github.com/v3/activity/starring/#check-if-you-are-starring-a-repository
-func (s *ActivityService) IsStarred(owner, repo string) (bool, *Response, error) {
+func (s *ActivityService) IsStarred(ctx context.Context, owner, repo string) (bool, *Response, error) {
u := fmt.Sprintf("user/starred/%v/%v", owner, repo)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return false, nil, err
}
- resp, err := s.client.Do(req, nil)
+ resp, err := s.client.Do(ctx, req, nil)
starred, err := parseBoolResponse(err)
return starred, resp, err
}
@@ -110,23 +113,23 @@ func (s *ActivityService) IsStarred(owner, repo string) (bool, *Response, error)
// Star a repository as the authenticated user.
//
// GitHub API docs: https://developer.github.com/v3/activity/starring/#star-a-repository
-func (s *ActivityService) Star(owner, repo string) (*Response, error) {
+func (s *ActivityService) Star(ctx context.Context, owner, repo string) (*Response, error) {
u := fmt.Sprintf("user/starred/%v/%v", owner, repo)
req, err := s.client.NewRequest("PUT", u, nil)
if err != nil {
return nil, err
}
- return s.client.Do(req, nil)
+ return s.client.Do(ctx, req, nil)
}
// Unstar a repository as the authenticated user.
//
// GitHub API docs: https://developer.github.com/v3/activity/starring/#unstar-a-repository
-func (s *ActivityService) Unstar(owner, repo string) (*Response, error) {
+func (s *ActivityService) Unstar(ctx context.Context, owner, repo string) (*Response, error) {
u := fmt.Sprintf("user/starred/%v/%v", owner, repo)
req, err := s.client.NewRequest("DELETE", u, nil)
if err != nil {
return nil, err
}
- return s.client.Do(req, nil)
+ return s.client.Do(ctx, req, nil)
}
diff --git a/github/activity_star_test.go b/github/activity_star_test.go
index 4c0767a5ea9..542bfc66b4b 100644
--- a/github/activity_star_test.go
+++ b/github/activity_star_test.go
@@ -6,6 +6,7 @@
package github
import (
+ "context"
"fmt"
"net/http"
"reflect"
@@ -27,7 +28,7 @@ func TestActivityService_ListStargazers(t *testing.T) {
fmt.Fprint(w, `[{"starred_at":"2002-02-10T15:30:00Z","user":{"id":1}}]`)
})
- stargazers, _, err := client.Activity.ListStargazers("o", "r", &ListOptions{Page: 2})
+ stargazers, _, err := client.Activity.ListStargazers(context.Background(), "o", "r", &ListOptions{Page: 2})
if err != nil {
t.Errorf("Activity.ListStargazers returned error: %v", err)
}
@@ -48,7 +49,7 @@ func TestActivityService_ListStarred_authenticatedUser(t *testing.T) {
fmt.Fprint(w, `[{"starred_at":"2002-02-10T15:30:00Z","repo":{"id":1}}]`)
})
- repos, _, err := client.Activity.ListStarred("", nil)
+ repos, _, err := client.Activity.ListStarred(context.Background(), "", nil)
if err != nil {
t.Errorf("Activity.ListStarred returned error: %v", err)
}
@@ -75,7 +76,7 @@ func TestActivityService_ListStarred_specifiedUser(t *testing.T) {
})
opt := &ActivityListStarredOptions{"created", "asc", ListOptions{Page: 2}}
- repos, _, err := client.Activity.ListStarred("u", opt)
+ repos, _, err := client.Activity.ListStarred(context.Background(), "u", opt)
if err != nil {
t.Errorf("Activity.ListStarred returned error: %v", err)
}
@@ -87,7 +88,7 @@ func TestActivityService_ListStarred_specifiedUser(t *testing.T) {
}
func TestActivityService_ListStarred_invalidUser(t *testing.T) {
- _, _, err := client.Activity.ListStarred("%", nil)
+ _, _, err := client.Activity.ListStarred(context.Background(), "%", nil)
testURLParseError(t, err)
}
@@ -100,7 +101,7 @@ func TestActivityService_IsStarred_hasStar(t *testing.T) {
w.WriteHeader(http.StatusNoContent)
})
- star, _, err := client.Activity.IsStarred("o", "r")
+ star, _, err := client.Activity.IsStarred(context.Background(), "o", "r")
if err != nil {
t.Errorf("Activity.IsStarred returned error: %v", err)
}
@@ -118,7 +119,7 @@ func TestActivityService_IsStarred_noStar(t *testing.T) {
w.WriteHeader(http.StatusNotFound)
})
- star, _, err := client.Activity.IsStarred("o", "r")
+ star, _, err := client.Activity.IsStarred(context.Background(), "o", "r")
if err != nil {
t.Errorf("Activity.IsStarred returned error: %v", err)
}
@@ -128,7 +129,7 @@ func TestActivityService_IsStarred_noStar(t *testing.T) {
}
func TestActivityService_IsStarred_invalidID(t *testing.T) {
- _, _, err := client.Activity.IsStarred("%", "%")
+ _, _, err := client.Activity.IsStarred(context.Background(), "%", "%")
testURLParseError(t, err)
}
@@ -140,14 +141,14 @@ func TestActivityService_Star(t *testing.T) {
testMethod(t, r, "PUT")
})
- _, err := client.Activity.Star("o", "r")
+ _, err := client.Activity.Star(context.Background(), "o", "r")
if err != nil {
t.Errorf("Activity.Star returned error: %v", err)
}
}
func TestActivityService_Star_invalidID(t *testing.T) {
- _, err := client.Activity.Star("%", "%")
+ _, err := client.Activity.Star(context.Background(), "%", "%")
testURLParseError(t, err)
}
@@ -159,13 +160,13 @@ func TestActivityService_Unstar(t *testing.T) {
testMethod(t, r, "DELETE")
})
- _, err := client.Activity.Unstar("o", "r")
+ _, err := client.Activity.Unstar(context.Background(), "o", "r")
if err != nil {
t.Errorf("Activity.Unstar returned error: %v", err)
}
}
func TestActivityService_Unstar_invalidID(t *testing.T) {
- _, err := client.Activity.Unstar("%", "%")
+ _, err := client.Activity.Unstar(context.Background(), "%", "%")
testURLParseError(t, err)
}
diff --git a/github/activity_test.go b/github/activity_test.go
index dc289e9212c..98567a254b6 100644
--- a/github/activity_test.go
+++ b/github/activity_test.go
@@ -6,6 +6,7 @@
package github
import (
+ "context"
"net/http"
"reflect"
"testing"
@@ -22,7 +23,7 @@ func TestActivityService_List(t *testing.T) {
w.Write(feedsJSON)
})
- got, _, err := client.Activity.ListFeeds()
+ got, _, err := client.Activity.ListFeeds(context.Background())
if err != nil {
t.Errorf("Activity.ListFeeds returned error: %v", err)
}
diff --git a/github/activity_watching.go b/github/activity_watching.go
index d8ee72dbe5d..a5153414a83 100644
--- a/github/activity_watching.go
+++ b/github/activity_watching.go
@@ -5,7 +5,10 @@
package github
-import "fmt"
+import (
+ "context"
+ "fmt"
+)
// Subscription identifies a repository or thread subscription.
type Subscription struct {
@@ -25,7 +28,7 @@ type Subscription struct {
// ListWatchers lists watchers of a particular repo.
//
// GitHub API Docs: https://developer.github.com/v3/activity/watching/#list-watchers
-func (s *ActivityService) ListWatchers(owner, repo string, opt *ListOptions) ([]*User, *Response, error) {
+func (s *ActivityService) ListWatchers(ctx context.Context, owner, repo string, opt *ListOptions) ([]*User, *Response, error) {
u := fmt.Sprintf("repos/%s/%s/subscribers", owner, repo)
u, err := addOptions(u, opt)
if err != nil {
@@ -38,7 +41,7 @@ func (s *ActivityService) ListWatchers(owner, repo string, opt *ListOptions) ([]
}
var watchers []*User
- resp, err := s.client.Do(req, &watchers)
+ resp, err := s.client.Do(ctx, req, &watchers)
if err != nil {
return nil, resp, err
}
@@ -50,7 +53,7 @@ func (s *ActivityService) ListWatchers(owner, repo string, opt *ListOptions) ([]
// the empty string will fetch watched repos for the authenticated user.
//
// GitHub API Docs: https://developer.github.com/v3/activity/watching/#list-repositories-being-watched
-func (s *ActivityService) ListWatched(user string, opt *ListOptions) ([]*Repository, *Response, error) {
+func (s *ActivityService) ListWatched(ctx context.Context, user string, opt *ListOptions) ([]*Repository, *Response, error) {
var u string
if user != "" {
u = fmt.Sprintf("users/%v/subscriptions", user)
@@ -68,7 +71,7 @@ func (s *ActivityService) ListWatched(user string, opt *ListOptions) ([]*Reposit
}
var watched []*Repository
- resp, err := s.client.Do(req, &watched)
+ resp, err := s.client.Do(ctx, req, &watched)
if err != nil {
return nil, resp, err
}
@@ -81,7 +84,7 @@ func (s *ActivityService) ListWatched(user string, opt *ListOptions) ([]*Reposit
// watching the repository, a nil Subscription is returned.
//
// GitHub API Docs: https://developer.github.com/v3/activity/watching/#get-a-repository-subscription
-func (s *ActivityService) GetRepositorySubscription(owner, repo string) (*Subscription, *Response, error) {
+func (s *ActivityService) GetRepositorySubscription(ctx context.Context, owner, repo string) (*Subscription, *Response, error) {
u := fmt.Sprintf("repos/%s/%s/subscription", owner, repo)
req, err := s.client.NewRequest("GET", u, nil)
@@ -90,7 +93,7 @@ func (s *ActivityService) GetRepositorySubscription(owner, repo string) (*Subscr
}
sub := new(Subscription)
- resp, err := s.client.Do(req, sub)
+ resp, err := s.client.Do(ctx, req, sub)
if err != nil {
// if it's just a 404, don't return that as an error
_, err = parseBoolResponse(err)
@@ -108,7 +111,7 @@ func (s *ActivityService) GetRepositorySubscription(owner, repo string) (*Subscr
// To stop watching a repository, use DeleteRepositorySubscription.
//
// GitHub API Docs: https://developer.github.com/v3/activity/watching/#set-a-repository-subscription
-func (s *ActivityService) SetRepositorySubscription(owner, repo string, subscription *Subscription) (*Subscription, *Response, error) {
+func (s *ActivityService) SetRepositorySubscription(ctx context.Context, owner, repo string, subscription *Subscription) (*Subscription, *Response, error) {
u := fmt.Sprintf("repos/%s/%s/subscription", owner, repo)
req, err := s.client.NewRequest("PUT", u, subscription)
@@ -117,7 +120,7 @@ func (s *ActivityService) SetRepositorySubscription(owner, repo string, subscrip
}
sub := new(Subscription)
- resp, err := s.client.Do(req, sub)
+ resp, err := s.client.Do(ctx, req, sub)
if err != nil {
return nil, resp, err
}
@@ -132,12 +135,12 @@ func (s *ActivityService) SetRepositorySubscription(owner, repo string, subscrip
// receive notifications from a repository, use SetRepositorySubscription.
//
// GitHub API Docs: https://developer.github.com/v3/activity/watching/#delete-a-repository-subscription
-func (s *ActivityService) DeleteRepositorySubscription(owner, repo string) (*Response, error) {
+func (s *ActivityService) DeleteRepositorySubscription(ctx context.Context, owner, repo string) (*Response, error) {
u := fmt.Sprintf("repos/%s/%s/subscription", owner, repo)
req, err := s.client.NewRequest("DELETE", u, nil)
if err != nil {
return nil, err
}
- return s.client.Do(req, nil)
+ return s.client.Do(ctx, req, nil)
}
diff --git a/github/activity_watching_test.go b/github/activity_watching_test.go
index 8989fd3eda8..d765f67e9e0 100644
--- a/github/activity_watching_test.go
+++ b/github/activity_watching_test.go
@@ -6,6 +6,7 @@
package github
import (
+ "context"
"encoding/json"
"fmt"
"net/http"
@@ -26,7 +27,7 @@ func TestActivityService_ListWatchers(t *testing.T) {
fmt.Fprint(w, `[{"id":1}]`)
})
- watchers, _, err := client.Activity.ListWatchers("o", "r", &ListOptions{Page: 2})
+ watchers, _, err := client.Activity.ListWatchers(context.Background(), "o", "r", &ListOptions{Page: 2})
if err != nil {
t.Errorf("Activity.ListWatchers returned error: %v", err)
}
@@ -49,7 +50,7 @@ func TestActivityService_ListWatched_authenticatedUser(t *testing.T) {
fmt.Fprint(w, `[{"id":1}]`)
})
- watched, _, err := client.Activity.ListWatched("", &ListOptions{Page: 2})
+ watched, _, err := client.Activity.ListWatched(context.Background(), "", &ListOptions{Page: 2})
if err != nil {
t.Errorf("Activity.ListWatched returned error: %v", err)
}
@@ -72,7 +73,7 @@ func TestActivityService_ListWatched_specifiedUser(t *testing.T) {
fmt.Fprint(w, `[{"id":1}]`)
})
- watched, _, err := client.Activity.ListWatched("u", &ListOptions{Page: 2})
+ watched, _, err := client.Activity.ListWatched(context.Background(), "u", &ListOptions{Page: 2})
if err != nil {
t.Errorf("Activity.ListWatched returned error: %v", err)
}
@@ -92,7 +93,7 @@ func TestActivityService_GetRepositorySubscription_true(t *testing.T) {
fmt.Fprint(w, `{"subscribed":true}`)
})
- sub, _, err := client.Activity.GetRepositorySubscription("o", "r")
+ sub, _, err := client.Activity.GetRepositorySubscription(context.Background(), "o", "r")
if err != nil {
t.Errorf("Activity.GetRepositorySubscription returned error: %v", err)
}
@@ -112,7 +113,7 @@ func TestActivityService_GetRepositorySubscription_false(t *testing.T) {
w.WriteHeader(http.StatusNotFound)
})
- sub, _, err := client.Activity.GetRepositorySubscription("o", "r")
+ sub, _, err := client.Activity.GetRepositorySubscription(context.Background(), "o", "r")
if err != nil {
t.Errorf("Activity.GetRepositorySubscription returned error: %v", err)
}
@@ -132,7 +133,7 @@ func TestActivityService_GetRepositorySubscription_error(t *testing.T) {
w.WriteHeader(http.StatusBadRequest)
})
- _, _, err := client.Activity.GetRepositorySubscription("o", "r")
+ _, _, err := client.Activity.GetRepositorySubscription(context.Background(), "o", "r")
if err == nil {
t.Errorf("Expected HTTP 400 response")
}
@@ -156,7 +157,7 @@ func TestActivityService_SetRepositorySubscription(t *testing.T) {
fmt.Fprint(w, `{"ignored":true}`)
})
- sub, _, err := client.Activity.SetRepositorySubscription("o", "r", input)
+ sub, _, err := client.Activity.SetRepositorySubscription(context.Background(), "o", "r", input)
if err != nil {
t.Errorf("Activity.SetRepositorySubscription returned error: %v", err)
}
@@ -176,7 +177,7 @@ func TestActivityService_DeleteRepositorySubscription(t *testing.T) {
w.WriteHeader(http.StatusNoContent)
})
- _, err := client.Activity.DeleteRepositorySubscription("o", "r")
+ _, err := client.Activity.DeleteRepositorySubscription(context.Background(), "o", "r")
if err != nil {
t.Errorf("Activity.DeleteRepositorySubscription returned error: %v", err)
}
diff --git a/github/admin.go b/github/admin.go
index f77b2a23fca..d0f055bcfa2 100644
--- a/github/admin.go
+++ b/github/admin.go
@@ -5,7 +5,10 @@
package github
-import "fmt"
+import (
+ "context"
+ "fmt"
+)
// AdminService handles communication with the admin related methods of the
// GitHub API. These API routes are normally only accessible for GitHub
@@ -62,7 +65,7 @@ func (m UserLDAPMapping) String() string {
// UpdateUserLDAPMapping updates the mapping between a GitHub user and an LDAP user.
//
// GitHub API docs: https://developer.github.com/v3/enterprise/ldap/#update-ldap-mapping-for-a-user
-func (s *AdminService) UpdateUserLDAPMapping(user string, mapping *UserLDAPMapping) (*UserLDAPMapping, *Response, error) {
+func (s *AdminService) UpdateUserLDAPMapping(ctx context.Context, user string, mapping *UserLDAPMapping) (*UserLDAPMapping, *Response, error) {
u := fmt.Sprintf("admin/ldap/users/%v/mapping", user)
req, err := s.client.NewRequest("PATCH", u, mapping)
if err != nil {
@@ -70,7 +73,7 @@ func (s *AdminService) UpdateUserLDAPMapping(user string, mapping *UserLDAPMappi
}
m := new(UserLDAPMapping)
- resp, err := s.client.Do(req, m)
+ resp, err := s.client.Do(ctx, req, m)
if err != nil {
return nil, resp, err
}
@@ -81,7 +84,7 @@ func (s *AdminService) UpdateUserLDAPMapping(user string, mapping *UserLDAPMappi
// UpdateTeamLDAPMapping updates the mapping between a GitHub team and an LDAP group.
//
// GitHub API docs: https://developer.github.com/v3/enterprise/ldap/#update-ldap-mapping-for-a-team
-func (s *AdminService) UpdateTeamLDAPMapping(team int, mapping *TeamLDAPMapping) (*TeamLDAPMapping, *Response, error) {
+func (s *AdminService) UpdateTeamLDAPMapping(ctx context.Context, team int, mapping *TeamLDAPMapping) (*TeamLDAPMapping, *Response, error) {
u := fmt.Sprintf("admin/ldap/teams/%v/mapping", team)
req, err := s.client.NewRequest("PATCH", u, mapping)
if err != nil {
@@ -89,7 +92,7 @@ func (s *AdminService) UpdateTeamLDAPMapping(team int, mapping *TeamLDAPMapping)
}
m := new(TeamLDAPMapping)
- resp, err := s.client.Do(req, m)
+ resp, err := s.client.Do(ctx, req, m)
if err != nil {
return nil, resp, err
}
diff --git a/github/admin_test.go b/github/admin_test.go
index f4f2e5a2223..32a870eb407 100644
--- a/github/admin_test.go
+++ b/github/admin_test.go
@@ -6,6 +6,7 @@
package github
import (
+ "context"
"encoding/json"
"fmt"
"net/http"
@@ -32,7 +33,7 @@ func TestAdminService_UpdateUserLDAPMapping(t *testing.T) {
fmt.Fprint(w, `{"id":1,"ldap_dn":"uid=asdf,ou=users,dc=github,dc=com"}`)
})
- mapping, _, err := client.Admin.UpdateUserLDAPMapping("u", input)
+ mapping, _, err := client.Admin.UpdateUserLDAPMapping(context.Background(), "u", input)
if err != nil {
t.Errorf("Admin.UpdateUserLDAPMapping returned error: %v", err)
}
@@ -65,7 +66,7 @@ func TestAdminService_UpdateTeamLDAPMapping(t *testing.T) {
fmt.Fprint(w, `{"id":1,"ldap_dn":"cn=Enterprise Ops,ou=teams,dc=github,dc=com"}`)
})
- mapping, _, err := client.Admin.UpdateTeamLDAPMapping(1, input)
+ mapping, _, err := client.Admin.UpdateTeamLDAPMapping(context.Background(), 1, input)
if err != nil {
t.Errorf("Admin.UpdateTeamLDAPMapping returned error: %v", err)
}
diff --git a/github/authorizations.go b/github/authorizations.go
index b50de5eec70..661b2674926 100644
--- a/github/authorizations.go
+++ b/github/authorizations.go
@@ -5,7 +5,10 @@
package github
-import "fmt"
+import (
+ "context"
+ "fmt"
+)
// Scope models a GitHub authorization scope.
//
@@ -134,7 +137,7 @@ func (a AuthorizationUpdateRequest) String() string {
// List the authorizations for the authenticated user.
//
// GitHub API docs: https://developer.github.com/v3/oauth_authorizations/#list-your-authorizations
-func (s *AuthorizationsService) List(opt *ListOptions) ([]*Authorization, *Response, error) {
+func (s *AuthorizationsService) List(ctx context.Context, opt *ListOptions) ([]*Authorization, *Response, error) {
u := "authorizations"
u, err := addOptions(u, opt)
if err != nil {
@@ -147,7 +150,7 @@ func (s *AuthorizationsService) List(opt *ListOptions) ([]*Authorization, *Respo
}
var auths []*Authorization
- resp, err := s.client.Do(req, &auths)
+ resp, err := s.client.Do(ctx, req, &auths)
if err != nil {
return nil, resp, err
}
@@ -157,7 +160,7 @@ func (s *AuthorizationsService) List(opt *ListOptions) ([]*Authorization, *Respo
// Get a single authorization.
//
// GitHub API docs: https://developer.github.com/v3/oauth_authorizations/#get-a-single-authorization
-func (s *AuthorizationsService) Get(id int) (*Authorization, *Response, error) {
+func (s *AuthorizationsService) Get(ctx context.Context, id int) (*Authorization, *Response, error) {
u := fmt.Sprintf("authorizations/%d", id)
req, err := s.client.NewRequest("GET", u, nil)
@@ -166,7 +169,7 @@ func (s *AuthorizationsService) Get(id int) (*Authorization, *Response, error) {
}
a := new(Authorization)
- resp, err := s.client.Do(req, a)
+ resp, err := s.client.Do(ctx, req, a)
if err != nil {
return nil, resp, err
}
@@ -176,7 +179,7 @@ func (s *AuthorizationsService) Get(id int) (*Authorization, *Response, error) {
// Create a new authorization for the specified OAuth application.
//
// GitHub API docs: https://developer.github.com/v3/oauth_authorizations/#create-a-new-authorization
-func (s *AuthorizationsService) Create(auth *AuthorizationRequest) (*Authorization, *Response, error) {
+func (s *AuthorizationsService) Create(ctx context.Context, auth *AuthorizationRequest) (*Authorization, *Response, error) {
u := "authorizations"
req, err := s.client.NewRequest("POST", u, auth)
@@ -185,7 +188,7 @@ func (s *AuthorizationsService) Create(auth *AuthorizationRequest) (*Authorizati
}
a := new(Authorization)
- resp, err := s.client.Do(req, a)
+ resp, err := s.client.Do(ctx, req, a)
if err != nil {
return nil, resp, err
}
@@ -206,7 +209,7 @@ func (s *AuthorizationsService) Create(auth *AuthorizationRequest) (*Authorizati
// GitHub API docs:
// - https://developer.github.com/v3/oauth_authorizations/#get-or-create-an-authorization-for-a-specific-app
// - https://developer.github.com/v3/oauth_authorizations/#get-or-create-an-authorization-for-a-specific-app-and-fingerprint
-func (s *AuthorizationsService) GetOrCreateForApp(clientID string, auth *AuthorizationRequest) (*Authorization, *Response, error) {
+func (s *AuthorizationsService) GetOrCreateForApp(ctx context.Context, clientID string, auth *AuthorizationRequest) (*Authorization, *Response, error) {
var u string
if auth.Fingerprint == nil || *auth.Fingerprint == "" {
u = fmt.Sprintf("authorizations/clients/%v", clientID)
@@ -220,7 +223,7 @@ func (s *AuthorizationsService) GetOrCreateForApp(clientID string, auth *Authori
}
a := new(Authorization)
- resp, err := s.client.Do(req, a)
+ resp, err := s.client.Do(ctx, req, a)
if err != nil {
return nil, resp, err
}
@@ -231,7 +234,7 @@ func (s *AuthorizationsService) GetOrCreateForApp(clientID string, auth *Authori
// Edit a single authorization.
//
// GitHub API docs: https://developer.github.com/v3/oauth_authorizations/#update-an-existing-authorization
-func (s *AuthorizationsService) Edit(id int, auth *AuthorizationUpdateRequest) (*Authorization, *Response, error) {
+func (s *AuthorizationsService) Edit(ctx context.Context, id int, auth *AuthorizationUpdateRequest) (*Authorization, *Response, error) {
u := fmt.Sprintf("authorizations/%d", id)
req, err := s.client.NewRequest("PATCH", u, auth)
@@ -240,7 +243,7 @@ func (s *AuthorizationsService) Edit(id int, auth *AuthorizationUpdateRequest) (
}
a := new(Authorization)
- resp, err := s.client.Do(req, a)
+ resp, err := s.client.Do(ctx, req, a)
if err != nil {
return nil, resp, err
}
@@ -251,7 +254,7 @@ func (s *AuthorizationsService) Edit(id int, auth *AuthorizationUpdateRequest) (
// Delete a single authorization.
//
// GitHub API docs: https://developer.github.com/v3/oauth_authorizations/#delete-an-authorization
-func (s *AuthorizationsService) Delete(id int) (*Response, error) {
+func (s *AuthorizationsService) Delete(ctx context.Context, id int) (*Response, error) {
u := fmt.Sprintf("authorizations/%d", id)
req, err := s.client.NewRequest("DELETE", u, nil)
@@ -259,7 +262,7 @@ func (s *AuthorizationsService) Delete(id int) (*Response, error) {
return nil, err
}
- return s.client.Do(req, nil)
+ return s.client.Do(ctx, req, nil)
}
// Check if an OAuth token is valid for a specific app.
@@ -271,7 +274,7 @@ func (s *AuthorizationsService) Delete(id int) (*Response, error) {
// The returned Authorization.User field will be populated.
//
// GitHub API docs: https://developer.github.com/v3/oauth_authorizations/#check-an-authorization
-func (s *AuthorizationsService) Check(clientID string, token string) (*Authorization, *Response, error) {
+func (s *AuthorizationsService) Check(ctx context.Context, clientID string, token string) (*Authorization, *Response, error) {
u := fmt.Sprintf("applications/%v/tokens/%v", clientID, token)
req, err := s.client.NewRequest("GET", u, nil)
@@ -280,7 +283,7 @@ func (s *AuthorizationsService) Check(clientID string, token string) (*Authoriza
}
a := new(Authorization)
- resp, err := s.client.Do(req, a)
+ resp, err := s.client.Do(ctx, req, a)
if err != nil {
return nil, resp, err
}
@@ -299,7 +302,7 @@ func (s *AuthorizationsService) Check(clientID string, token string) (*Authoriza
// The returned Authorization.User field will be populated.
//
// GitHub API docs: https://developer.github.com/v3/oauth_authorizations/#reset-an-authorization
-func (s *AuthorizationsService) Reset(clientID string, token string) (*Authorization, *Response, error) {
+func (s *AuthorizationsService) Reset(ctx context.Context, clientID string, token string) (*Authorization, *Response, error) {
u := fmt.Sprintf("applications/%v/tokens/%v", clientID, token)
req, err := s.client.NewRequest("POST", u, nil)
@@ -308,7 +311,7 @@ func (s *AuthorizationsService) Reset(clientID string, token string) (*Authoriza
}
a := new(Authorization)
- resp, err := s.client.Do(req, a)
+ resp, err := s.client.Do(ctx, req, a)
if err != nil {
return nil, resp, err
}
@@ -323,7 +326,7 @@ func (s *AuthorizationsService) Reset(clientID string, token string) (*Authoriza
// clientSecret. Invalid tokens will return a 404 Not Found.
//
// GitHub API docs: https://developer.github.com/v3/oauth_authorizations/#revoke-an-authorization-for-an-application
-func (s *AuthorizationsService) Revoke(clientID string, token string) (*Response, error) {
+func (s *AuthorizationsService) Revoke(ctx context.Context, clientID string, token string) (*Response, error) {
u := fmt.Sprintf("applications/%v/tokens/%v", clientID, token)
req, err := s.client.NewRequest("DELETE", u, nil)
@@ -331,7 +334,7 @@ func (s *AuthorizationsService) Revoke(clientID string, token string) (*Response
return nil, err
}
- return s.client.Do(req, nil)
+ return s.client.Do(ctx, req, nil)
}
// ListGrants lists the set of OAuth applications that have been granted
@@ -340,14 +343,14 @@ func (s *AuthorizationsService) Revoke(clientID string, token string) (*Response
// tokens an application has generated for the user.
//
// GitHub API docs: https://developer.github.com/v3/oauth_authorizations/#list-your-grants
-func (s *AuthorizationsService) ListGrants() ([]*Grant, *Response, error) {
+func (s *AuthorizationsService) ListGrants(ctx context.Context) ([]*Grant, *Response, error) {
req, err := s.client.NewRequest("GET", "applications/grants", nil)
if err != nil {
return nil, nil, err
}
grants := []*Grant{}
- resp, err := s.client.Do(req, &grants)
+ resp, err := s.client.Do(ctx, req, &grants)
if err != nil {
return nil, resp, err
}
@@ -358,7 +361,7 @@ func (s *AuthorizationsService) ListGrants() ([]*Grant, *Response, error) {
// GetGrant gets a single OAuth application grant.
//
// GitHub API docs: https://developer.github.com/v3/oauth_authorizations/#get-a-single-grant
-func (s *AuthorizationsService) GetGrant(id int) (*Grant, *Response, error) {
+func (s *AuthorizationsService) GetGrant(ctx context.Context, id int) (*Grant, *Response, error) {
u := fmt.Sprintf("applications/grants/%d", id)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
@@ -366,7 +369,7 @@ func (s *AuthorizationsService) GetGrant(id int) (*Grant, *Response, error) {
}
grant := new(Grant)
- resp, err := s.client.Do(req, grant)
+ resp, err := s.client.Do(ctx, req, grant)
if err != nil {
return nil, resp, err
}
@@ -379,14 +382,14 @@ func (s *AuthorizationsService) GetGrant(id int) (*Grant, *Response, error) {
// the user.
//
// GitHub API docs: https://developer.github.com/v3/oauth_authorizations/#delete-a-grant
-func (s *AuthorizationsService) DeleteGrant(id int) (*Response, error) {
+func (s *AuthorizationsService) DeleteGrant(ctx context.Context, id int) (*Response, error) {
u := fmt.Sprintf("applications/grants/%d", id)
req, err := s.client.NewRequest("DELETE", u, nil)
if err != nil {
return nil, err
}
- return s.client.Do(req, nil)
+ return s.client.Do(ctx, req, nil)
}
// CreateImpersonation creates an impersonation OAuth token.
@@ -396,7 +399,7 @@ func (s *AuthorizationsService) DeleteGrant(id int) (*Response, error) {
// new token automatically revokes an existing one.
//
// GitHub API docs: https://developer.github.com/enterprise/2.5/v3/users/administration/#create-an-impersonation-oauth-token
-func (s *AuthorizationsService) CreateImpersonation(username string, authReq *AuthorizationRequest) (*Authorization, *Response, error) {
+func (s *AuthorizationsService) CreateImpersonation(ctx context.Context, username string, authReq *AuthorizationRequest) (*Authorization, *Response, error) {
u := fmt.Sprintf("admin/users/%v/authorizations", username)
req, err := s.client.NewRequest("POST", u, authReq)
if err != nil {
@@ -404,7 +407,7 @@ func (s *AuthorizationsService) CreateImpersonation(username string, authReq *Au
}
a := new(Authorization)
- resp, err := s.client.Do(req, a)
+ resp, err := s.client.Do(ctx, req, a)
if err != nil {
return nil, resp, err
}
@@ -416,12 +419,12 @@ func (s *AuthorizationsService) CreateImpersonation(username string, authReq *Au
// NOTE: there can be only one at a time.
//
// GitHub API docs: https://developer.github.com/enterprise/2.5/v3/users/administration/#delete-an-impersonation-oauth-token
-func (s *AuthorizationsService) DeleteImpersonation(username string) (*Response, error) {
+func (s *AuthorizationsService) DeleteImpersonation(ctx context.Context, username string) (*Response, error) {
u := fmt.Sprintf("admin/users/%v/authorizations", username)
req, err := s.client.NewRequest("DELETE", u, nil)
if err != nil {
return nil, err
}
- return s.client.Do(req, nil)
+ return s.client.Do(ctx, req, nil)
}
diff --git a/github/authorizations_test.go b/github/authorizations_test.go
index 621cf78f841..e18bcd060fc 100644
--- a/github/authorizations_test.go
+++ b/github/authorizations_test.go
@@ -6,6 +6,7 @@
package github
import (
+ "context"
"encoding/json"
"fmt"
"net/http"
@@ -24,7 +25,7 @@ func TestAuthorizationsService_List(t *testing.T) {
})
opt := &ListOptions{Page: 1, PerPage: 2}
- got, _, err := client.Authorizations.List(opt)
+ got, _, err := client.Authorizations.List(context.Background(), opt)
if err != nil {
t.Errorf("Authorizations.List returned error: %v", err)
}
@@ -44,7 +45,7 @@ func TestAuthorizationsService_Get(t *testing.T) {
fmt.Fprint(w, `{"id":1}`)
})
- got, _, err := client.Authorizations.Get(1)
+ got, _, err := client.Authorizations.Get(context.Background(), 1)
if err != nil {
t.Errorf("Authorizations.Get returned error: %v", err)
}
@@ -75,7 +76,7 @@ func TestAuthorizationsService_Create(t *testing.T) {
fmt.Fprint(w, `{"ID":1}`)
})
- got, _, err := client.Authorizations.Create(input)
+ got, _, err := client.Authorizations.Create(context.Background(), input)
if err != nil {
t.Errorf("Authorizations.Create returned error: %v", err)
}
@@ -106,7 +107,7 @@ func TestAuthorizationsService_GetOrCreateForApp(t *testing.T) {
fmt.Fprint(w, `{"ID":1}`)
})
- got, _, err := client.Authorizations.GetOrCreateForApp("id", input)
+ got, _, err := client.Authorizations.GetOrCreateForApp(context.Background(), "id", input)
if err != nil {
t.Errorf("Authorizations.GetOrCreateForApp returned error: %v", err)
}
@@ -138,7 +139,7 @@ func TestAuthorizationsService_GetOrCreateForApp_Fingerprint(t *testing.T) {
fmt.Fprint(w, `{"ID":1}`)
})
- got, _, err := client.Authorizations.GetOrCreateForApp("id", input)
+ got, _, err := client.Authorizations.GetOrCreateForApp(context.Background(), "id", input)
if err != nil {
t.Errorf("Authorizations.GetOrCreateForApp returned error: %v", err)
}
@@ -169,7 +170,7 @@ func TestAuthorizationsService_Edit(t *testing.T) {
fmt.Fprint(w, `{"ID":1}`)
})
- got, _, err := client.Authorizations.Edit(1, input)
+ got, _, err := client.Authorizations.Edit(context.Background(), 1, input)
if err != nil {
t.Errorf("Authorizations.Edit returned error: %v", err)
}
@@ -189,7 +190,7 @@ func TestAuthorizationsService_Delete(t *testing.T) {
w.WriteHeader(http.StatusNoContent)
})
- _, err := client.Authorizations.Delete(1)
+ _, err := client.Authorizations.Delete(context.Background(), 1)
if err != nil {
t.Errorf("Authorizations.Delete returned error: %v", err)
}
@@ -204,7 +205,7 @@ func TestAuthorizationsService_Check(t *testing.T) {
fmt.Fprint(w, `{"id":1}`)
})
- got, _, err := client.Authorizations.Check("id", "t")
+ got, _, err := client.Authorizations.Check(context.Background(), "id", "t")
if err != nil {
t.Errorf("Authorizations.Check returned error: %v", err)
}
@@ -224,7 +225,7 @@ func TestAuthorizationsService_Reset(t *testing.T) {
fmt.Fprint(w, `{"ID":1}`)
})
- got, _, err := client.Authorizations.Reset("id", "t")
+ got, _, err := client.Authorizations.Reset(context.Background(), "id", "t")
if err != nil {
t.Errorf("Authorizations.Reset returned error: %v", err)
}
@@ -244,7 +245,7 @@ func TestAuthorizationsService_Revoke(t *testing.T) {
w.WriteHeader(http.StatusNoContent)
})
- _, err := client.Authorizations.Revoke("id", "t")
+ _, err := client.Authorizations.Revoke(context.Background(), "id", "t")
if err != nil {
t.Errorf("Authorizations.Revoke returned error: %v", err)
}
@@ -259,7 +260,7 @@ func TestListGrants(t *testing.T) {
fmt.Fprint(w, `[{"id": 1}]`)
})
- got, _, err := client.Authorizations.ListGrants()
+ got, _, err := client.Authorizations.ListGrants(context.Background())
if err != nil {
t.Errorf("OAuthAuthorizations.ListGrants returned error: %v", err)
}
@@ -279,7 +280,7 @@ func TestGetGrant(t *testing.T) {
fmt.Fprint(w, `{"id": 1}`)
})
- got, _, err := client.Authorizations.GetGrant(1)
+ got, _, err := client.Authorizations.GetGrant(context.Background(), 1)
if err != nil {
t.Errorf("OAuthAuthorizations.GetGrant returned error: %v", err)
}
@@ -298,7 +299,7 @@ func TestDeleteGrant(t *testing.T) {
testMethod(t, r, "DELETE")
})
- _, err := client.Authorizations.DeleteGrant(1)
+ _, err := client.Authorizations.DeleteGrant(context.Background(), 1)
if err != nil {
t.Errorf("OAuthAuthorizations.DeleteGrant returned error: %v", err)
}
@@ -314,7 +315,7 @@ func TestAuthorizationsService_CreateImpersonation(t *testing.T) {
})
req := &AuthorizationRequest{Scopes: []Scope{ScopePublicRepo}}
- got, _, err := client.Authorizations.CreateImpersonation("u", req)
+ got, _, err := client.Authorizations.CreateImpersonation(context.Background(), "u", req)
if err != nil {
t.Errorf("Authorizations.CreateImpersonation returned error: %+v", err)
}
@@ -333,7 +334,7 @@ func TestAuthorizationsService_DeleteImpersonation(t *testing.T) {
testMethod(t, r, "DELETE")
})
- _, err := client.Authorizations.DeleteImpersonation("u")
+ _, err := client.Authorizations.DeleteImpersonation(context.Background(), "u")
if err != nil {
t.Errorf("Authorizations.DeleteImpersonation returned error: %+v", err)
}
diff --git a/github/examples_test.go b/github/examples_test.go
index 7b754cd2e25..f09d6505ac7 100644
--- a/github/examples_test.go
+++ b/github/examples_test.go
@@ -6,6 +6,7 @@
package github_test
import (
+ "context"
"fmt"
"log"
@@ -18,7 +19,7 @@ func ExampleClient_Markdown() {
input := "# heading #\n\nLink to issue #1"
opt := &github.MarkdownOptions{Mode: "gfm", Context: "google/go-github"}
- output, _, err := client.Markdown(input, opt)
+ output, _, err := client.Markdown(context.Background(), input, opt)
if err != nil {
fmt.Println(err)
}
@@ -29,7 +30,7 @@ func ExampleClient_Markdown() {
func ExampleRepositoriesService_GetReadme() {
client := github.NewClient(nil)
- readme, _, err := client.Repositories.GetReadme("google", "go-github", nil)
+ readme, _, err := client.Repositories.GetReadme(context.Background(), "google", "go-github", nil)
if err != nil {
fmt.Println(err)
return
@@ -50,7 +51,7 @@ func ExampleRepositoriesService_List() {
user := "willnorris"
opt := &github.RepositoryListOptions{Type: "owner", Sort: "updated", Direction: "desc"}
- repos, _, err := client.Repositories.List(user, opt)
+ repos, _, err := client.Repositories.List(context.Background(), user, opt)
if err != nil {
fmt.Println(err)
}
@@ -62,7 +63,7 @@ func ExampleUsersService_ListAll() {
client := github.NewClient(nil)
opts := &github.UserListOptions{}
for {
- users, _, err := client.Users.ListAll(opts)
+ users, _, err := client.Users.ListAll(context.Background(), opts)
if err != nil {
log.Fatalf("error listing users: %v", err)
}
diff --git a/github/gists.go b/github/gists.go
index f727f5494ab..732538c78f3 100644
--- a/github/gists.go
+++ b/github/gists.go
@@ -6,6 +6,7 @@
package github
import (
+ "context"
"fmt"
"time"
)
@@ -93,7 +94,7 @@ type GistListOptions struct {
// user.
//
// GitHub API docs: https://developer.github.com/v3/gists/#list-gists
-func (s *GistsService) List(user string, opt *GistListOptions) ([]*Gist, *Response, error) {
+func (s *GistsService) List(ctx context.Context, user string, opt *GistListOptions) ([]*Gist, *Response, error) {
var u string
if user != "" {
u = fmt.Sprintf("users/%v/gists", user)
@@ -111,7 +112,7 @@ func (s *GistsService) List(user string, opt *GistListOptions) ([]*Gist, *Respon
}
var gists []*Gist
- resp, err := s.client.Do(req, &gists)
+ resp, err := s.client.Do(ctx, req, &gists)
if err != nil {
return nil, resp, err
}
@@ -122,7 +123,7 @@ func (s *GistsService) List(user string, opt *GistListOptions) ([]*Gist, *Respon
// ListAll lists all public gists.
//
// GitHub API docs: https://developer.github.com/v3/gists/#list-gists
-func (s *GistsService) ListAll(opt *GistListOptions) ([]*Gist, *Response, error) {
+func (s *GistsService) ListAll(ctx context.Context, opt *GistListOptions) ([]*Gist, *Response, error) {
u, err := addOptions("gists/public", opt)
if err != nil {
return nil, nil, err
@@ -134,7 +135,7 @@ func (s *GistsService) ListAll(opt *GistListOptions) ([]*Gist, *Response, error)
}
var gists []*Gist
- resp, err := s.client.Do(req, &gists)
+ resp, err := s.client.Do(ctx, req, &gists)
if err != nil {
return nil, resp, err
}
@@ -145,7 +146,7 @@ func (s *GistsService) ListAll(opt *GistListOptions) ([]*Gist, *Response, error)
// ListStarred lists starred gists of authenticated user.
//
// GitHub API docs: https://developer.github.com/v3/gists/#list-gists
-func (s *GistsService) ListStarred(opt *GistListOptions) ([]*Gist, *Response, error) {
+func (s *GistsService) ListStarred(ctx context.Context, opt *GistListOptions) ([]*Gist, *Response, error) {
u, err := addOptions("gists/starred", opt)
if err != nil {
return nil, nil, err
@@ -157,7 +158,7 @@ func (s *GistsService) ListStarred(opt *GistListOptions) ([]*Gist, *Response, er
}
var gists []*Gist
- resp, err := s.client.Do(req, &gists)
+ resp, err := s.client.Do(ctx, req, &gists)
if err != nil {
return nil, resp, err
}
@@ -168,14 +169,14 @@ func (s *GistsService) ListStarred(opt *GistListOptions) ([]*Gist, *Response, er
// Get a single gist.
//
// GitHub API docs: https://developer.github.com/v3/gists/#get-a-single-gist
-func (s *GistsService) Get(id string) (*Gist, *Response, error) {
+func (s *GistsService) Get(ctx context.Context, id string) (*Gist, *Response, error) {
u := fmt.Sprintf("gists/%v", id)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}
gist := new(Gist)
- resp, err := s.client.Do(req, gist)
+ resp, err := s.client.Do(ctx, req, gist)
if err != nil {
return nil, resp, err
}
@@ -186,14 +187,14 @@ func (s *GistsService) Get(id string) (*Gist, *Response, error) {
// GetRevision gets a specific revision of a gist.
//
// GitHub API docs: https://developer.github.com/v3/gists/#get-a-specific-revision-of-a-gist
-func (s *GistsService) GetRevision(id, sha string) (*Gist, *Response, error) {
+func (s *GistsService) GetRevision(ctx context.Context, id, sha string) (*Gist, *Response, error) {
u := fmt.Sprintf("gists/%v/%v", id, sha)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}
gist := new(Gist)
- resp, err := s.client.Do(req, gist)
+ resp, err := s.client.Do(ctx, req, gist)
if err != nil {
return nil, resp, err
}
@@ -204,14 +205,14 @@ func (s *GistsService) GetRevision(id, sha string) (*Gist, *Response, error) {
// Create a gist for authenticated user.
//
// GitHub API docs: https://developer.github.com/v3/gists/#create-a-gist
-func (s *GistsService) Create(gist *Gist) (*Gist, *Response, error) {
+func (s *GistsService) Create(ctx context.Context, gist *Gist) (*Gist, *Response, error) {
u := "gists"
req, err := s.client.NewRequest("POST", u, gist)
if err != nil {
return nil, nil, err
}
g := new(Gist)
- resp, err := s.client.Do(req, g)
+ resp, err := s.client.Do(ctx, req, g)
if err != nil {
return nil, resp, err
}
@@ -222,14 +223,14 @@ func (s *GistsService) Create(gist *Gist) (*Gist, *Response, error) {
// Edit a gist.
//
// GitHub API docs: https://developer.github.com/v3/gists/#edit-a-gist
-func (s *GistsService) Edit(id string, gist *Gist) (*Gist, *Response, error) {
+func (s *GistsService) Edit(ctx context.Context, id string, gist *Gist) (*Gist, *Response, error) {
u := fmt.Sprintf("gists/%v", id)
req, err := s.client.NewRequest("PATCH", u, gist)
if err != nil {
return nil, nil, err
}
g := new(Gist)
- resp, err := s.client.Do(req, g)
+ resp, err := s.client.Do(ctx, req, g)
if err != nil {
return nil, resp, err
}
@@ -240,7 +241,7 @@ func (s *GistsService) Edit(id string, gist *Gist) (*Gist, *Response, error) {
// ListCommits lists commits of a gist.
//
// Github API docs: https://developer.github.com/v3/gists/#list-gist-commits
-func (s *GistsService) ListCommits(id string) ([]*GistCommit, *Response, error) {
+func (s *GistsService) ListCommits(ctx context.Context, id string) ([]*GistCommit, *Response, error) {
u := fmt.Sprintf("gists/%v/commits", id)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
@@ -248,7 +249,7 @@ func (s *GistsService) ListCommits(id string) ([]*GistCommit, *Response, error)
}
var gistCommits []*GistCommit
- resp, err := s.client.Do(req, &gistCommits)
+ resp, err := s.client.Do(ctx, req, &gistCommits)
if err != nil {
return nil, resp, err
}
@@ -259,49 +260,49 @@ func (s *GistsService) ListCommits(id string) ([]*GistCommit, *Response, error)
// Delete a gist.
//
// GitHub API docs: https://developer.github.com/v3/gists/#delete-a-gist
-func (s *GistsService) Delete(id string) (*Response, error) {
+func (s *GistsService) Delete(ctx context.Context, id string) (*Response, error) {
u := fmt.Sprintf("gists/%v", id)
req, err := s.client.NewRequest("DELETE", u, nil)
if err != nil {
return nil, err
}
- return s.client.Do(req, nil)
+ return s.client.Do(ctx, req, nil)
}
// Star a gist on behalf of authenticated user.
//
// GitHub API docs: https://developer.github.com/v3/gists/#star-a-gist
-func (s *GistsService) Star(id string) (*Response, error) {
+func (s *GistsService) Star(ctx context.Context, id string) (*Response, error) {
u := fmt.Sprintf("gists/%v/star", id)
req, err := s.client.NewRequest("PUT", u, nil)
if err != nil {
return nil, err
}
- return s.client.Do(req, nil)
+ return s.client.Do(ctx, req, nil)
}
// Unstar a gist on a behalf of authenticated user.
//
// Github API docs: https://developer.github.com/v3/gists/#unstar-a-gist
-func (s *GistsService) Unstar(id string) (*Response, error) {
+func (s *GistsService) Unstar(ctx context.Context, id string) (*Response, error) {
u := fmt.Sprintf("gists/%v/star", id)
req, err := s.client.NewRequest("DELETE", u, nil)
if err != nil {
return nil, err
}
- return s.client.Do(req, nil)
+ return s.client.Do(ctx, req, nil)
}
// IsStarred checks if a gist is starred by authenticated user.
//
// GitHub API docs: https://developer.github.com/v3/gists/#check-if-a-gist-is-starred
-func (s *GistsService) IsStarred(id string) (bool, *Response, error) {
+func (s *GistsService) IsStarred(ctx context.Context, id string) (bool, *Response, error) {
u := fmt.Sprintf("gists/%v/star", id)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return false, nil, err
}
- resp, err := s.client.Do(req, nil)
+ resp, err := s.client.Do(ctx, req, nil)
starred, err := parseBoolResponse(err)
return starred, resp, err
}
@@ -309,7 +310,7 @@ func (s *GistsService) IsStarred(id string) (bool, *Response, error) {
// Fork a gist.
//
// GitHub API docs: https://developer.github.com/v3/gists/#fork-a-gist
-func (s *GistsService) Fork(id string) (*Gist, *Response, error) {
+func (s *GistsService) Fork(ctx context.Context, id string) (*Gist, *Response, error) {
u := fmt.Sprintf("gists/%v/forks", id)
req, err := s.client.NewRequest("POST", u, nil)
if err != nil {
@@ -317,7 +318,7 @@ func (s *GistsService) Fork(id string) (*Gist, *Response, error) {
}
g := new(Gist)
- resp, err := s.client.Do(req, g)
+ resp, err := s.client.Do(ctx, req, g)
if err != nil {
return nil, resp, err
}
@@ -328,7 +329,7 @@ func (s *GistsService) Fork(id string) (*Gist, *Response, error) {
// ListForks lists forks of a gist.
//
// Github API docs: https://developer.github.com/v3/gists/#list-gist-forks
-func (s *GistsService) ListForks(id string) ([]*GistFork, *Response, error) {
+func (s *GistsService) ListForks(ctx context.Context, id string) ([]*GistFork, *Response, error) {
u := fmt.Sprintf("gists/%v/forks", id)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
@@ -336,7 +337,7 @@ func (s *GistsService) ListForks(id string) ([]*GistFork, *Response, error) {
}
var gistForks []*GistFork
- resp, err := s.client.Do(req, &gistForks)
+ resp, err := s.client.Do(ctx, req, &gistForks)
if err != nil {
return nil, resp, err
}
diff --git a/github/gists_comments.go b/github/gists_comments.go
index 84af61cd153..2d0722375e0 100644
--- a/github/gists_comments.go
+++ b/github/gists_comments.go
@@ -6,6 +6,7 @@
package github
import (
+ "context"
"fmt"
"time"
)
@@ -26,7 +27,7 @@ func (g GistComment) String() string {
// ListComments lists all comments for a gist.
//
// GitHub API docs: https://developer.github.com/v3/gists/comments/#list-comments-on-a-gist
-func (s *GistsService) ListComments(gistID string, opt *ListOptions) ([]*GistComment, *Response, error) {
+func (s *GistsService) ListComments(ctx context.Context, gistID string, opt *ListOptions) ([]*GistComment, *Response, error) {
u := fmt.Sprintf("gists/%v/comments", gistID)
u, err := addOptions(u, opt)
if err != nil {
@@ -39,7 +40,7 @@ func (s *GistsService) ListComments(gistID string, opt *ListOptions) ([]*GistCom
}
var comments []*GistComment
- resp, err := s.client.Do(req, &comments)
+ resp, err := s.client.Do(ctx, req, &comments)
if err != nil {
return nil, resp, err
}
@@ -50,7 +51,7 @@ func (s *GistsService) ListComments(gistID string, opt *ListOptions) ([]*GistCom
// GetComment retrieves a single comment from a gist.
//
// GitHub API docs: https://developer.github.com/v3/gists/comments/#get-a-single-comment
-func (s *GistsService) GetComment(gistID string, commentID int) (*GistComment, *Response, error) {
+func (s *GistsService) GetComment(ctx context.Context, gistID string, commentID int) (*GistComment, *Response, error) {
u := fmt.Sprintf("gists/%v/comments/%v", gistID, commentID)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
@@ -58,7 +59,7 @@ func (s *GistsService) GetComment(gistID string, commentID int) (*GistComment, *
}
c := new(GistComment)
- resp, err := s.client.Do(req, c)
+ resp, err := s.client.Do(ctx, req, c)
if err != nil {
return nil, resp, err
}
@@ -69,7 +70,7 @@ func (s *GistsService) GetComment(gistID string, commentID int) (*GistComment, *
// CreateComment creates a comment for a gist.
//
// GitHub API docs: https://developer.github.com/v3/gists/comments/#create-a-comment
-func (s *GistsService) CreateComment(gistID string, comment *GistComment) (*GistComment, *Response, error) {
+func (s *GistsService) CreateComment(ctx context.Context, gistID string, comment *GistComment) (*GistComment, *Response, error) {
u := fmt.Sprintf("gists/%v/comments", gistID)
req, err := s.client.NewRequest("POST", u, comment)
if err != nil {
@@ -77,7 +78,7 @@ func (s *GistsService) CreateComment(gistID string, comment *GistComment) (*Gist
}
c := new(GistComment)
- resp, err := s.client.Do(req, c)
+ resp, err := s.client.Do(ctx, req, c)
if err != nil {
return nil, resp, err
}
@@ -88,7 +89,7 @@ func (s *GistsService) CreateComment(gistID string, comment *GistComment) (*Gist
// EditComment edits an existing gist comment.
//
// GitHub API docs: https://developer.github.com/v3/gists/comments/#edit-a-comment
-func (s *GistsService) EditComment(gistID string, commentID int, comment *GistComment) (*GistComment, *Response, error) {
+func (s *GistsService) EditComment(ctx context.Context, gistID string, commentID int, comment *GistComment) (*GistComment, *Response, error) {
u := fmt.Sprintf("gists/%v/comments/%v", gistID, commentID)
req, err := s.client.NewRequest("PATCH", u, comment)
if err != nil {
@@ -96,7 +97,7 @@ func (s *GistsService) EditComment(gistID string, commentID int, comment *GistCo
}
c := new(GistComment)
- resp, err := s.client.Do(req, c)
+ resp, err := s.client.Do(ctx, req, c)
if err != nil {
return nil, resp, err
}
@@ -107,12 +108,12 @@ func (s *GistsService) EditComment(gistID string, commentID int, comment *GistCo
// DeleteComment deletes a gist comment.
//
// GitHub API docs: https://developer.github.com/v3/gists/comments/#delete-a-comment
-func (s *GistsService) DeleteComment(gistID string, commentID int) (*Response, error) {
+func (s *GistsService) DeleteComment(ctx context.Context, gistID string, commentID int) (*Response, error) {
u := fmt.Sprintf("gists/%v/comments/%v", gistID, commentID)
req, err := s.client.NewRequest("DELETE", u, nil)
if err != nil {
return nil, err
}
- return s.client.Do(req, nil)
+ return s.client.Do(ctx, req, nil)
}
diff --git a/github/gists_comments_test.go b/github/gists_comments_test.go
index eacd89f9c2a..4b6841363ea 100644
--- a/github/gists_comments_test.go
+++ b/github/gists_comments_test.go
@@ -6,6 +6,7 @@
package github
import (
+ "context"
"encoding/json"
"fmt"
"net/http"
@@ -24,7 +25,7 @@ func TestGistsService_ListComments(t *testing.T) {
})
opt := &ListOptions{Page: 2}
- comments, _, err := client.Gists.ListComments("1", opt)
+ comments, _, err := client.Gists.ListComments(context.Background(), "1", opt)
if err != nil {
t.Errorf("Gists.Comments returned error: %v", err)
}
@@ -36,7 +37,7 @@ func TestGistsService_ListComments(t *testing.T) {
}
func TestGistsService_ListComments_invalidID(t *testing.T) {
- _, _, err := client.Gists.ListComments("%", nil)
+ _, _, err := client.Gists.ListComments(context.Background(), "%", nil)
testURLParseError(t, err)
}
@@ -49,7 +50,7 @@ func TestGistsService_GetComment(t *testing.T) {
fmt.Fprint(w, `{"id": 1}`)
})
- comment, _, err := client.Gists.GetComment("1", 2)
+ comment, _, err := client.Gists.GetComment(context.Background(), "1", 2)
if err != nil {
t.Errorf("Gists.GetComment returned error: %v", err)
}
@@ -61,7 +62,7 @@ func TestGistsService_GetComment(t *testing.T) {
}
func TestGistsService_GetComment_invalidID(t *testing.T) {
- _, _, err := client.Gists.GetComment("%", 1)
+ _, _, err := client.Gists.GetComment(context.Background(), "%", 1)
testURLParseError(t, err)
}
@@ -83,7 +84,7 @@ func TestGistsService_CreateComment(t *testing.T) {
fmt.Fprint(w, `{"id":1}`)
})
- comment, _, err := client.Gists.CreateComment("1", input)
+ comment, _, err := client.Gists.CreateComment(context.Background(), "1", input)
if err != nil {
t.Errorf("Gists.CreateComment returned error: %v", err)
}
@@ -95,7 +96,7 @@ func TestGistsService_CreateComment(t *testing.T) {
}
func TestGistsService_CreateComment_invalidID(t *testing.T) {
- _, _, err := client.Gists.CreateComment("%", nil)
+ _, _, err := client.Gists.CreateComment(context.Background(), "%", nil)
testURLParseError(t, err)
}
@@ -117,7 +118,7 @@ func TestGistsService_EditComment(t *testing.T) {
fmt.Fprint(w, `{"id":1}`)
})
- comment, _, err := client.Gists.EditComment("1", 2, input)
+ comment, _, err := client.Gists.EditComment(context.Background(), "1", 2, input)
if err != nil {
t.Errorf("Gists.EditComment returned error: %v", err)
}
@@ -129,7 +130,7 @@ func TestGistsService_EditComment(t *testing.T) {
}
func TestGistsService_EditComment_invalidID(t *testing.T) {
- _, _, err := client.Gists.EditComment("%", 1, nil)
+ _, _, err := client.Gists.EditComment(context.Background(), "%", 1, nil)
testURLParseError(t, err)
}
@@ -141,13 +142,13 @@ func TestGistsService_DeleteComment(t *testing.T) {
testMethod(t, r, "DELETE")
})
- _, err := client.Gists.DeleteComment("1", 2)
+ _, err := client.Gists.DeleteComment(context.Background(), "1", 2)
if err != nil {
t.Errorf("Gists.Delete returned error: %v", err)
}
}
func TestGistsService_DeleteComment_invalidID(t *testing.T) {
- _, err := client.Gists.DeleteComment("%", 1)
+ _, err := client.Gists.DeleteComment(context.Background(), "%", 1)
testURLParseError(t, err)
}
diff --git a/github/gists_test.go b/github/gists_test.go
index 0b081ae967f..b8d7feea532 100644
--- a/github/gists_test.go
+++ b/github/gists_test.go
@@ -6,6 +6,7 @@
package github
import (
+ "context"
"encoding/json"
"fmt"
"net/http"
@@ -29,7 +30,7 @@ func TestGistsService_List_specifiedUser(t *testing.T) {
})
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(context.Background(), "u", opt)
if err != nil {
t.Errorf("Gists.List returned error: %v", err)
}
@@ -49,7 +50,7 @@ func TestGistsService_List_authenticatedUser(t *testing.T) {
fmt.Fprint(w, `[{"id": "1"}]`)
})
- gists, _, err := client.Gists.List("", nil)
+ gists, _, err := client.Gists.List(context.Background(), "", nil)
if err != nil {
t.Errorf("Gists.List returned error: %v", err)
}
@@ -61,7 +62,7 @@ func TestGistsService_List_authenticatedUser(t *testing.T) {
}
func TestGistsService_List_invalidUser(t *testing.T) {
- _, _, err := client.Gists.List("%", nil)
+ _, _, err := client.Gists.List(context.Background(), "%", nil)
testURLParseError(t, err)
}
@@ -80,7 +81,7 @@ func TestGistsService_ListAll(t *testing.T) {
})
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(context.Background(), opt)
if err != nil {
t.Errorf("Gists.ListAll returned error: %v", err)
}
@@ -106,7 +107,7 @@ func TestGistsService_ListStarred(t *testing.T) {
})
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(context.Background(), opt)
if err != nil {
t.Errorf("Gists.ListStarred returned error: %v", err)
}
@@ -126,7 +127,7 @@ func TestGistsService_Get(t *testing.T) {
fmt.Fprint(w, `{"id": "1"}`)
})
- gist, _, err := client.Gists.Get("1")
+ gist, _, err := client.Gists.Get(context.Background(), "1")
if err != nil {
t.Errorf("Gists.Get returned error: %v", err)
}
@@ -138,7 +139,7 @@ func TestGistsService_Get(t *testing.T) {
}
func TestGistsService_Get_invalidID(t *testing.T) {
- _, _, err := client.Gists.Get("%")
+ _, _, err := client.Gists.Get(context.Background(), "%")
testURLParseError(t, err)
}
@@ -151,7 +152,7 @@ func TestGistsService_GetRevision(t *testing.T) {
fmt.Fprint(w, `{"id": "1"}`)
})
- gist, _, err := client.Gists.GetRevision("1", "s")
+ gist, _, err := client.Gists.GetRevision(context.Background(), "1", "s")
if err != nil {
t.Errorf("Gists.Get returned error: %v", err)
}
@@ -163,7 +164,7 @@ func TestGistsService_GetRevision(t *testing.T) {
}
func TestGistsService_GetRevision_invalidID(t *testing.T) {
- _, _, err := client.Gists.GetRevision("%", "%")
+ _, _, err := client.Gists.GetRevision(context.Background(), "%", "%")
testURLParseError(t, err)
}
@@ -202,7 +203,7 @@ func TestGistsService_Create(t *testing.T) {
}`)
})
- gist, _, err := client.Gists.Create(input)
+ gist, _, err := client.Gists.Create(context.Background(), input)
if err != nil {
t.Errorf("Gists.Create returned error: %v", err)
}
@@ -257,7 +258,7 @@ func TestGistsService_Edit(t *testing.T) {
}`)
})
- gist, _, err := client.Gists.Edit("1", input)
+ gist, _, err := client.Gists.Edit(context.Background(), "1", input)
if err != nil {
t.Errorf("Gists.Edit returned error: %v", err)
}
@@ -277,7 +278,7 @@ func TestGistsService_Edit(t *testing.T) {
}
func TestGistsService_Edit_invalidID(t *testing.T) {
- _, _, err := client.Gists.Edit("%", nil)
+ _, _, err := client.Gists.Edit(context.Background(), "%", nil)
testURLParseError(t, err)
}
@@ -307,7 +308,7 @@ func TestGistsService_ListCommits(t *testing.T) {
`)
})
- gistCommits, _, err := client.Gists.ListCommits("1")
+ gistCommits, _, err := client.Gists.ListCommits(context.Background(), "1")
if err != nil {
t.Errorf("Gists.ListCommits returned error: %v", err)
}
@@ -336,14 +337,14 @@ func TestGistsService_Delete(t *testing.T) {
testMethod(t, r, "DELETE")
})
- _, err := client.Gists.Delete("1")
+ _, err := client.Gists.Delete(context.Background(), "1")
if err != nil {
t.Errorf("Gists.Delete returned error: %v", err)
}
}
func TestGistsService_Delete_invalidID(t *testing.T) {
- _, err := client.Gists.Delete("%")
+ _, err := client.Gists.Delete(context.Background(), "%")
testURLParseError(t, err)
}
@@ -355,14 +356,14 @@ func TestGistsService_Star(t *testing.T) {
testMethod(t, r, "PUT")
})
- _, err := client.Gists.Star("1")
+ _, err := client.Gists.Star(context.Background(), "1")
if err != nil {
t.Errorf("Gists.Star returned error: %v", err)
}
}
func TestGistsService_Star_invalidID(t *testing.T) {
- _, err := client.Gists.Star("%")
+ _, err := client.Gists.Star(context.Background(), "%")
testURLParseError(t, err)
}
@@ -374,14 +375,14 @@ func TestGistsService_Unstar(t *testing.T) {
testMethod(t, r, "DELETE")
})
- _, err := client.Gists.Unstar("1")
+ _, err := client.Gists.Unstar(context.Background(), "1")
if err != nil {
t.Errorf("Gists.Unstar returned error: %v", err)
}
}
func TestGistsService_Unstar_invalidID(t *testing.T) {
- _, err := client.Gists.Unstar("%")
+ _, err := client.Gists.Unstar(context.Background(), "%")
testURLParseError(t, err)
}
@@ -394,7 +395,7 @@ func TestGistsService_IsStarred_hasStar(t *testing.T) {
w.WriteHeader(http.StatusNoContent)
})
- star, _, err := client.Gists.IsStarred("1")
+ star, _, err := client.Gists.IsStarred(context.Background(), "1")
if err != nil {
t.Errorf("Gists.Starred returned error: %v", err)
}
@@ -412,7 +413,7 @@ func TestGistsService_IsStarred_noStar(t *testing.T) {
w.WriteHeader(http.StatusNotFound)
})
- star, _, err := client.Gists.IsStarred("1")
+ star, _, err := client.Gists.IsStarred(context.Background(), "1")
if err != nil {
t.Errorf("Gists.Starred returned error: %v", err)
}
@@ -422,7 +423,7 @@ func TestGistsService_IsStarred_noStar(t *testing.T) {
}
func TestGistsService_IsStarred_invalidID(t *testing.T) {
- _, _, err := client.Gists.IsStarred("%")
+ _, _, err := client.Gists.IsStarred(context.Background(), "%")
testURLParseError(t, err)
}
@@ -435,7 +436,7 @@ func TestGistsService_Fork(t *testing.T) {
fmt.Fprint(w, `{"id": "2"}`)
})
- gist, _, err := client.Gists.Fork("1")
+ gist, _, err := client.Gists.Fork(context.Background(), "1")
if err != nil {
t.Errorf("Gists.Fork returned error: %v", err)
}
@@ -465,7 +466,7 @@ func TestGistsService_ListForks(t *testing.T) {
`)
})
- gistForks, _, err := client.Gists.ListForks("1")
+ gistForks, _, err := client.Gists.ListForks(context.Background(), "1")
if err != nil {
t.Errorf("Gists.ListForks returned error: %v", err)
}
@@ -483,6 +484,6 @@ func TestGistsService_ListForks(t *testing.T) {
}
func TestGistsService_Fork_invalidID(t *testing.T) {
- _, _, err := client.Gists.Fork("%")
+ _, _, err := client.Gists.Fork(context.Background(), "%")
testURLParseError(t, err)
}
diff --git a/github/git_blobs.go b/github/git_blobs.go
index 5a46708d890..67ea74a1967 100644
--- a/github/git_blobs.go
+++ b/github/git_blobs.go
@@ -5,7 +5,10 @@
package github
-import "fmt"
+import (
+ "context"
+ "fmt"
+)
// Blob represents a blob object.
type Blob struct {
@@ -19,7 +22,7 @@ type Blob struct {
// GetBlob fetchs a blob from a repo given a SHA.
//
// GitHub API docs: https://developer.github.com/v3/git/blobs/#get-a-blob
-func (s *GitService) GetBlob(owner string, repo string, sha string) (*Blob, *Response, error) {
+func (s *GitService) GetBlob(ctx context.Context, owner string, repo string, sha string) (*Blob, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/git/blobs/%v", owner, repo, sha)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
@@ -27,14 +30,14 @@ func (s *GitService) GetBlob(owner string, repo string, sha string) (*Blob, *Res
}
blob := new(Blob)
- resp, err := s.client.Do(req, blob)
+ resp, err := s.client.Do(ctx, req, blob)
return blob, resp, err
}
// CreateBlob creates a blob object.
//
// GitHub API docs: https://developer.github.com/v3/git/blobs/#create-a-blob
-func (s *GitService) CreateBlob(owner string, repo string, blob *Blob) (*Blob, *Response, error) {
+func (s *GitService) CreateBlob(ctx context.Context, owner string, repo string, blob *Blob) (*Blob, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/git/blobs", owner, repo)
req, err := s.client.NewRequest("POST", u, blob)
if err != nil {
@@ -42,6 +45,6 @@ func (s *GitService) CreateBlob(owner string, repo string, blob *Blob) (*Blob, *
}
t := new(Blob)
- resp, err := s.client.Do(req, t)
+ resp, err := s.client.Do(ctx, req, t)
return t, resp, err
}
diff --git a/github/git_blobs_test.go b/github/git_blobs_test.go
index 9530e161fb8..00861bb9a64 100644
--- a/github/git_blobs_test.go
+++ b/github/git_blobs_test.go
@@ -6,6 +6,7 @@
package github
import (
+ "context"
"encoding/json"
"fmt"
"net/http"
@@ -27,7 +28,7 @@ func TestGitService_GetBlob(t *testing.T) {
}`)
})
- blob, _, err := client.Git.GetBlob("o", "r", "s")
+ blob, _, err := client.Git.GetBlob(context.Background(), "o", "r", "s")
if err != nil {
t.Errorf("Git.GetBlob returned error: %v", err)
}
@@ -43,7 +44,7 @@ func TestGitService_GetBlob(t *testing.T) {
}
func TestGitService_GetBlob_invalidOwner(t *testing.T) {
- _, _, err := client.Git.GetBlob("%", "%", "%")
+ _, _, err := client.Git.GetBlob(context.Background(), "%", "%", "%")
testURLParseError(t, err)
}
@@ -79,7 +80,7 @@ func TestGitService_CreateBlob(t *testing.T) {
}`)
})
- blob, _, err := client.Git.CreateBlob("o", "r", input)
+ blob, _, err := client.Git.CreateBlob(context.Background(), "o", "r", input)
if err != nil {
t.Errorf("Git.CreateBlob returned error: %v", err)
}
@@ -92,6 +93,6 @@ func TestGitService_CreateBlob(t *testing.T) {
}
func TestGitService_CreateBlob_invalidOwner(t *testing.T) {
- _, _, err := client.Git.CreateBlob("%", "%", &Blob{})
+ _, _, err := client.Git.CreateBlob(context.Background(), "%", "%", &Blob{})
testURLParseError(t, err)
}
diff --git a/github/git_commits.go b/github/git_commits.go
index 29e05740d69..b0c4da7b6db 100644
--- a/github/git_commits.go
+++ b/github/git_commits.go
@@ -6,6 +6,7 @@
package github
import (
+ "context"
"fmt"
"time"
)
@@ -58,7 +59,7 @@ func (c CommitAuthor) String() string {
// GetCommit fetchs the Commit object for a given SHA.
//
// GitHub API docs: https://developer.github.com/v3/git/commits/#get-a-commit
-func (s *GitService) GetCommit(owner string, repo string, sha string) (*Commit, *Response, error) {
+func (s *GitService) GetCommit(ctx context.Context, owner string, repo string, sha string) (*Commit, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/git/commits/%v", owner, repo, sha)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
@@ -69,7 +70,7 @@ func (s *GitService) GetCommit(owner string, repo string, sha string) (*Commit,
req.Header.Set("Accept", mediaTypeGitSigningPreview)
c := new(Commit)
- resp, err := s.client.Do(req, c)
+ resp, err := s.client.Do(ctx, req, c)
if err != nil {
return nil, resp, err
}
@@ -93,7 +94,7 @@ type createCommit struct {
// the authenticated user’s information and the current date.
//
// GitHub API docs: https://developer.github.com/v3/git/commits/#create-a-commit
-func (s *GitService) CreateCommit(owner string, repo string, commit *Commit) (*Commit, *Response, error) {
+func (s *GitService) CreateCommit(ctx context.Context, owner string, repo string, commit *Commit) (*Commit, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/git/commits", owner, repo)
body := &createCommit{}
@@ -118,7 +119,7 @@ func (s *GitService) CreateCommit(owner string, repo string, commit *Commit) (*C
}
c := new(Commit)
- resp, err := s.client.Do(req, c)
+ resp, err := s.client.Do(ctx, req, c)
if err != nil {
return nil, resp, err
}
diff --git a/github/git_commits_test.go b/github/git_commits_test.go
index 566ac4f9eb0..8f718e47233 100644
--- a/github/git_commits_test.go
+++ b/github/git_commits_test.go
@@ -6,6 +6,7 @@
package github
import (
+ "context"
"encoding/json"
"fmt"
"net/http"
@@ -23,7 +24,7 @@ func TestGitService_GetCommit(t *testing.T) {
fmt.Fprint(w, `{"sha":"s","message":"m","author":{"name":"n"}}`)
})
- commit, _, err := client.Git.GetCommit("o", "r", "s")
+ commit, _, err := client.Git.GetCommit(context.Background(), "o", "r", "s")
if err != nil {
t.Errorf("Git.GetCommit returned error: %v", err)
}
@@ -35,7 +36,7 @@ func TestGitService_GetCommit(t *testing.T) {
}
func TestGitService_GetCommit_invalidOwner(t *testing.T) {
- _, _, err := client.Git.GetCommit("%", "%", "%")
+ _, _, err := client.Git.GetCommit(context.Background(), "%", "%", "%")
testURLParseError(t, err)
}
@@ -66,7 +67,7 @@ func TestGitService_CreateCommit(t *testing.T) {
fmt.Fprint(w, `{"sha":"s"}`)
})
- commit, _, err := client.Git.CreateCommit("o", "r", input)
+ commit, _, err := client.Git.CreateCommit(context.Background(), "o", "r", input)
if err != nil {
t.Errorf("Git.CreateCommit returned error: %v", err)
}
@@ -78,6 +79,6 @@ func TestGitService_CreateCommit(t *testing.T) {
}
func TestGitService_CreateCommit_invalidOwner(t *testing.T) {
- _, _, err := client.Git.CreateCommit("%", "%", nil)
+ _, _, err := client.Git.CreateCommit(context.Background(), "%", "%", nil)
testURLParseError(t, err)
}
diff --git a/github/git_refs.go b/github/git_refs.go
index bcec615f769..bd5df3f72ad 100644
--- a/github/git_refs.go
+++ b/github/git_refs.go
@@ -6,6 +6,7 @@
package github
import (
+ "context"
"fmt"
"strings"
)
@@ -47,7 +48,7 @@ type updateRefRequest struct {
// GetRef fetches the Reference object for a given Git ref.
//
// GitHub API docs: https://developer.github.com/v3/git/refs/#get-a-reference
-func (s *GitService) GetRef(owner string, repo string, ref string) (*Reference, *Response, error) {
+func (s *GitService) GetRef(ctx context.Context, owner string, repo string, ref string) (*Reference, *Response, error) {
ref = strings.TrimPrefix(ref, "refs/")
u := fmt.Sprintf("repos/%v/%v/git/refs/%v", owner, repo, ref)
req, err := s.client.NewRequest("GET", u, nil)
@@ -56,7 +57,7 @@ func (s *GitService) GetRef(owner string, repo string, ref string) (*Reference,
}
r := new(Reference)
- resp, err := s.client.Do(req, r)
+ resp, err := s.client.Do(ctx, req, r)
if err != nil {
return nil, resp, err
}
@@ -75,7 +76,7 @@ type ReferenceListOptions struct {
// ListRefs lists all refs in a repository.
//
// GitHub API docs: https://developer.github.com/v3/git/refs/#get-all-references
-func (s *GitService) ListRefs(owner, repo string, opt *ReferenceListOptions) ([]*Reference, *Response, error) {
+func (s *GitService) ListRefs(ctx context.Context, owner, repo string, opt *ReferenceListOptions) ([]*Reference, *Response, error) {
var u string
if opt != nil && opt.Type != "" {
u = fmt.Sprintf("repos/%v/%v/git/refs/%v", owner, repo, opt.Type)
@@ -93,7 +94,7 @@ func (s *GitService) ListRefs(owner, repo string, opt *ReferenceListOptions) ([]
}
var rs []*Reference
- resp, err := s.client.Do(req, &rs)
+ resp, err := s.client.Do(ctx, req, &rs)
if err != nil {
return nil, resp, err
}
@@ -104,7 +105,7 @@ func (s *GitService) ListRefs(owner, repo string, opt *ReferenceListOptions) ([]
// CreateRef creates a new ref in a repository.
//
// GitHub API docs: https://developer.github.com/v3/git/refs/#create-a-reference
-func (s *GitService) CreateRef(owner string, repo string, ref *Reference) (*Reference, *Response, error) {
+func (s *GitService) CreateRef(ctx context.Context, owner string, repo string, ref *Reference) (*Reference, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/git/refs", owner, repo)
req, err := s.client.NewRequest("POST", u, &createRefRequest{
// back-compat with previous behavior that didn't require 'refs/' prefix
@@ -116,7 +117,7 @@ func (s *GitService) CreateRef(owner string, repo string, ref *Reference) (*Refe
}
r := new(Reference)
- resp, err := s.client.Do(req, r)
+ resp, err := s.client.Do(ctx, req, r)
if err != nil {
return nil, resp, err
}
@@ -127,7 +128,7 @@ func (s *GitService) CreateRef(owner string, repo string, ref *Reference) (*Refe
// UpdateRef updates an existing ref in a repository.
//
// GitHub API docs: https://developer.github.com/v3/git/refs/#update-a-reference
-func (s *GitService) UpdateRef(owner string, repo string, ref *Reference, force bool) (*Reference, *Response, error) {
+func (s *GitService) UpdateRef(ctx context.Context, owner string, repo string, ref *Reference, force bool) (*Reference, *Response, error) {
refPath := strings.TrimPrefix(*ref.Ref, "refs/")
u := fmt.Sprintf("repos/%v/%v/git/refs/%v", owner, repo, refPath)
req, err := s.client.NewRequest("PATCH", u, &updateRefRequest{
@@ -139,7 +140,7 @@ func (s *GitService) UpdateRef(owner string, repo string, ref *Reference, force
}
r := new(Reference)
- resp, err := s.client.Do(req, r)
+ resp, err := s.client.Do(ctx, req, r)
if err != nil {
return nil, resp, err
}
@@ -150,7 +151,7 @@ func (s *GitService) UpdateRef(owner string, repo string, ref *Reference, force
// DeleteRef deletes a ref from a repository.
//
// GitHub API docs: https://developer.github.com/v3/git/refs/#delete-a-reference
-func (s *GitService) DeleteRef(owner string, repo string, ref string) (*Response, error) {
+func (s *GitService) DeleteRef(ctx context.Context, owner string, repo string, ref string) (*Response, error) {
ref = strings.TrimPrefix(ref, "refs/")
u := fmt.Sprintf("repos/%v/%v/git/refs/%v", owner, repo, ref)
req, err := s.client.NewRequest("DELETE", u, nil)
@@ -158,5 +159,5 @@ func (s *GitService) DeleteRef(owner string, repo string, ref string) (*Response
return nil, err
}
- return s.client.Do(req, nil)
+ return s.client.Do(ctx, req, nil)
}
diff --git a/github/git_refs_test.go b/github/git_refs_test.go
index cc4cd5ae220..915211ea92f 100644
--- a/github/git_refs_test.go
+++ b/github/git_refs_test.go
@@ -6,6 +6,7 @@
package github
import (
+ "context"
"encoding/json"
"fmt"
"net/http"
@@ -31,7 +32,7 @@ func TestGitService_GetRef(t *testing.T) {
}`)
})
- ref, _, err := client.Git.GetRef("o", "r", "refs/heads/b")
+ ref, _, err := client.Git.GetRef(context.Background(), "o", "r", "refs/heads/b")
if err != nil {
t.Errorf("Git.GetRef returned error: %v", err)
}
@@ -50,7 +51,7 @@ func TestGitService_GetRef(t *testing.T) {
}
// without 'refs/' prefix
- if _, _, err := client.Git.GetRef("o", "r", "heads/b"); err != nil {
+ if _, _, err := client.Git.GetRef(context.Background(), "o", "r", "heads/b"); err != nil {
t.Errorf("Git.GetRef returned error: %v", err)
}
}
@@ -84,7 +85,7 @@ func TestGitService_ListRefs(t *testing.T) {
]`)
})
- refs, _, err := client.Git.ListRefs("o", "r", nil)
+ refs, _, err := client.Git.ListRefs(context.Background(), "o", "r", nil)
if err != nil {
t.Errorf("Git.ListRefs returned error: %v", err)
}
@@ -125,7 +126,7 @@ func TestGitService_ListRefs_options(t *testing.T) {
})
opt := &ReferenceListOptions{Type: "t", ListOptions: ListOptions{Page: 2}}
- refs, _, err := client.Git.ListRefs("o", "r", opt)
+ refs, _, err := client.Git.ListRefs(context.Background(), "o", "r", opt)
if err != nil {
t.Errorf("Git.ListRefs returned error: %v", err)
}
@@ -165,7 +166,7 @@ func TestGitService_CreateRef(t *testing.T) {
}`)
})
- ref, _, err := client.Git.CreateRef("o", "r", &Reference{
+ ref, _, err := client.Git.CreateRef(context.Background(), "o", "r", &Reference{
Ref: String("refs/heads/b"),
Object: &GitObject{
SHA: String("aa218f56b14c9653891f9e74264a383fa43fefbd"),
@@ -189,7 +190,7 @@ func TestGitService_CreateRef(t *testing.T) {
}
// without 'refs/' prefix
- _, _, err = client.Git.CreateRef("o", "r", &Reference{
+ _, _, err = client.Git.CreateRef(context.Background(), "o", "r", &Reference{
Ref: String("heads/b"),
Object: &GitObject{
SHA: String("aa218f56b14c9653891f9e74264a383fa43fefbd"),
@@ -229,7 +230,7 @@ func TestGitService_UpdateRef(t *testing.T) {
}`)
})
- ref, _, err := client.Git.UpdateRef("o", "r", &Reference{
+ ref, _, err := client.Git.UpdateRef(context.Background(), "o", "r", &Reference{
Ref: String("refs/heads/b"),
Object: &GitObject{SHA: String("aa218f56b14c9653891f9e74264a383fa43fefbd")},
}, true)
@@ -251,7 +252,7 @@ func TestGitService_UpdateRef(t *testing.T) {
}
// without 'refs/' prefix
- _, _, err = client.Git.UpdateRef("o", "r", &Reference{
+ _, _, err = client.Git.UpdateRef(context.Background(), "o", "r", &Reference{
Ref: String("heads/b"),
Object: &GitObject{SHA: String("aa218f56b14c9653891f9e74264a383fa43fefbd")},
}, true)
@@ -268,13 +269,13 @@ func TestGitService_DeleteRef(t *testing.T) {
testMethod(t, r, "DELETE")
})
- _, err := client.Git.DeleteRef("o", "r", "refs/heads/b")
+ _, err := client.Git.DeleteRef(context.Background(), "o", "r", "refs/heads/b")
if err != nil {
t.Errorf("Git.DeleteRef returned error: %v", err)
}
// without 'refs/' prefix
- if _, err := client.Git.DeleteRef("o", "r", "heads/b"); err != nil {
+ if _, err := client.Git.DeleteRef(context.Background(), "o", "r", "heads/b"); err != nil {
t.Errorf("Git.DeleteRef returned error: %v", err)
}
}
diff --git a/github/git_tags.go b/github/git_tags.go
index a58858b3a76..08df3d3d1b1 100644
--- a/github/git_tags.go
+++ b/github/git_tags.go
@@ -6,6 +6,7 @@
package github
import (
+ "context"
"fmt"
)
@@ -34,7 +35,7 @@ type createTagRequest struct {
// GetTag fetchs a tag from a repo given a SHA.
//
// GitHub API docs: https://developer.github.com/v3/git/tags/#get-a-tag
-func (s *GitService) GetTag(owner string, repo string, sha string) (*Tag, *Response, error) {
+func (s *GitService) GetTag(ctx context.Context, owner string, repo string, sha string) (*Tag, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/git/tags/%v", owner, repo, sha)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
@@ -45,14 +46,14 @@ func (s *GitService) GetTag(owner string, repo string, sha string) (*Tag, *Respo
req.Header.Set("Accept", mediaTypeGitSigningPreview)
tag := new(Tag)
- resp, err := s.client.Do(req, tag)
+ resp, err := s.client.Do(ctx, req, tag)
return tag, resp, err
}
// CreateTag creates a tag object.
//
// GitHub API docs: https://developer.github.com/v3/git/tags/#create-a-tag-object
-func (s *GitService) CreateTag(owner string, repo string, tag *Tag) (*Tag, *Response, error) {
+func (s *GitService) CreateTag(ctx context.Context, owner string, repo string, tag *Tag) (*Tag, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/git/tags", owner, repo)
// convert Tag into a createTagRequest
@@ -72,6 +73,6 @@ func (s *GitService) CreateTag(owner string, repo string, tag *Tag) (*Tag, *Resp
}
t := new(Tag)
- resp, err := s.client.Do(req, t)
+ resp, err := s.client.Do(ctx, req, t)
return t, resp, err
}
diff --git a/github/git_tags_test.go b/github/git_tags_test.go
index c44361db822..7031fe8a4d3 100644
--- a/github/git_tags_test.go
+++ b/github/git_tags_test.go
@@ -6,6 +6,7 @@
package github
import (
+ "context"
"encoding/json"
"fmt"
"net/http"
@@ -24,7 +25,7 @@ func TestGitService_GetTag(t *testing.T) {
fmt.Fprint(w, `{"tag": "t"}`)
})
- tag, _, err := client.Git.GetTag("o", "r", "s")
+ tag, _, err := client.Git.GetTag(context.Background(), "o", "r", "s")
if err != nil {
t.Errorf("Git.GetTag returned error: %v", err)
}
@@ -53,7 +54,7 @@ func TestGitService_CreateTag(t *testing.T) {
fmt.Fprint(w, `{"tag": "t"}`)
})
- tag, _, err := client.Git.CreateTag("o", "r", &Tag{
+ tag, _, err := client.Git.CreateTag(context.Background(), "o", "r", &Tag{
Tag: input.Tag,
Object: &GitObject{SHA: input.Object},
})
diff --git a/github/git_trees.go b/github/git_trees.go
index 13acfa6497d..bdd481f1ee1 100644
--- a/github/git_trees.go
+++ b/github/git_trees.go
@@ -5,7 +5,10 @@
package github
-import "fmt"
+import (
+ "context"
+ "fmt"
+)
// Tree represents a GitHub tree.
type Tree struct {
@@ -36,7 +39,7 @@ func (t TreeEntry) String() string {
// GetTree fetches the Tree object for a given sha hash from a repository.
//
// GitHub API docs: https://developer.github.com/v3/git/trees/#get-a-tree
-func (s *GitService) GetTree(owner string, repo string, sha string, recursive bool) (*Tree, *Response, error) {
+func (s *GitService) GetTree(ctx context.Context, owner string, repo string, sha string, recursive bool) (*Tree, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/git/trees/%v", owner, repo, sha)
if recursive {
u += "?recursive=1"
@@ -48,7 +51,7 @@ func (s *GitService) GetTree(owner string, repo string, sha string, recursive bo
}
t := new(Tree)
- resp, err := s.client.Do(req, t)
+ resp, err := s.client.Do(ctx, req, t)
if err != nil {
return nil, resp, err
}
@@ -67,7 +70,7 @@ type createTree struct {
// that tree with the new path contents and write a new tree out.
//
// GitHub API docs: https://developer.github.com/v3/git/trees/#create-a-tree
-func (s *GitService) CreateTree(owner string, repo string, baseTree string, entries []TreeEntry) (*Tree, *Response, error) {
+func (s *GitService) CreateTree(ctx context.Context, owner string, repo string, baseTree string, entries []TreeEntry) (*Tree, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/git/trees", owner, repo)
body := &createTree{
@@ -80,7 +83,7 @@ func (s *GitService) CreateTree(owner string, repo string, baseTree string, entr
}
t := new(Tree)
- resp, err := s.client.Do(req, t)
+ resp, err := s.client.Do(ctx, req, t)
if err != nil {
return nil, resp, err
}
diff --git a/github/git_trees_test.go b/github/git_trees_test.go
index 99ec4f34cc6..2854a77eba2 100644
--- a/github/git_trees_test.go
+++ b/github/git_trees_test.go
@@ -6,6 +6,7 @@
package github
import (
+ "context"
"encoding/json"
"fmt"
"net/http"
@@ -27,7 +28,7 @@ func TestGitService_GetTree(t *testing.T) {
}`)
})
- tree, _, err := client.Git.GetTree("o", "r", "s", true)
+ tree, _, err := client.Git.GetTree(context.Background(), "o", "r", "s", true)
if err != nil {
t.Errorf("Git.GetTree returned error: %v", err)
}
@@ -46,7 +47,7 @@ func TestGitService_GetTree(t *testing.T) {
}
func TestGitService_GetTree_invalidOwner(t *testing.T) {
- _, _, err := client.Git.GetTree("%", "%", "%", false)
+ _, _, err := client.Git.GetTree(context.Background(), "%", "%", "%", false)
testURLParseError(t, err)
}
@@ -93,7 +94,7 @@ func TestGitService_CreateTree(t *testing.T) {
}`)
})
- tree, _, err := client.Git.CreateTree("o", "r", "b", input)
+ tree, _, err := client.Git.CreateTree(context.Background(), "o", "r", "b", input)
if err != nil {
t.Errorf("Git.CreateTree returned error: %v", err)
}
@@ -160,7 +161,7 @@ func TestGitService_CreateTree_Content(t *testing.T) {
}`)
})
- tree, _, err := client.Git.CreateTree("o", "r", "b", input)
+ tree, _, err := client.Git.CreateTree(context.Background(), "o", "r", "b", input)
if err != nil {
t.Errorf("Git.CreateTree returned error: %v", err)
}
@@ -184,6 +185,6 @@ func TestGitService_CreateTree_Content(t *testing.T) {
}
func TestGitService_CreateTree_invalidOwner(t *testing.T) {
- _, _, err := client.Git.CreateTree("%", "%", "", nil)
+ _, _, err := client.Git.CreateTree(context.Background(), "%", "%", "", nil)
testURLParseError(t, err)
}
diff --git a/github/github.go b/github/github.go
index 379ec06d9e6..23fcd75bb5b 100644
--- a/github/github.go
+++ b/github/github.go
@@ -7,6 +7,7 @@ package github
import (
"bytes"
+ "context"
"encoding/json"
"errors"
"fmt"
@@ -384,7 +385,12 @@ func parseRate(r *http.Response) Rate {
// interface, the raw response body will be written to v, without attempting to
// first decode it. If rate limit is exceeded and reset time is in the future,
// Do returns *RateLimitError immediately without making a network API call.
-func (c *Client) Do(req *http.Request, v interface{}) (*Response, error) {
+//
+// The provided ctx must be non-nil. If it is canceled or times out,
+// ctx.Err() will be returned.
+func (c *Client) Do(ctx context.Context, req *http.Request, v interface{}) (*Response, error) {
+ req = req.WithContext(ctx)
+
rateLimitCategory := category(req.URL.Path)
// If we've hit rate limit, don't make further requests before Reset time.
@@ -394,12 +400,22 @@ func (c *Client) Do(req *http.Request, v interface{}) (*Response, error) {
resp, err := c.client.Do(req)
if err != nil {
+ // If we got an error, and the context has been canceled,
+ // the context's error is probably more useful.
+ select {
+ case <-ctx.Done():
+ return nil, ctx.Err()
+ default:
+ }
+
+ // If the error type is *url.Error, sanitize its URL before returning.
if e, ok := err.(*url.Error); ok {
if url, err := url.Parse(e.URL); err == nil {
e.URL = sanitizeURL(url).String()
return nil, e
}
}
+
return nil, err
}
@@ -713,7 +729,7 @@ func category(path string) rateLimitCategory {
}
// RateLimits returns the rate limits for the current client.
-func (c *Client) RateLimits() (*RateLimits, *Response, error) {
+func (c *Client) RateLimits(ctx context.Context) (*RateLimits, *Response, error) {
req, err := c.NewRequest("GET", "rate_limit", nil)
if err != nil {
return nil, nil, err
@@ -722,7 +738,7 @@ func (c *Client) RateLimits() (*RateLimits, *Response, error) {
response := new(struct {
Resources *RateLimits `json:"resources"`
})
- resp, err := c.Do(req, response)
+ resp, err := c.Do(ctx, req, response)
if err != nil {
return nil, nil, err
}
diff --git a/github/github_test.go b/github/github_test.go
index 89a14dc6da3..b0686922299 100644
--- a/github/github_test.go
+++ b/github/github_test.go
@@ -7,6 +7,7 @@ package github
import (
"bytes"
+ "context"
"encoding/json"
"fmt"
"io/ioutil"
@@ -329,7 +330,7 @@ func TestDo(t *testing.T) {
req, _ := client.NewRequest("GET", "/", nil)
body := new(foo)
- client.Do(req, body)
+ client.Do(context.Background(), req, body)
want := &foo{"a"}
if !reflect.DeepEqual(body, want) {
@@ -346,7 +347,7 @@ func TestDo_httpError(t *testing.T) {
})
req, _ := client.NewRequest("GET", "/", nil)
- _, err := client.Do(req, nil)
+ _, err := client.Do(context.Background(), req, nil)
if err == nil {
t.Error("Expected HTTP 400 error.")
@@ -365,7 +366,7 @@ func TestDo_redirectLoop(t *testing.T) {
})
req, _ := client.NewRequest("GET", "/", nil)
- _, err := client.Do(req, nil)
+ _, err := client.Do(context.Background(), req, nil)
if err == nil {
t.Error("Expected error to be returned.")
@@ -388,7 +389,7 @@ func TestDo_sanitizeURL(t *testing.T) {
if err != nil {
t.Fatalf("NewRequest returned unexpected error: %v", err)
}
- _, err = unauthedClient.Do(req, nil)
+ _, err = unauthedClient.Do(context.Background(), req, nil)
if err == nil {
t.Fatal("Expected error to be returned.")
}
@@ -408,7 +409,7 @@ func TestDo_rateLimit(t *testing.T) {
})
req, _ := client.NewRequest("GET", "/", nil)
- resp, err := client.Do(req, nil)
+ resp, err := client.Do(context.Background(), req, nil)
if err != nil {
t.Errorf("Do returned unexpected error: %v", err)
}
@@ -437,7 +438,7 @@ func TestDo_rateLimit_errorResponse(t *testing.T) {
})
req, _ := client.NewRequest("GET", "/", nil)
- resp, err := client.Do(req, nil)
+ resp, err := client.Do(context.Background(), req, nil)
if err == nil {
t.Error("Expected error to be returned.")
}
@@ -474,7 +475,7 @@ func TestDo_rateLimit_rateLimitError(t *testing.T) {
})
req, _ := client.NewRequest("GET", "/", nil)
- _, err := client.Do(req, nil)
+ _, err := client.Do(context.Background(), req, nil)
if err == nil {
t.Error("Expected error to be returned.")
@@ -521,11 +522,11 @@ func TestDo_rateLimit_noNetworkCall(t *testing.T) {
// First request is made, and it makes the client aware of rate reset time being in the future.
req, _ := client.NewRequest("GET", "/first", nil)
- client.Do(req, nil)
+ client.Do(context.Background(), req, nil)
// Second request should not cause a network call to be made, since client can predict a rate limit error.
req, _ = client.NewRequest("GET", "/second", nil)
- _, err := client.Do(req, nil)
+ _, err := client.Do(context.Background(), req, nil)
if madeNetworkCall {
t.Fatal("Network call was made, even though rate limit is known to still be exceeded.")
@@ -567,7 +568,7 @@ func TestDo_rateLimit_abuseRateLimitError(t *testing.T) {
})
req, _ := client.NewRequest("GET", "/", nil)
- _, err := client.Do(req, nil)
+ _, err := client.Do(context.Background(), req, nil)
if err == nil {
t.Error("Expected error to be returned.")
@@ -597,7 +598,7 @@ func TestDo_rateLimit_abuseRateLimitError_retryAfter(t *testing.T) {
})
req, _ := client.NewRequest("GET", "/", nil)
- _, err := client.Do(req, nil)
+ _, err := client.Do(context.Background(), req, nil)
if err == nil {
t.Error("Expected error to be returned.")
@@ -625,7 +626,7 @@ func TestDo_noContent(t *testing.T) {
var body json.RawMessage
req, _ := client.NewRequest("GET", "/", nil)
- _, err := client.Do(req, &body)
+ _, err := client.Do(context.Background(), req, &body)
if err != nil {
t.Fatalf("Do returned unexpected error: %v", err)
}
@@ -767,7 +768,7 @@ func TestRateLimits(t *testing.T) {
}}`)
})
- rate, _, err := client.RateLimits()
+ rate, _, err := client.RateLimits(context.Background())
if err != nil {
t.Errorf("RateLimits returned error: %v", err)
}
@@ -818,7 +819,7 @@ func TestUnauthenticatedRateLimitedTransport(t *testing.T) {
unauthedClient := NewClient(tp.Client())
unauthedClient.BaseURL = client.BaseURL
req, _ := unauthedClient.NewRequest("GET", "/", nil)
- unauthedClient.Do(req, nil)
+ unauthedClient.Do(context.Background(), req, nil)
}
func TestUnauthenticatedRateLimitedTransport_missingFields(t *testing.T) {
@@ -892,7 +893,7 @@ func TestBasicAuthTransport(t *testing.T) {
basicAuthClient := NewClient(tp.Client())
basicAuthClient.BaseURL = client.BaseURL
req, _ := basicAuthClient.NewRequest("GET", "/", nil)
- basicAuthClient.Do(req, nil)
+ basicAuthClient.Do(context.Background(), req, nil)
}
func TestBasicAuthTransport_transport(t *testing.T) {
diff --git a/github/gitignore.go b/github/gitignore.go
index 396178dcf26..f258d566f26 100644
--- a/github/gitignore.go
+++ b/github/gitignore.go
@@ -5,7 +5,10 @@
package github
-import "fmt"
+import (
+ "context"
+ "fmt"
+)
// GitignoresService provides access to the gitignore related functions in the
// GitHub API.
@@ -26,14 +29,14 @@ func (g Gitignore) String() string {
// List all available Gitignore templates.
//
// https://developer.github.com/v3/gitignore/#listing-available-templates
-func (s GitignoresService) List() ([]string, *Response, error) {
+func (s GitignoresService) List(ctx context.Context) ([]string, *Response, error) {
req, err := s.client.NewRequest("GET", "gitignore/templates", nil)
if err != nil {
return nil, nil, err
}
var availableTemplates []string
- resp, err := s.client.Do(req, &availableTemplates)
+ resp, err := s.client.Do(ctx, req, &availableTemplates)
if err != nil {
return nil, resp, err
}
@@ -44,7 +47,7 @@ func (s GitignoresService) List() ([]string, *Response, error) {
// Get a Gitignore by name.
//
// https://developer.github.com/v3/gitignore/#get-a-single-template
-func (s GitignoresService) Get(name string) (*Gitignore, *Response, error) {
+func (s GitignoresService) Get(ctx context.Context, name string) (*Gitignore, *Response, error) {
u := fmt.Sprintf("gitignore/templates/%v", name)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
@@ -52,7 +55,7 @@ func (s GitignoresService) Get(name string) (*Gitignore, *Response, error) {
}
gitignore := new(Gitignore)
- resp, err := s.client.Do(req, gitignore)
+ resp, err := s.client.Do(ctx, req, gitignore)
if err != nil {
return nil, resp, err
}
diff --git a/github/gitignore_test.go b/github/gitignore_test.go
index 6d49d00fa46..e5a62643b5d 100644
--- a/github/gitignore_test.go
+++ b/github/gitignore_test.go
@@ -6,6 +6,7 @@
package github
import (
+ "context"
"fmt"
"net/http"
"reflect"
@@ -21,7 +22,7 @@ func TestGitignoresService_List(t *testing.T) {
fmt.Fprint(w, `["C", "Go"]`)
})
- available, _, err := client.Gitignores.List()
+ available, _, err := client.Gitignores.List(context.Background())
if err != nil {
t.Errorf("Gitignores.List returned error: %v", err)
}
@@ -41,7 +42,7 @@ func TestGitignoresService_Get(t *testing.T) {
fmt.Fprint(w, `{"name":"Name","source":"template source"}`)
})
- gitignore, _, err := client.Gitignores.Get("name")
+ gitignore, _, err := client.Gitignores.Get(context.Background(), "name")
if err != nil {
t.Errorf("Gitignores.List returned error: %v", err)
}
@@ -53,6 +54,6 @@ func TestGitignoresService_Get(t *testing.T) {
}
func TestGitignoresService_Get_invalidTemplate(t *testing.T) {
- _, _, err := client.Gitignores.Get("%")
+ _, _, err := client.Gitignores.Get(context.Background(), "%")
testURLParseError(t, err)
}
diff --git a/github/integration.go b/github/integration.go
index 033ee44aec6..6d74e44f007 100644
--- a/github/integration.go
+++ b/github/integration.go
@@ -5,6 +5,8 @@
package github
+import "context"
+
// IntegrationsService provides access to the installation related functions
// in the GitHub API.
//
@@ -14,7 +16,7 @@ type IntegrationsService service
// ListInstallations lists the installations that the current integration has.
//
// GitHub API docs: https://developer.github.com/v3/integrations/#find-installations
-func (s *IntegrationsService) ListInstallations(opt *ListOptions) ([]*Installation, *Response, error) {
+func (s *IntegrationsService) ListInstallations(ctx context.Context, opt *ListOptions) ([]*Installation, *Response, error) {
u, err := addOptions("integration/installations", opt)
if err != nil {
return nil, nil, err
@@ -29,7 +31,7 @@ func (s *IntegrationsService) ListInstallations(opt *ListOptions) ([]*Installati
req.Header.Set("Accept", mediaTypeIntegrationPreview)
var i []*Installation
- resp, err := s.client.Do(req, &i)
+ resp, err := s.client.Do(ctx, req, &i)
if err != nil {
return nil, resp, err
}
diff --git a/github/integration_installation.go b/github/integration_installation.go
index b130470d39e..933106400bf 100644
--- a/github/integration_installation.go
+++ b/github/integration_installation.go
@@ -5,6 +5,8 @@
package github
+import "context"
+
// Installation represents a GitHub integration installation.
type Installation struct {
ID *int `json:"id,omitempty"`
@@ -20,7 +22,7 @@ func (i Installation) String() string {
// ListRepos lists the repositories that the current installation has access to.
//
// GitHub API docs: https://developer.github.com/v3/integrations/installations/#list-repositories
-func (s *IntegrationsService) ListRepos(opt *ListOptions) ([]*Repository, *Response, error) {
+func (s *IntegrationsService) ListRepos(ctx context.Context, opt *ListOptions) ([]*Repository, *Response, error) {
u, err := addOptions("installation/repositories", opt)
if err != nil {
return nil, nil, err
@@ -37,7 +39,7 @@ func (s *IntegrationsService) ListRepos(opt *ListOptions) ([]*Repository, *Respo
var r struct {
Repositories []*Repository `json:"repositories"`
}
- resp, err := s.client.Do(req, &r)
+ resp, err := s.client.Do(ctx, req, &r)
if err != nil {
return nil, resp, err
}
diff --git a/github/integration_installation_test.go b/github/integration_installation_test.go
index 4c7be1fcebc..05f101677c8 100644
--- a/github/integration_installation_test.go
+++ b/github/integration_installation_test.go
@@ -6,6 +6,7 @@
package github
import (
+ "context"
"fmt"
"net/http"
"reflect"
@@ -27,7 +28,7 @@ func TestIntegrationService_ListRepos(t *testing.T) {
})
opt := &ListOptions{Page: 1, PerPage: 2}
- repositories, _, err := client.Integrations.ListRepos(opt)
+ repositories, _, err := client.Integrations.ListRepos(context.Background(), opt)
if err != nil {
t.Errorf("Integration.ListRepos returned error: %v", err)
}
diff --git a/github/integration_test.go b/github/integration_test.go
index f091cc688db..09ea304948a 100644
--- a/github/integration_test.go
+++ b/github/integration_test.go
@@ -6,6 +6,7 @@
package github
import (
+ "context"
"fmt"
"net/http"
"reflect"
@@ -27,7 +28,7 @@ func TestIntegrationService_ListInstallations(t *testing.T) {
})
opt := &ListOptions{Page: 1, PerPage: 2}
- installations, _, err := client.Integrations.ListInstallations(opt)
+ installations, _, err := client.Integrations.ListInstallations(context.Background(), opt)
if err != nil {
t.Errorf("Integration.ListInstallations returned error: %v", err)
}
diff --git a/github/issues.go b/github/issues.go
index c1997ee7cde..a25f461822c 100644
--- a/github/issues.go
+++ b/github/issues.go
@@ -6,6 +6,7 @@
package github
import (
+ "context"
"fmt"
"time"
)
@@ -108,26 +109,26 @@ type PullRequestLinks struct {
// repositories.
//
// GitHub API docs: https://developer.github.com/v3/issues/#list-issues
-func (s *IssuesService) List(all bool, opt *IssueListOptions) ([]*Issue, *Response, error) {
+func (s *IssuesService) List(ctx context.Context, all bool, opt *IssueListOptions) ([]*Issue, *Response, error) {
var u string
if all {
u = "issues"
} else {
u = "user/issues"
}
- return s.listIssues(u, opt)
+ return s.listIssues(ctx, u, opt)
}
// ListByOrg fetches the issues in the specified organization for the
// authenticated user.
//
// GitHub API docs: https://developer.github.com/v3/issues/#list-issues
-func (s *IssuesService) ListByOrg(org string, opt *IssueListOptions) ([]*Issue, *Response, error) {
+func (s *IssuesService) ListByOrg(ctx context.Context, org string, opt *IssueListOptions) ([]*Issue, *Response, error) {
u := fmt.Sprintf("orgs/%v/issues", org)
- return s.listIssues(u, opt)
+ return s.listIssues(ctx, u, opt)
}
-func (s *IssuesService) listIssues(u string, opt *IssueListOptions) ([]*Issue, *Response, error) {
+func (s *IssuesService) listIssues(ctx context.Context, u string, opt *IssueListOptions) ([]*Issue, *Response, error) {
u, err := addOptions(u, opt)
if err != nil {
return nil, nil, err
@@ -142,7 +143,7 @@ func (s *IssuesService) listIssues(u string, opt *IssueListOptions) ([]*Issue, *
req.Header.Set("Accept", mediaTypeReactionsPreview)
var issues []*Issue
- resp, err := s.client.Do(req, &issues)
+ resp, err := s.client.Do(ctx, req, &issues)
if err != nil {
return nil, resp, err
}
@@ -193,7 +194,7 @@ type IssueListByRepoOptions struct {
// ListByRepo lists the issues for the specified repository.
//
// GitHub API docs: https://developer.github.com/v3/issues/#list-issues-for-a-repository
-func (s *IssuesService) ListByRepo(owner string, repo string, opt *IssueListByRepoOptions) ([]*Issue, *Response, error) {
+func (s *IssuesService) ListByRepo(ctx context.Context, owner string, repo string, opt *IssueListByRepoOptions) ([]*Issue, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/issues", owner, repo)
u, err := addOptions(u, opt)
if err != nil {
@@ -209,7 +210,7 @@ func (s *IssuesService) ListByRepo(owner string, repo string, opt *IssueListByRe
req.Header.Set("Accept", mediaTypeReactionsPreview)
var issues []*Issue
- resp, err := s.client.Do(req, &issues)
+ resp, err := s.client.Do(ctx, req, &issues)
if err != nil {
return nil, resp, err
}
@@ -220,7 +221,7 @@ func (s *IssuesService) ListByRepo(owner string, repo string, opt *IssueListByRe
// Get a single issue.
//
// GitHub API docs: https://developer.github.com/v3/issues/#get-a-single-issue
-func (s *IssuesService) Get(owner string, repo string, number int) (*Issue, *Response, error) {
+func (s *IssuesService) Get(ctx context.Context, owner string, repo string, number int) (*Issue, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/issues/%d", owner, repo, number)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
@@ -231,7 +232,7 @@ func (s *IssuesService) Get(owner string, repo string, number int) (*Issue, *Res
req.Header.Set("Accept", mediaTypeReactionsPreview)
issue := new(Issue)
- resp, err := s.client.Do(req, issue)
+ resp, err := s.client.Do(ctx, req, issue)
if err != nil {
return nil, resp, err
}
@@ -242,7 +243,7 @@ func (s *IssuesService) Get(owner string, repo string, number int) (*Issue, *Res
// Create a new issue on the specified repository.
//
// GitHub API docs: https://developer.github.com/v3/issues/#create-an-issue
-func (s *IssuesService) Create(owner string, repo string, issue *IssueRequest) (*Issue, *Response, error) {
+func (s *IssuesService) Create(ctx context.Context, owner string, repo string, issue *IssueRequest) (*Issue, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/issues", owner, repo)
req, err := s.client.NewRequest("POST", u, issue)
if err != nil {
@@ -250,7 +251,7 @@ func (s *IssuesService) Create(owner string, repo string, issue *IssueRequest) (
}
i := new(Issue)
- resp, err := s.client.Do(req, i)
+ resp, err := s.client.Do(ctx, req, i)
if err != nil {
return nil, resp, err
}
@@ -261,7 +262,7 @@ func (s *IssuesService) Create(owner string, repo string, issue *IssueRequest) (
// Edit an issue.
//
// GitHub API docs: https://developer.github.com/v3/issues/#edit-an-issue
-func (s *IssuesService) Edit(owner string, repo string, number int, issue *IssueRequest) (*Issue, *Response, error) {
+func (s *IssuesService) Edit(ctx context.Context, owner string, repo string, number int, issue *IssueRequest) (*Issue, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/issues/%d", owner, repo, number)
req, err := s.client.NewRequest("PATCH", u, issue)
if err != nil {
@@ -269,7 +270,7 @@ func (s *IssuesService) Edit(owner string, repo string, number int, issue *Issue
}
i := new(Issue)
- resp, err := s.client.Do(req, i)
+ resp, err := s.client.Do(ctx, req, i)
if err != nil {
return nil, resp, err
}
@@ -280,25 +281,25 @@ func (s *IssuesService) Edit(owner string, repo string, number int, issue *Issue
// Lock an issue's conversation.
//
// GitHub API docs: https://developer.github.com/v3/issues/#lock-an-issue
-func (s *IssuesService) Lock(owner string, repo string, number int) (*Response, error) {
+func (s *IssuesService) Lock(ctx context.Context, owner string, repo string, number int) (*Response, error) {
u := fmt.Sprintf("repos/%v/%v/issues/%d/lock", owner, repo, number)
req, err := s.client.NewRequest("PUT", u, nil)
if err != nil {
return nil, err
}
- return s.client.Do(req, nil)
+ return s.client.Do(ctx, req, nil)
}
// Unlock an issue's conversation.
//
// GitHub API docs: https://developer.github.com/v3/issues/#unlock-an-issue
-func (s *IssuesService) Unlock(owner string, repo string, number int) (*Response, error) {
+func (s *IssuesService) Unlock(ctx context.Context, owner string, repo string, number int) (*Response, error) {
u := fmt.Sprintf("repos/%v/%v/issues/%d/lock", owner, repo, number)
req, err := s.client.NewRequest("DELETE", u, nil)
if err != nil {
return nil, err
}
- return s.client.Do(req, nil)
+ return s.client.Do(ctx, req, nil)
}
diff --git a/github/issues_assignees.go b/github/issues_assignees.go
index bdc6a6b5f2b..9cb366f50a3 100644
--- a/github/issues_assignees.go
+++ b/github/issues_assignees.go
@@ -5,13 +5,16 @@
package github
-import "fmt"
+import (
+ "context"
+ "fmt"
+)
// ListAssignees fetches all available assignees (owners and collaborators) to
// which issues may be assigned.
//
// GitHub API docs: https://developer.github.com/v3/issues/assignees/#list-assignees
-func (s *IssuesService) ListAssignees(owner, repo string, opt *ListOptions) ([]*User, *Response, error) {
+func (s *IssuesService) ListAssignees(ctx context.Context, owner, repo string, opt *ListOptions) ([]*User, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/assignees", owner, repo)
u, err := addOptions(u, opt)
if err != nil {
@@ -23,7 +26,7 @@ func (s *IssuesService) ListAssignees(owner, repo string, opt *ListOptions) ([]*
return nil, nil, err
}
var assignees []*User
- resp, err := s.client.Do(req, &assignees)
+ resp, err := s.client.Do(ctx, req, &assignees)
if err != nil {
return nil, resp, err
}
@@ -34,13 +37,13 @@ func (s *IssuesService) ListAssignees(owner, repo string, opt *ListOptions) ([]*
// IsAssignee checks if a user is an assignee for the specified repository.
//
// GitHub API docs: https://developer.github.com/v3/issues/assignees/#check-assignee
-func (s *IssuesService) IsAssignee(owner, repo, user string) (bool, *Response, error) {
+func (s *IssuesService) IsAssignee(ctx context.Context, owner, repo, user string) (bool, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/assignees/%v", owner, repo, user)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return false, nil, err
}
- resp, err := s.client.Do(req, nil)
+ resp, err := s.client.Do(ctx, req, nil)
assignee, err := parseBoolResponse(err)
return assignee, resp, err
}
@@ -48,7 +51,7 @@ func (s *IssuesService) IsAssignee(owner, repo, user string) (bool, *Response, e
// AddAssignees adds the provided GitHub users as assignees to the issue.
//
// GitHub API docs: https://developer.github.com/v3/issues/assignees/#add-assignees-to-an-issue
-func (s *IssuesService) AddAssignees(owner, repo string, number int, assignees []string) (*Issue, *Response, error) {
+func (s *IssuesService) AddAssignees(ctx context.Context, owner, repo string, number int, assignees []string) (*Issue, *Response, error) {
users := &struct {
Assignees []string `json:"assignees,omitempty"`
}{Assignees: assignees}
@@ -59,14 +62,14 @@ func (s *IssuesService) AddAssignees(owner, repo string, number int, assignees [
}
issue := &Issue{}
- resp, err := s.client.Do(req, issue)
+ resp, err := s.client.Do(ctx, req, issue)
return issue, resp, err
}
// RemoveAssignees removes the provided GitHub users as assignees from the issue.
//
// GitHub API docs: https://developer.github.com/v3/issues/assignees/#remove-assignees-from-an-issue
-func (s *IssuesService) RemoveAssignees(owner, repo string, number int, assignees []string) (*Issue, *Response, error) {
+func (s *IssuesService) RemoveAssignees(ctx context.Context, owner, repo string, number int, assignees []string) (*Issue, *Response, error) {
users := &struct {
Assignees []string `json:"assignees,omitempty"`
}{Assignees: assignees}
@@ -77,6 +80,6 @@ func (s *IssuesService) RemoveAssignees(owner, repo string, number int, assignee
}
issue := &Issue{}
- resp, err := s.client.Do(req, issue)
+ resp, err := s.client.Do(ctx, req, issue)
return issue, resp, err
}
diff --git a/github/issues_assignees_test.go b/github/issues_assignees_test.go
index 73d521ee9f9..d88a7888a4e 100644
--- a/github/issues_assignees_test.go
+++ b/github/issues_assignees_test.go
@@ -6,6 +6,7 @@
package github
import (
+ "context"
"encoding/json"
"fmt"
"net/http"
@@ -24,7 +25,7 @@ func TestIssuesService_ListAssignees(t *testing.T) {
})
opt := &ListOptions{Page: 2}
- assignees, _, err := client.Issues.ListAssignees("o", "r", opt)
+ assignees, _, err := client.Issues.ListAssignees(context.Background(), "o", "r", opt)
if err != nil {
t.Errorf("Issues.ListAssignees returned error: %v", err)
}
@@ -36,7 +37,7 @@ func TestIssuesService_ListAssignees(t *testing.T) {
}
func TestIssuesService_ListAssignees_invalidOwner(t *testing.T) {
- _, _, err := client.Issues.ListAssignees("%", "r", nil)
+ _, _, err := client.Issues.ListAssignees(context.Background(), "%", "r", nil)
testURLParseError(t, err)
}
@@ -48,7 +49,7 @@ func TestIssuesService_IsAssignee_true(t *testing.T) {
testMethod(t, r, "GET")
})
- assignee, _, err := client.Issues.IsAssignee("o", "r", "u")
+ assignee, _, err := client.Issues.IsAssignee(context.Background(), "o", "r", "u")
if err != nil {
t.Errorf("Issues.IsAssignee returned error: %v", err)
}
@@ -66,7 +67,7 @@ func TestIssuesService_IsAssignee_false(t *testing.T) {
w.WriteHeader(http.StatusNotFound)
})
- assignee, _, err := client.Issues.IsAssignee("o", "r", "u")
+ assignee, _, err := client.Issues.IsAssignee(context.Background(), "o", "r", "u")
if err != nil {
t.Errorf("Issues.IsAssignee returned error: %v", err)
}
@@ -84,7 +85,7 @@ func TestIssuesService_IsAssignee_error(t *testing.T) {
http.Error(w, "BadRequest", http.StatusBadRequest)
})
- assignee, _, err := client.Issues.IsAssignee("o", "r", "u")
+ assignee, _, err := client.Issues.IsAssignee(context.Background(), "o", "r", "u")
if err == nil {
t.Errorf("Expected HTTP 400 response")
}
@@ -94,7 +95,7 @@ func TestIssuesService_IsAssignee_error(t *testing.T) {
}
func TestIssuesService_IsAssignee_invalidOwner(t *testing.T) {
- _, _, err := client.Issues.IsAssignee("%", "r", "u")
+ _, _, err := client.Issues.IsAssignee(context.Background(), "%", "r", "u")
testURLParseError(t, err)
}
@@ -116,7 +117,7 @@ func TestIssuesService_AddAssignees(t *testing.T) {
fmt.Fprint(w, `{"number":1,"assignees":[{"login":"user1"},{"login":"user2"}]}`)
})
- got, _, err := client.Issues.AddAssignees("o", "r", 1, []string{"user1", "user2"})
+ got, _, err := client.Issues.AddAssignees(context.Background(), "o", "r", 1, []string{"user1", "user2"})
if err != nil {
t.Errorf("Issues.AddAssignees returned error: %v", err)
}
@@ -145,7 +146,7 @@ func TestIssuesService_RemoveAssignees(t *testing.T) {
fmt.Fprint(w, `{"number":1,"assignees":[]}`)
})
- got, _, err := client.Issues.RemoveAssignees("o", "r", 1, []string{"user1", "user2"})
+ got, _, err := client.Issues.RemoveAssignees(context.Background(), "o", "r", 1, []string{"user1", "user2"})
if err != nil {
t.Errorf("Issues.RemoveAssignees returned error: %v", err)
}
diff --git a/github/issues_comments.go b/github/issues_comments.go
index e8a852ef533..fd72657cd4d 100644
--- a/github/issues_comments.go
+++ b/github/issues_comments.go
@@ -6,6 +6,7 @@
package github
import (
+ "context"
"fmt"
"time"
)
@@ -46,7 +47,7 @@ type IssueListCommentsOptions struct {
// number of 0 will return all comments on all issues for the repository.
//
// GitHub API docs: https://developer.github.com/v3/issues/comments/#list-comments-on-an-issue
-func (s *IssuesService) ListComments(owner string, repo string, number int, opt *IssueListCommentsOptions) ([]*IssueComment, *Response, error) {
+func (s *IssuesService) ListComments(ctx context.Context, owner string, repo string, number int, opt *IssueListCommentsOptions) ([]*IssueComment, *Response, error) {
var u string
if number == 0 {
u = fmt.Sprintf("repos/%v/%v/issues/comments", owner, repo)
@@ -67,7 +68,7 @@ func (s *IssuesService) ListComments(owner string, repo string, number int, opt
req.Header.Set("Accept", mediaTypeReactionsPreview)
var comments []*IssueComment
- resp, err := s.client.Do(req, &comments)
+ resp, err := s.client.Do(ctx, req, &comments)
if err != nil {
return nil, resp, err
}
@@ -78,7 +79,7 @@ func (s *IssuesService) ListComments(owner string, repo string, number int, opt
// GetComment fetches the specified issue comment.
//
// GitHub API docs: https://developer.github.com/v3/issues/comments/#get-a-single-comment
-func (s *IssuesService) GetComment(owner string, repo string, id int) (*IssueComment, *Response, error) {
+func (s *IssuesService) GetComment(ctx context.Context, owner string, repo string, id int) (*IssueComment, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/issues/comments/%d", owner, repo, id)
req, err := s.client.NewRequest("GET", u, nil)
@@ -90,7 +91,7 @@ func (s *IssuesService) GetComment(owner string, repo string, id int) (*IssueCom
req.Header.Set("Accept", mediaTypeReactionsPreview)
comment := new(IssueComment)
- resp, err := s.client.Do(req, comment)
+ resp, err := s.client.Do(ctx, req, comment)
if err != nil {
return nil, resp, err
}
@@ -101,14 +102,14 @@ func (s *IssuesService) GetComment(owner string, repo string, id int) (*IssueCom
// CreateComment creates a new comment on the specified issue.
//
// GitHub API docs: https://developer.github.com/v3/issues/comments/#create-a-comment
-func (s *IssuesService) CreateComment(owner string, repo string, number int, comment *IssueComment) (*IssueComment, *Response, error) {
+func (s *IssuesService) CreateComment(ctx context.Context, owner string, repo string, number int, comment *IssueComment) (*IssueComment, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/issues/%d/comments", owner, repo, number)
req, err := s.client.NewRequest("POST", u, comment)
if err != nil {
return nil, nil, err
}
c := new(IssueComment)
- resp, err := s.client.Do(req, c)
+ resp, err := s.client.Do(ctx, req, c)
if err != nil {
return nil, resp, err
}
@@ -119,14 +120,14 @@ func (s *IssuesService) CreateComment(owner string, repo string, number int, com
// EditComment updates an issue comment.
//
// GitHub API docs: https://developer.github.com/v3/issues/comments/#edit-a-comment
-func (s *IssuesService) EditComment(owner string, repo string, id int, comment *IssueComment) (*IssueComment, *Response, error) {
+func (s *IssuesService) EditComment(ctx context.Context, owner string, repo string, id int, comment *IssueComment) (*IssueComment, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/issues/comments/%d", owner, repo, id)
req, err := s.client.NewRequest("PATCH", u, comment)
if err != nil {
return nil, nil, err
}
c := new(IssueComment)
- resp, err := s.client.Do(req, c)
+ resp, err := s.client.Do(ctx, req, c)
if err != nil {
return nil, resp, err
}
@@ -137,11 +138,11 @@ func (s *IssuesService) EditComment(owner string, repo string, id int, comment *
// DeleteComment deletes an issue comment.
//
// GitHub API docs: https://developer.github.com/v3/issues/comments/#delete-a-comment
-func (s *IssuesService) DeleteComment(owner string, repo string, id int) (*Response, error) {
+func (s *IssuesService) DeleteComment(ctx context.Context, owner string, repo string, id int) (*Response, error) {
u := fmt.Sprintf("repos/%v/%v/issues/comments/%d", owner, repo, id)
req, err := s.client.NewRequest("DELETE", u, nil)
if err != nil {
return nil, err
}
- return s.client.Do(req, nil)
+ return s.client.Do(ctx, req, nil)
}
diff --git a/github/issues_comments_test.go b/github/issues_comments_test.go
index b3a0ec19731..78c486362f4 100644
--- a/github/issues_comments_test.go
+++ b/github/issues_comments_test.go
@@ -6,6 +6,7 @@
package github
import (
+ "context"
"encoding/json"
"fmt"
"net/http"
@@ -36,7 +37,7 @@ func TestIssuesService_ListComments_allIssues(t *testing.T) {
Since: time.Date(2002, time.February, 10, 15, 30, 0, 0, time.UTC),
ListOptions: ListOptions{Page: 2},
}
- comments, _, err := client.Issues.ListComments("o", "r", 0, opt)
+ comments, _, err := client.Issues.ListComments(context.Background(), "o", "r", 0, opt)
if err != nil {
t.Errorf("Issues.ListComments returned error: %v", err)
}
@@ -57,7 +58,7 @@ func TestIssuesService_ListComments_specificIssue(t *testing.T) {
fmt.Fprint(w, `[{"id":1}]`)
})
- comments, _, err := client.Issues.ListComments("o", "r", 1, nil)
+ comments, _, err := client.Issues.ListComments(context.Background(), "o", "r", 1, nil)
if err != nil {
t.Errorf("Issues.ListComments returned error: %v", err)
}
@@ -69,7 +70,7 @@ func TestIssuesService_ListComments_specificIssue(t *testing.T) {
}
func TestIssuesService_ListComments_invalidOwner(t *testing.T) {
- _, _, err := client.Issues.ListComments("%", "r", 1, nil)
+ _, _, err := client.Issues.ListComments(context.Background(), "%", "r", 1, nil)
testURLParseError(t, err)
}
@@ -83,7 +84,7 @@ func TestIssuesService_GetComment(t *testing.T) {
fmt.Fprint(w, `{"id":1}`)
})
- comment, _, err := client.Issues.GetComment("o", "r", 1)
+ comment, _, err := client.Issues.GetComment(context.Background(), "o", "r", 1)
if err != nil {
t.Errorf("Issues.GetComment returned error: %v", err)
}
@@ -95,7 +96,7 @@ func TestIssuesService_GetComment(t *testing.T) {
}
func TestIssuesService_GetComment_invalidOrg(t *testing.T) {
- _, _, err := client.Issues.GetComment("%", "r", 1)
+ _, _, err := client.Issues.GetComment(context.Background(), "%", "r", 1)
testURLParseError(t, err)
}
@@ -117,7 +118,7 @@ func TestIssuesService_CreateComment(t *testing.T) {
fmt.Fprint(w, `{"id":1}`)
})
- comment, _, err := client.Issues.CreateComment("o", "r", 1, input)
+ comment, _, err := client.Issues.CreateComment(context.Background(), "o", "r", 1, input)
if err != nil {
t.Errorf("Issues.CreateComment returned error: %v", err)
}
@@ -129,7 +130,7 @@ func TestIssuesService_CreateComment(t *testing.T) {
}
func TestIssuesService_CreateComment_invalidOrg(t *testing.T) {
- _, _, err := client.Issues.CreateComment("%", "r", 1, nil)
+ _, _, err := client.Issues.CreateComment(context.Background(), "%", "r", 1, nil)
testURLParseError(t, err)
}
@@ -151,7 +152,7 @@ func TestIssuesService_EditComment(t *testing.T) {
fmt.Fprint(w, `{"id":1}`)
})
- comment, _, err := client.Issues.EditComment("o", "r", 1, input)
+ comment, _, err := client.Issues.EditComment(context.Background(), "o", "r", 1, input)
if err != nil {
t.Errorf("Issues.EditComment returned error: %v", err)
}
@@ -163,7 +164,7 @@ func TestIssuesService_EditComment(t *testing.T) {
}
func TestIssuesService_EditComment_invalidOwner(t *testing.T) {
- _, _, err := client.Issues.EditComment("%", "r", 1, nil)
+ _, _, err := client.Issues.EditComment(context.Background(), "%", "r", 1, nil)
testURLParseError(t, err)
}
@@ -175,13 +176,13 @@ func TestIssuesService_DeleteComment(t *testing.T) {
testMethod(t, r, "DELETE")
})
- _, err := client.Issues.DeleteComment("o", "r", 1)
+ _, err := client.Issues.DeleteComment(context.Background(), "o", "r", 1)
if err != nil {
t.Errorf("Issues.DeleteComments returned error: %v", err)
}
}
func TestIssuesService_DeleteComment_invalidOwner(t *testing.T) {
- _, err := client.Issues.DeleteComment("%", "r", 1)
+ _, err := client.Issues.DeleteComment(context.Background(), "%", "r", 1)
testURLParseError(t, err)
}
diff --git a/github/issues_events.go b/github/issues_events.go
index 98f215c6565..bede41901ff 100644
--- a/github/issues_events.go
+++ b/github/issues_events.go
@@ -6,6 +6,7 @@
package github
import (
+ "context"
"fmt"
"time"
)
@@ -73,7 +74,7 @@ type IssueEvent struct {
// ListIssueEvents lists events for the specified issue.
//
// GitHub API docs: https://developer.github.com/v3/issues/events/#list-events-for-an-issue
-func (s *IssuesService) ListIssueEvents(owner, repo string, number int, opt *ListOptions) ([]*IssueEvent, *Response, error) {
+func (s *IssuesService) ListIssueEvents(ctx context.Context, owner, repo string, number int, opt *ListOptions) ([]*IssueEvent, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/issues/%v/events", owner, repo, number)
u, err := addOptions(u, opt)
if err != nil {
@@ -86,7 +87,7 @@ func (s *IssuesService) ListIssueEvents(owner, repo string, number int, opt *Lis
}
var events []*IssueEvent
- resp, err := s.client.Do(req, &events)
+ resp, err := s.client.Do(ctx, req, &events)
if err != nil {
return nil, resp, err
}
@@ -97,7 +98,7 @@ func (s *IssuesService) ListIssueEvents(owner, repo string, number int, opt *Lis
// ListRepositoryEvents lists events for the specified repository.
//
// GitHub API docs: https://developer.github.com/v3/issues/events/#list-events-for-a-repository
-func (s *IssuesService) ListRepositoryEvents(owner, repo string, opt *ListOptions) ([]*IssueEvent, *Response, error) {
+func (s *IssuesService) ListRepositoryEvents(ctx context.Context, owner, repo string, opt *ListOptions) ([]*IssueEvent, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/issues/events", owner, repo)
u, err := addOptions(u, opt)
if err != nil {
@@ -110,7 +111,7 @@ func (s *IssuesService) ListRepositoryEvents(owner, repo string, opt *ListOption
}
var events []*IssueEvent
- resp, err := s.client.Do(req, &events)
+ resp, err := s.client.Do(ctx, req, &events)
if err != nil {
return nil, resp, err
}
@@ -121,7 +122,7 @@ func (s *IssuesService) ListRepositoryEvents(owner, repo string, opt *ListOption
// GetEvent returns the specified issue event.
//
// GitHub API docs: https://developer.github.com/v3/issues/events/#get-a-single-event
-func (s *IssuesService) GetEvent(owner, repo string, id int) (*IssueEvent, *Response, error) {
+func (s *IssuesService) GetEvent(ctx context.Context, owner, repo string, id int) (*IssueEvent, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/issues/events/%v", owner, repo, id)
req, err := s.client.NewRequest("GET", u, nil)
@@ -130,7 +131,7 @@ func (s *IssuesService) GetEvent(owner, repo string, id int) (*IssueEvent, *Resp
}
event := new(IssueEvent)
- resp, err := s.client.Do(req, event)
+ resp, err := s.client.Do(ctx, req, event)
if err != nil {
return nil, resp, err
}
diff --git a/github/issues_events_test.go b/github/issues_events_test.go
index 2250432e785..d85b6223eaa 100644
--- a/github/issues_events_test.go
+++ b/github/issues_events_test.go
@@ -6,6 +6,7 @@
package github
import (
+ "context"
"fmt"
"net/http"
"reflect"
@@ -26,7 +27,7 @@ func TestIssuesService_ListIssueEvents(t *testing.T) {
})
opt := &ListOptions{Page: 1, PerPage: 2}
- events, _, err := client.Issues.ListIssueEvents("o", "r", 1, opt)
+ events, _, err := client.Issues.ListIssueEvents(context.Background(), "o", "r", 1, opt)
if err != nil {
t.Errorf("Issues.ListIssueEvents returned error: %v", err)
}
@@ -51,7 +52,7 @@ func TestIssuesService_ListRepositoryEvents(t *testing.T) {
})
opt := &ListOptions{Page: 1, PerPage: 2}
- events, _, err := client.Issues.ListRepositoryEvents("o", "r", opt)
+ events, _, err := client.Issues.ListRepositoryEvents(context.Background(), "o", "r", opt)
if err != nil {
t.Errorf("Issues.ListRepositoryEvents returned error: %v", err)
}
@@ -71,7 +72,7 @@ func TestIssuesService_GetEvent(t *testing.T) {
fmt.Fprint(w, `{"id":1}`)
})
- event, _, err := client.Issues.GetEvent("o", "r", 1)
+ event, _, err := client.Issues.GetEvent(context.Background(), "o", "r", 1)
if err != nil {
t.Errorf("Issues.GetEvent returned error: %v", err)
}
diff --git a/github/issues_labels.go b/github/issues_labels.go
index c9f8c46a2ac..5c0b821c31e 100644
--- a/github/issues_labels.go
+++ b/github/issues_labels.go
@@ -5,7 +5,10 @@
package github
-import "fmt"
+import (
+ "context"
+ "fmt"
+)
// Label represents a GitHub label on an Issue
type Label struct {
@@ -21,7 +24,7 @@ func (l Label) String() string {
// ListLabels lists all labels for a repository.
//
// GitHub API docs: https://developer.github.com/v3/issues/labels/#list-all-labels-for-this-repository
-func (s *IssuesService) ListLabels(owner string, repo string, opt *ListOptions) ([]*Label, *Response, error) {
+func (s *IssuesService) ListLabels(ctx context.Context, owner string, repo string, opt *ListOptions) ([]*Label, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/labels", owner, repo)
u, err := addOptions(u, opt)
if err != nil {
@@ -34,7 +37,7 @@ func (s *IssuesService) ListLabels(owner string, repo string, opt *ListOptions)
}
var labels []*Label
- resp, err := s.client.Do(req, &labels)
+ resp, err := s.client.Do(ctx, req, &labels)
if err != nil {
return nil, resp, err
}
@@ -45,7 +48,7 @@ func (s *IssuesService) ListLabels(owner string, repo string, opt *ListOptions)
// GetLabel gets a single label.
//
// GitHub API docs: https://developer.github.com/v3/issues/labels/#get-a-single-label
-func (s *IssuesService) GetLabel(owner string, repo string, name string) (*Label, *Response, error) {
+func (s *IssuesService) GetLabel(ctx context.Context, owner string, repo string, name string) (*Label, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/labels/%v", owner, repo, name)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
@@ -53,7 +56,7 @@ func (s *IssuesService) GetLabel(owner string, repo string, name string) (*Label
}
label := new(Label)
- resp, err := s.client.Do(req, label)
+ resp, err := s.client.Do(ctx, req, label)
if err != nil {
return nil, resp, err
}
@@ -64,7 +67,7 @@ func (s *IssuesService) GetLabel(owner string, repo string, name string) (*Label
// CreateLabel creates a new label on the specified repository.
//
// GitHub API docs: https://developer.github.com/v3/issues/labels/#create-a-label
-func (s *IssuesService) CreateLabel(owner string, repo string, label *Label) (*Label, *Response, error) {
+func (s *IssuesService) CreateLabel(ctx context.Context, owner string, repo string, label *Label) (*Label, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/labels", owner, repo)
req, err := s.client.NewRequest("POST", u, label)
if err != nil {
@@ -72,7 +75,7 @@ func (s *IssuesService) CreateLabel(owner string, repo string, label *Label) (*L
}
l := new(Label)
- resp, err := s.client.Do(req, l)
+ resp, err := s.client.Do(ctx, req, l)
if err != nil {
return nil, resp, err
}
@@ -83,7 +86,7 @@ func (s *IssuesService) CreateLabel(owner string, repo string, label *Label) (*L
// EditLabel edits a label.
//
// GitHub API docs: https://developer.github.com/v3/issues/labels/#update-a-label
-func (s *IssuesService) EditLabel(owner string, repo string, name string, label *Label) (*Label, *Response, error) {
+func (s *IssuesService) EditLabel(ctx context.Context, owner string, repo string, name string, label *Label) (*Label, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/labels/%v", owner, repo, name)
req, err := s.client.NewRequest("PATCH", u, label)
if err != nil {
@@ -91,7 +94,7 @@ func (s *IssuesService) EditLabel(owner string, repo string, name string, label
}
l := new(Label)
- resp, err := s.client.Do(req, l)
+ resp, err := s.client.Do(ctx, req, l)
if err != nil {
return nil, resp, err
}
@@ -102,19 +105,19 @@ func (s *IssuesService) EditLabel(owner string, repo string, name string, label
// DeleteLabel deletes a label.
//
// GitHub API docs: https://developer.github.com/v3/issues/labels/#delete-a-label
-func (s *IssuesService) DeleteLabel(owner string, repo string, name string) (*Response, error) {
+func (s *IssuesService) DeleteLabel(ctx context.Context, owner string, repo string, name string) (*Response, error) {
u := fmt.Sprintf("repos/%v/%v/labels/%v", owner, repo, name)
req, err := s.client.NewRequest("DELETE", u, nil)
if err != nil {
return nil, err
}
- return s.client.Do(req, nil)
+ return s.client.Do(ctx, req, nil)
}
// ListLabelsByIssue lists all labels for an issue.
//
// GitHub API docs: https://developer.github.com/v3/issues/labels/#list-labels-on-an-issue
-func (s *IssuesService) ListLabelsByIssue(owner string, repo string, number int, opt *ListOptions) ([]*Label, *Response, error) {
+func (s *IssuesService) ListLabelsByIssue(ctx context.Context, owner string, repo string, number int, opt *ListOptions) ([]*Label, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/issues/%d/labels", owner, repo, number)
u, err := addOptions(u, opt)
if err != nil {
@@ -127,7 +130,7 @@ func (s *IssuesService) ListLabelsByIssue(owner string, repo string, number int,
}
var labels []*Label
- resp, err := s.client.Do(req, &labels)
+ resp, err := s.client.Do(ctx, req, &labels)
if err != nil {
return nil, resp, err
}
@@ -138,7 +141,7 @@ func (s *IssuesService) ListLabelsByIssue(owner string, repo string, number int,
// AddLabelsToIssue adds labels to an issue.
//
// GitHub API docs: https://developer.github.com/v3/issues/labels/#add-labels-to-an-issue
-func (s *IssuesService) AddLabelsToIssue(owner string, repo string, number int, labels []string) ([]*Label, *Response, error) {
+func (s *IssuesService) AddLabelsToIssue(ctx context.Context, owner string, repo string, number int, labels []string) ([]*Label, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/issues/%d/labels", owner, repo, number)
req, err := s.client.NewRequest("POST", u, labels)
if err != nil {
@@ -146,7 +149,7 @@ func (s *IssuesService) AddLabelsToIssue(owner string, repo string, number int,
}
var l []*Label
- resp, err := s.client.Do(req, &l)
+ resp, err := s.client.Do(ctx, req, &l)
if err != nil {
return nil, resp, err
}
@@ -157,19 +160,19 @@ func (s *IssuesService) AddLabelsToIssue(owner string, repo string, number int,
// RemoveLabelForIssue removes a label for an issue.
//
// GitHub API docs: https://developer.github.com/v3/issues/labels/#remove-a-label-from-an-issue
-func (s *IssuesService) RemoveLabelForIssue(owner string, repo string, number int, label string) (*Response, error) {
+func (s *IssuesService) RemoveLabelForIssue(ctx context.Context, owner string, repo string, number int, label string) (*Response, error) {
u := fmt.Sprintf("repos/%v/%v/issues/%d/labels/%v", owner, repo, number, label)
req, err := s.client.NewRequest("DELETE", u, nil)
if err != nil {
return nil, err
}
- return s.client.Do(req, nil)
+ return s.client.Do(ctx, req, nil)
}
// ReplaceLabelsForIssue replaces all labels for an issue.
//
// GitHub API docs: https://developer.github.com/v3/issues/labels/#replace-all-labels-for-an-issue
-func (s *IssuesService) ReplaceLabelsForIssue(owner string, repo string, number int, labels []string) ([]*Label, *Response, error) {
+func (s *IssuesService) ReplaceLabelsForIssue(ctx context.Context, owner string, repo string, number int, labels []string) ([]*Label, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/issues/%d/labels", owner, repo, number)
req, err := s.client.NewRequest("PUT", u, labels)
if err != nil {
@@ -177,7 +180,7 @@ func (s *IssuesService) ReplaceLabelsForIssue(owner string, repo string, number
}
var l []*Label
- resp, err := s.client.Do(req, &l)
+ resp, err := s.client.Do(ctx, req, &l)
if err != nil {
return nil, resp, err
}
@@ -188,19 +191,19 @@ func (s *IssuesService) ReplaceLabelsForIssue(owner string, repo string, number
// RemoveLabelsForIssue removes all labels for an issue.
//
// GitHub API docs: https://developer.github.com/v3/issues/labels/#remove-all-labels-from-an-issue
-func (s *IssuesService) RemoveLabelsForIssue(owner string, repo string, number int) (*Response, error) {
+func (s *IssuesService) RemoveLabelsForIssue(ctx context.Context, owner string, repo string, number int) (*Response, error) {
u := fmt.Sprintf("repos/%v/%v/issues/%d/labels", owner, repo, number)
req, err := s.client.NewRequest("DELETE", u, nil)
if err != nil {
return nil, err
}
- return s.client.Do(req, nil)
+ return s.client.Do(ctx, req, nil)
}
// ListLabelsForMilestone lists labels for every issue in a milestone.
//
// GitHub API docs: https://developer.github.com/v3/issues/labels/#get-labels-for-every-issue-in-a-milestone
-func (s *IssuesService) ListLabelsForMilestone(owner string, repo string, number int, opt *ListOptions) ([]*Label, *Response, error) {
+func (s *IssuesService) ListLabelsForMilestone(ctx context.Context, owner string, repo string, number int, opt *ListOptions) ([]*Label, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/milestones/%d/labels", owner, repo, number)
u, err := addOptions(u, opt)
if err != nil {
@@ -213,7 +216,7 @@ func (s *IssuesService) ListLabelsForMilestone(owner string, repo string, number
}
var labels []*Label
- resp, err := s.client.Do(req, &labels)
+ resp, err := s.client.Do(ctx, req, &labels)
if err != nil {
return nil, resp, err
}
diff --git a/github/issues_labels_test.go b/github/issues_labels_test.go
index 2018bd126b7..88bc191b740 100644
--- a/github/issues_labels_test.go
+++ b/github/issues_labels_test.go
@@ -6,6 +6,7 @@
package github
import (
+ "context"
"encoding/json"
"fmt"
"net/http"
@@ -24,7 +25,7 @@ func TestIssuesService_ListLabels(t *testing.T) {
})
opt := &ListOptions{Page: 2}
- labels, _, err := client.Issues.ListLabels("o", "r", opt)
+ labels, _, err := client.Issues.ListLabels(context.Background(), "o", "r", opt)
if err != nil {
t.Errorf("Issues.ListLabels returned error: %v", err)
}
@@ -36,7 +37,7 @@ func TestIssuesService_ListLabels(t *testing.T) {
}
func TestIssuesService_ListLabels_invalidOwner(t *testing.T) {
- _, _, err := client.Issues.ListLabels("%", "%", nil)
+ _, _, err := client.Issues.ListLabels(context.Background(), "%", "%", nil)
testURLParseError(t, err)
}
@@ -49,7 +50,7 @@ func TestIssuesService_GetLabel(t *testing.T) {
fmt.Fprint(w, `{"url":"u", "name": "n", "color": "c"}`)
})
- label, _, err := client.Issues.GetLabel("o", "r", "n")
+ label, _, err := client.Issues.GetLabel(context.Background(), "o", "r", "n")
if err != nil {
t.Errorf("Issues.GetLabel returned error: %v", err)
}
@@ -61,7 +62,7 @@ func TestIssuesService_GetLabel(t *testing.T) {
}
func TestIssuesService_GetLabel_invalidOwner(t *testing.T) {
- _, _, err := client.Issues.GetLabel("%", "%", "%")
+ _, _, err := client.Issues.GetLabel(context.Background(), "%", "%", "%")
testURLParseError(t, err)
}
@@ -83,7 +84,7 @@ func TestIssuesService_CreateLabel(t *testing.T) {
fmt.Fprint(w, `{"url":"u"}`)
})
- label, _, err := client.Issues.CreateLabel("o", "r", input)
+ label, _, err := client.Issues.CreateLabel(context.Background(), "o", "r", input)
if err != nil {
t.Errorf("Issues.CreateLabel returned error: %v", err)
}
@@ -95,7 +96,7 @@ func TestIssuesService_CreateLabel(t *testing.T) {
}
func TestIssuesService_CreateLabel_invalidOwner(t *testing.T) {
- _, _, err := client.Issues.CreateLabel("%", "%", nil)
+ _, _, err := client.Issues.CreateLabel(context.Background(), "%", "%", nil)
testURLParseError(t, err)
}
@@ -117,7 +118,7 @@ func TestIssuesService_EditLabel(t *testing.T) {
fmt.Fprint(w, `{"url":"u"}`)
})
- label, _, err := client.Issues.EditLabel("o", "r", "n", input)
+ label, _, err := client.Issues.EditLabel(context.Background(), "o", "r", "n", input)
if err != nil {
t.Errorf("Issues.EditLabel returned error: %v", err)
}
@@ -129,7 +130,7 @@ func TestIssuesService_EditLabel(t *testing.T) {
}
func TestIssuesService_EditLabel_invalidOwner(t *testing.T) {
- _, _, err := client.Issues.EditLabel("%", "%", "%", nil)
+ _, _, err := client.Issues.EditLabel(context.Background(), "%", "%", "%", nil)
testURLParseError(t, err)
}
@@ -141,14 +142,14 @@ func TestIssuesService_DeleteLabel(t *testing.T) {
testMethod(t, r, "DELETE")
})
- _, err := client.Issues.DeleteLabel("o", "r", "n")
+ _, err := client.Issues.DeleteLabel(context.Background(), "o", "r", "n")
if err != nil {
t.Errorf("Issues.DeleteLabel returned error: %v", err)
}
}
func TestIssuesService_DeleteLabel_invalidOwner(t *testing.T) {
- _, err := client.Issues.DeleteLabel("%", "%", "%")
+ _, err := client.Issues.DeleteLabel(context.Background(), "%", "%", "%")
testURLParseError(t, err)
}
@@ -163,7 +164,7 @@ func TestIssuesService_ListLabelsByIssue(t *testing.T) {
})
opt := &ListOptions{Page: 2}
- labels, _, err := client.Issues.ListLabelsByIssue("o", "r", 1, opt)
+ labels, _, err := client.Issues.ListLabelsByIssue(context.Background(), "o", "r", 1, opt)
if err != nil {
t.Errorf("Issues.ListLabelsByIssue returned error: %v", err)
}
@@ -175,7 +176,7 @@ func TestIssuesService_ListLabelsByIssue(t *testing.T) {
}
func TestIssuesService_ListLabelsByIssue_invalidOwner(t *testing.T) {
- _, _, err := client.Issues.ListLabelsByIssue("%", "%", 1, nil)
+ _, _, err := client.Issues.ListLabelsByIssue(context.Background(), "%", "%", 1, nil)
testURLParseError(t, err)
}
@@ -197,7 +198,7 @@ func TestIssuesService_AddLabelsToIssue(t *testing.T) {
fmt.Fprint(w, `[{"url":"u"}]`)
})
- labels, _, err := client.Issues.AddLabelsToIssue("o", "r", 1, input)
+ labels, _, err := client.Issues.AddLabelsToIssue(context.Background(), "o", "r", 1, input)
if err != nil {
t.Errorf("Issues.AddLabelsToIssue returned error: %v", err)
}
@@ -209,7 +210,7 @@ func TestIssuesService_AddLabelsToIssue(t *testing.T) {
}
func TestIssuesService_AddLabelsToIssue_invalidOwner(t *testing.T) {
- _, _, err := client.Issues.AddLabelsToIssue("%", "%", 1, nil)
+ _, _, err := client.Issues.AddLabelsToIssue(context.Background(), "%", "%", 1, nil)
testURLParseError(t, err)
}
@@ -221,14 +222,14 @@ func TestIssuesService_RemoveLabelForIssue(t *testing.T) {
testMethod(t, r, "DELETE")
})
- _, err := client.Issues.RemoveLabelForIssue("o", "r", 1, "l")
+ _, err := client.Issues.RemoveLabelForIssue(context.Background(), "o", "r", 1, "l")
if err != nil {
t.Errorf("Issues.RemoveLabelForIssue returned error: %v", err)
}
}
func TestIssuesService_RemoveLabelForIssue_invalidOwner(t *testing.T) {
- _, err := client.Issues.RemoveLabelForIssue("%", "%", 1, "%")
+ _, err := client.Issues.RemoveLabelForIssue(context.Background(), "%", "%", 1, "%")
testURLParseError(t, err)
}
@@ -250,7 +251,7 @@ func TestIssuesService_ReplaceLabelsForIssue(t *testing.T) {
fmt.Fprint(w, `[{"url":"u"}]`)
})
- labels, _, err := client.Issues.ReplaceLabelsForIssue("o", "r", 1, input)
+ labels, _, err := client.Issues.ReplaceLabelsForIssue(context.Background(), "o", "r", 1, input)
if err != nil {
t.Errorf("Issues.ReplaceLabelsForIssue returned error: %v", err)
}
@@ -262,7 +263,7 @@ func TestIssuesService_ReplaceLabelsForIssue(t *testing.T) {
}
func TestIssuesService_ReplaceLabelsForIssue_invalidOwner(t *testing.T) {
- _, _, err := client.Issues.ReplaceLabelsForIssue("%", "%", 1, nil)
+ _, _, err := client.Issues.ReplaceLabelsForIssue(context.Background(), "%", "%", 1, nil)
testURLParseError(t, err)
}
@@ -274,14 +275,14 @@ func TestIssuesService_RemoveLabelsForIssue(t *testing.T) {
testMethod(t, r, "DELETE")
})
- _, err := client.Issues.RemoveLabelsForIssue("o", "r", 1)
+ _, err := client.Issues.RemoveLabelsForIssue(context.Background(), "o", "r", 1)
if err != nil {
t.Errorf("Issues.RemoveLabelsForIssue returned error: %v", err)
}
}
func TestIssuesService_RemoveLabelsForIssue_invalidOwner(t *testing.T) {
- _, err := client.Issues.RemoveLabelsForIssue("%", "%", 1)
+ _, err := client.Issues.RemoveLabelsForIssue(context.Background(), "%", "%", 1)
testURLParseError(t, err)
}
@@ -296,7 +297,7 @@ func TestIssuesService_ListLabelsForMilestone(t *testing.T) {
})
opt := &ListOptions{Page: 2}
- labels, _, err := client.Issues.ListLabelsForMilestone("o", "r", 1, opt)
+ labels, _, err := client.Issues.ListLabelsForMilestone(context.Background(), "o", "r", 1, opt)
if err != nil {
t.Errorf("Issues.ListLabelsForMilestone returned error: %v", err)
}
@@ -308,6 +309,6 @@ func TestIssuesService_ListLabelsForMilestone(t *testing.T) {
}
func TestIssuesService_ListLabelsForMilestone_invalidOwner(t *testing.T) {
- _, _, err := client.Issues.ListLabelsForMilestone("%", "%", 1, nil)
+ _, _, err := client.Issues.ListLabelsForMilestone(context.Background(), "%", "%", 1, nil)
testURLParseError(t, err)
}
diff --git a/github/issues_milestones.go b/github/issues_milestones.go
index 0cc2d58c020..b062305589f 100644
--- a/github/issues_milestones.go
+++ b/github/issues_milestones.go
@@ -6,6 +6,7 @@
package github
import (
+ "context"
"fmt"
"time"
)
@@ -54,7 +55,7 @@ type MilestoneListOptions struct {
// ListMilestones lists all milestones for a repository.
//
// GitHub API docs: https://developer.github.com/v3/issues/milestones/#list-milestones-for-a-repository
-func (s *IssuesService) ListMilestones(owner string, repo string, opt *MilestoneListOptions) ([]*Milestone, *Response, error) {
+func (s *IssuesService) ListMilestones(ctx context.Context, owner string, repo string, opt *MilestoneListOptions) ([]*Milestone, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/milestones", owner, repo)
u, err := addOptions(u, opt)
if err != nil {
@@ -67,7 +68,7 @@ func (s *IssuesService) ListMilestones(owner string, repo string, opt *Milestone
}
var milestones []*Milestone
- resp, err := s.client.Do(req, &milestones)
+ resp, err := s.client.Do(ctx, req, &milestones)
if err != nil {
return nil, resp, err
}
@@ -78,7 +79,7 @@ func (s *IssuesService) ListMilestones(owner string, repo string, opt *Milestone
// GetMilestone gets a single milestone.
//
// GitHub API docs: https://developer.github.com/v3/issues/milestones/#get-a-single-milestone
-func (s *IssuesService) GetMilestone(owner string, repo string, number int) (*Milestone, *Response, error) {
+func (s *IssuesService) GetMilestone(ctx context.Context, owner string, repo string, number int) (*Milestone, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/milestones/%d", owner, repo, number)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
@@ -86,7 +87,7 @@ func (s *IssuesService) GetMilestone(owner string, repo string, number int) (*Mi
}
milestone := new(Milestone)
- resp, err := s.client.Do(req, milestone)
+ resp, err := s.client.Do(ctx, req, milestone)
if err != nil {
return nil, resp, err
}
@@ -97,7 +98,7 @@ func (s *IssuesService) GetMilestone(owner string, repo string, number int) (*Mi
// CreateMilestone creates a new milestone on the specified repository.
//
// GitHub API docs: https://developer.github.com/v3/issues/milestones/#create-a-milestone
-func (s *IssuesService) CreateMilestone(owner string, repo string, milestone *Milestone) (*Milestone, *Response, error) {
+func (s *IssuesService) CreateMilestone(ctx context.Context, owner string, repo string, milestone *Milestone) (*Milestone, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/milestones", owner, repo)
req, err := s.client.NewRequest("POST", u, milestone)
if err != nil {
@@ -105,7 +106,7 @@ func (s *IssuesService) CreateMilestone(owner string, repo string, milestone *Mi
}
m := new(Milestone)
- resp, err := s.client.Do(req, m)
+ resp, err := s.client.Do(ctx, req, m)
if err != nil {
return nil, resp, err
}
@@ -116,7 +117,7 @@ func (s *IssuesService) CreateMilestone(owner string, repo string, milestone *Mi
// EditMilestone edits a milestone.
//
// GitHub API docs: https://developer.github.com/v3/issues/milestones/#update-a-milestone
-func (s *IssuesService) EditMilestone(owner string, repo string, number int, milestone *Milestone) (*Milestone, *Response, error) {
+func (s *IssuesService) EditMilestone(ctx context.Context, owner string, repo string, number int, milestone *Milestone) (*Milestone, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/milestones/%d", owner, repo, number)
req, err := s.client.NewRequest("PATCH", u, milestone)
if err != nil {
@@ -124,7 +125,7 @@ func (s *IssuesService) EditMilestone(owner string, repo string, number int, mil
}
m := new(Milestone)
- resp, err := s.client.Do(req, m)
+ resp, err := s.client.Do(ctx, req, m)
if err != nil {
return nil, resp, err
}
@@ -135,12 +136,12 @@ func (s *IssuesService) EditMilestone(owner string, repo string, number int, mil
// DeleteMilestone deletes a milestone.
//
// GitHub API docs: https://developer.github.com/v3/issues/milestones/#delete-a-milestone
-func (s *IssuesService) DeleteMilestone(owner string, repo string, number int) (*Response, error) {
+func (s *IssuesService) DeleteMilestone(ctx context.Context, owner string, repo string, number int) (*Response, error) {
u := fmt.Sprintf("repos/%v/%v/milestones/%d", owner, repo, number)
req, err := s.client.NewRequest("DELETE", u, nil)
if err != nil {
return nil, err
}
- return s.client.Do(req, nil)
+ return s.client.Do(ctx, req, nil)
}
diff --git a/github/issues_milestones_test.go b/github/issues_milestones_test.go
index 11bf4d39d27..befa1b48727 100644
--- a/github/issues_milestones_test.go
+++ b/github/issues_milestones_test.go
@@ -6,6 +6,7 @@
package github
import (
+ "context"
"encoding/json"
"fmt"
"net/http"
@@ -29,7 +30,7 @@ func TestIssuesService_ListMilestones(t *testing.T) {
})
opt := &MilestoneListOptions{"closed", "due_date", "asc", ListOptions{Page: 2}}
- milestones, _, err := client.Issues.ListMilestones("o", "r", opt)
+ milestones, _, err := client.Issues.ListMilestones(context.Background(), "o", "r", opt)
if err != nil {
t.Errorf("IssuesService.ListMilestones returned error: %v", err)
}
@@ -41,7 +42,7 @@ func TestIssuesService_ListMilestones(t *testing.T) {
}
func TestIssuesService_ListMilestones_invalidOwner(t *testing.T) {
- _, _, err := client.Issues.ListMilestones("%", "r", nil)
+ _, _, err := client.Issues.ListMilestones(context.Background(), "%", "r", nil)
testURLParseError(t, err)
}
@@ -54,7 +55,7 @@ func TestIssuesService_GetMilestone(t *testing.T) {
fmt.Fprint(w, `{"number":1}`)
})
- milestone, _, err := client.Issues.GetMilestone("o", "r", 1)
+ milestone, _, err := client.Issues.GetMilestone(context.Background(), "o", "r", 1)
if err != nil {
t.Errorf("IssuesService.GetMilestone returned error: %v", err)
}
@@ -66,7 +67,7 @@ func TestIssuesService_GetMilestone(t *testing.T) {
}
func TestIssuesService_GetMilestone_invalidOwner(t *testing.T) {
- _, _, err := client.Issues.GetMilestone("%", "r", 1)
+ _, _, err := client.Issues.GetMilestone(context.Background(), "%", "r", 1)
testURLParseError(t, err)
}
@@ -88,7 +89,7 @@ func TestIssuesService_CreateMilestone(t *testing.T) {
fmt.Fprint(w, `{"number":1}`)
})
- milestone, _, err := client.Issues.CreateMilestone("o", "r", input)
+ milestone, _, err := client.Issues.CreateMilestone(context.Background(), "o", "r", input)
if err != nil {
t.Errorf("IssuesService.CreateMilestone returned error: %v", err)
}
@@ -100,7 +101,7 @@ func TestIssuesService_CreateMilestone(t *testing.T) {
}
func TestIssuesService_CreateMilestone_invalidOwner(t *testing.T) {
- _, _, err := client.Issues.CreateMilestone("%", "r", nil)
+ _, _, err := client.Issues.CreateMilestone(context.Background(), "%", "r", nil)
testURLParseError(t, err)
}
@@ -122,7 +123,7 @@ func TestIssuesService_EditMilestone(t *testing.T) {
fmt.Fprint(w, `{"number":1}`)
})
- milestone, _, err := client.Issues.EditMilestone("o", "r", 1, input)
+ milestone, _, err := client.Issues.EditMilestone(context.Background(), "o", "r", 1, input)
if err != nil {
t.Errorf("IssuesService.EditMilestone returned error: %v", err)
}
@@ -134,7 +135,7 @@ func TestIssuesService_EditMilestone(t *testing.T) {
}
func TestIssuesService_EditMilestone_invalidOwner(t *testing.T) {
- _, _, err := client.Issues.EditMilestone("%", "r", 1, nil)
+ _, _, err := client.Issues.EditMilestone(context.Background(), "%", "r", 1, nil)
testURLParseError(t, err)
}
@@ -146,13 +147,13 @@ func TestIssuesService_DeleteMilestone(t *testing.T) {
testMethod(t, r, "DELETE")
})
- _, err := client.Issues.DeleteMilestone("o", "r", 1)
+ _, err := client.Issues.DeleteMilestone(context.Background(), "o", "r", 1)
if err != nil {
t.Errorf("IssuesService.DeleteMilestone returned error: %v", err)
}
}
func TestIssuesService_DeleteMilestone_invalidOwner(t *testing.T) {
- _, err := client.Issues.DeleteMilestone("%", "r", 1)
+ _, err := client.Issues.DeleteMilestone(context.Background(), "%", "r", 1)
testURLParseError(t, err)
}
diff --git a/github/issues_test.go b/github/issues_test.go
index 5e6369e1c9c..dadee75573e 100644
--- a/github/issues_test.go
+++ b/github/issues_test.go
@@ -6,6 +6,7 @@
package github
import (
+ "context"
"encoding/json"
"fmt"
"net/http"
@@ -39,7 +40,7 @@ func TestIssuesService_List_all(t *testing.T) {
time.Date(2002, time.February, 10, 15, 30, 0, 0, time.UTC),
ListOptions{Page: 1, PerPage: 2},
}
- issues, _, err := client.Issues.List(true, opt)
+ issues, _, err := client.Issues.List(context.Background(), true, opt)
if err != nil {
t.Errorf("Issues.List returned error: %v", err)
}
@@ -60,7 +61,7 @@ func TestIssuesService_List_owned(t *testing.T) {
fmt.Fprint(w, `[{"number":1}]`)
})
- issues, _, err := client.Issues.List(false, nil)
+ issues, _, err := client.Issues.List(context.Background(), false, nil)
if err != nil {
t.Errorf("Issues.List returned error: %v", err)
}
@@ -81,7 +82,7 @@ func TestIssuesService_ListByOrg(t *testing.T) {
fmt.Fprint(w, `[{"number":1}]`)
})
- issues, _, err := client.Issues.ListByOrg("o", nil)
+ issues, _, err := client.Issues.ListByOrg(context.Background(), "o", nil)
if err != nil {
t.Errorf("Issues.ListByOrg returned error: %v", err)
}
@@ -93,7 +94,7 @@ func TestIssuesService_ListByOrg(t *testing.T) {
}
func TestIssuesService_ListByOrg_invalidOrg(t *testing.T) {
- _, _, err := client.Issues.ListByOrg("%", nil)
+ _, _, err := client.Issues.ListByOrg(context.Background(), "%", nil)
testURLParseError(t, err)
}
@@ -123,7 +124,7 @@ func TestIssuesService_ListByRepo(t *testing.T) {
time.Date(2002, time.February, 10, 15, 30, 0, 0, time.UTC),
ListOptions{0, 0},
}
- issues, _, err := client.Issues.ListByRepo("o", "r", opt)
+ issues, _, err := client.Issues.ListByRepo(context.Background(), "o", "r", opt)
if err != nil {
t.Errorf("Issues.ListByOrg returned error: %v", err)
}
@@ -135,7 +136,7 @@ func TestIssuesService_ListByRepo(t *testing.T) {
}
func TestIssuesService_ListByRepo_invalidOwner(t *testing.T) {
- _, _, err := client.Issues.ListByRepo("%", "r", nil)
+ _, _, err := client.Issues.ListByRepo(context.Background(), "%", "r", nil)
testURLParseError(t, err)
}
@@ -149,7 +150,7 @@ func TestIssuesService_Get(t *testing.T) {
fmt.Fprint(w, `{"number":1, "labels": [{"url": "u", "name": "n", "color": "c"}]}`)
})
- issue, _, err := client.Issues.Get("o", "r", 1)
+ issue, _, err := client.Issues.Get(context.Background(), "o", "r", 1)
if err != nil {
t.Errorf("Issues.Get returned error: %v", err)
}
@@ -168,7 +169,7 @@ func TestIssuesService_Get(t *testing.T) {
}
func TestIssuesService_Get_invalidOwner(t *testing.T) {
- _, _, err := client.Issues.Get("%", "r", 1)
+ _, _, err := client.Issues.Get(context.Background(), "%", "r", 1)
testURLParseError(t, err)
}
@@ -195,7 +196,7 @@ func TestIssuesService_Create(t *testing.T) {
fmt.Fprint(w, `{"number":1}`)
})
- issue, _, err := client.Issues.Create("o", "r", input)
+ issue, _, err := client.Issues.Create(context.Background(), "o", "r", input)
if err != nil {
t.Errorf("Issues.Create returned error: %v", err)
}
@@ -207,7 +208,7 @@ func TestIssuesService_Create(t *testing.T) {
}
func TestIssuesService_Create_invalidOwner(t *testing.T) {
- _, _, err := client.Issues.Create("%", "r", nil)
+ _, _, err := client.Issues.Create(context.Background(), "%", "r", nil)
testURLParseError(t, err)
}
@@ -229,7 +230,7 @@ func TestIssuesService_Edit(t *testing.T) {
fmt.Fprint(w, `{"number":1}`)
})
- issue, _, err := client.Issues.Edit("o", "r", 1, input)
+ issue, _, err := client.Issues.Edit(context.Background(), "o", "r", 1, input)
if err != nil {
t.Errorf("Issues.Edit returned error: %v", err)
}
@@ -241,7 +242,7 @@ func TestIssuesService_Edit(t *testing.T) {
}
func TestIssuesService_Edit_invalidOwner(t *testing.T) {
- _, _, err := client.Issues.Edit("%", "r", 1, nil)
+ _, _, err := client.Issues.Edit(context.Background(), "%", "r", 1, nil)
testURLParseError(t, err)
}
@@ -255,7 +256,7 @@ func TestIssuesService_Lock(t *testing.T) {
w.WriteHeader(http.StatusNoContent)
})
- if _, err := client.Issues.Lock("o", "r", 1); err != nil {
+ if _, err := client.Issues.Lock(context.Background(), "o", "r", 1); err != nil {
t.Errorf("Issues.Lock returned error: %v", err)
}
}
@@ -270,7 +271,7 @@ func TestIssuesService_Unlock(t *testing.T) {
w.WriteHeader(http.StatusNoContent)
})
- if _, err := client.Issues.Unlock("o", "r", 1); err != nil {
+ if _, err := client.Issues.Unlock(context.Background(), "o", "r", 1); err != nil {
t.Errorf("Issues.Unlock returned error: %v", err)
}
}
diff --git a/github/issues_timeline.go b/github/issues_timeline.go
index d20eef8f073..bc0b1089903 100644
--- a/github/issues_timeline.go
+++ b/github/issues_timeline.go
@@ -6,6 +6,7 @@
package github
import (
+ "context"
"fmt"
"time"
)
@@ -127,7 +128,7 @@ type Source struct {
// ListIssueTimeline lists events for the specified issue.
//
// GitHub API docs: https://developer.github.com/v3/issues/timeline/#list-events-for-an-issue
-func (s *IssuesService) ListIssueTimeline(owner, repo string, number int, opt *ListOptions) ([]*Timeline, *Response, error) {
+func (s *IssuesService) ListIssueTimeline(ctx context.Context, owner, repo string, number int, opt *ListOptions) ([]*Timeline, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/issues/%v/timeline", owner, repo, number)
u, err := addOptions(u, opt)
if err != nil {
@@ -143,6 +144,6 @@ func (s *IssuesService) ListIssueTimeline(owner, repo string, number int, opt *L
req.Header.Set("Accept", mediaTypeTimelinePreview)
var events []*Timeline
- resp, err := s.client.Do(req, &events)
+ resp, err := s.client.Do(ctx, req, &events)
return events, resp, err
}
diff --git a/github/issues_timeline_test.go b/github/issues_timeline_test.go
index fb67fd6b119..2fd22109b06 100644
--- a/github/issues_timeline_test.go
+++ b/github/issues_timeline_test.go
@@ -6,6 +6,7 @@
package github
import (
+ "context"
"fmt"
"net/http"
"reflect"
@@ -27,7 +28,7 @@ func TestIssuesService_ListIssueTimeline(t *testing.T) {
})
opt := &ListOptions{Page: 1, PerPage: 2}
- events, _, err := client.Issues.ListIssueTimeline("o", "r", 1, opt)
+ events, _, err := client.Issues.ListIssueTimeline(context.Background(), "o", "r", 1, opt)
if err != nil {
t.Errorf("Issues.ListIssueTimeline returned error: %v", err)
}
diff --git a/github/licenses.go b/github/licenses.go
index 5340e617c77..e9cd1777afb 100644
--- a/github/licenses.go
+++ b/github/licenses.go
@@ -5,7 +5,10 @@
package github
-import "fmt"
+import (
+ "context"
+ "fmt"
+)
// LicensesService handles communication with the license related
// methods of the GitHub API.
@@ -58,7 +61,7 @@ func (l License) String() string {
// List popular open source licenses.
//
// GitHub API docs: https://developer.github.com/v3/licenses/#list-all-licenses
-func (s *LicensesService) List() ([]*License, *Response, error) {
+func (s *LicensesService) List(ctx context.Context) ([]*License, *Response, error) {
req, err := s.client.NewRequest("GET", "licenses", nil)
if err != nil {
return nil, nil, err
@@ -68,7 +71,7 @@ func (s *LicensesService) List() ([]*License, *Response, error) {
req.Header.Set("Accept", mediaTypeLicensesPreview)
var licenses []*License
- resp, err := s.client.Do(req, &licenses)
+ resp, err := s.client.Do(ctx, req, &licenses)
if err != nil {
return nil, resp, err
}
@@ -79,7 +82,7 @@ func (s *LicensesService) List() ([]*License, *Response, error) {
// Get extended metadata for one license.
//
// GitHub API docs: https://developer.github.com/v3/licenses/#get-an-individual-license
-func (s *LicensesService) Get(licenseName string) (*License, *Response, error) {
+func (s *LicensesService) Get(ctx context.Context, licenseName string) (*License, *Response, error) {
u := fmt.Sprintf("licenses/%s", licenseName)
req, err := s.client.NewRequest("GET", u, nil)
@@ -91,7 +94,7 @@ func (s *LicensesService) Get(licenseName string) (*License, *Response, error) {
req.Header.Set("Accept", mediaTypeLicensesPreview)
license := new(License)
- resp, err := s.client.Do(req, license)
+ resp, err := s.client.Do(ctx, req, license)
if err != nil {
return nil, resp, err
}
diff --git a/github/licenses_test.go b/github/licenses_test.go
index 00a621cb84b..5c06e659854 100644
--- a/github/licenses_test.go
+++ b/github/licenses_test.go
@@ -6,6 +6,7 @@
package github
import (
+ "context"
"fmt"
"net/http"
"reflect"
@@ -22,7 +23,7 @@ func TestLicensesService_List(t *testing.T) {
fmt.Fprint(w, `[{"key":"mit","name":"MIT","spdx_id":"MIT","url":"https://api.github.com/licenses/mit","featured":true}]`)
})
- licenses, _, err := client.Licenses.List()
+ licenses, _, err := client.Licenses.List(context.Background())
if err != nil {
t.Errorf("Licenses.List returned error: %v", err)
}
@@ -49,7 +50,7 @@ func TestLicensesService_Get(t *testing.T) {
fmt.Fprint(w, `{"key":"mit","name":"MIT"}`)
})
- license, _, err := client.Licenses.Get("mit")
+ license, _, err := client.Licenses.Get(context.Background(), "mit")
if err != nil {
t.Errorf("Licenses.Get returned error: %v", err)
}
@@ -61,6 +62,6 @@ func TestLicensesService_Get(t *testing.T) {
}
func TestLicensesService_Get_invalidTemplate(t *testing.T) {
- _, _, err := client.Licenses.Get("%")
+ _, _, err := client.Licenses.Get(context.Background(), "%")
testURLParseError(t, err)
}
diff --git a/github/migrations.go b/github/migrations.go
index a7890b0a32b..6793269cd39 100644
--- a/github/migrations.go
+++ b/github/migrations.go
@@ -6,6 +6,7 @@
package github
import (
+ "context"
"errors"
"fmt"
"net/http"
@@ -74,7 +75,7 @@ type startMigration struct {
// repos is a slice of repository names to migrate.
//
// GitHub API docs: https://developer.github.com/v3/migration/migrations/#start-a-migration
-func (s *MigrationService) StartMigration(org string, repos []string, opt *MigrationOptions) (*Migration, *Response, error) {
+func (s *MigrationService) StartMigration(ctx context.Context, org string, repos []string, opt *MigrationOptions) (*Migration, *Response, error) {
u := fmt.Sprintf("orgs/%v/migrations", org)
body := &startMigration{Repositories: repos}
@@ -92,7 +93,7 @@ func (s *MigrationService) StartMigration(org string, repos []string, opt *Migra
req.Header.Set("Accept", mediaTypeMigrationsPreview)
m := &Migration{}
- resp, err := s.client.Do(req, m)
+ resp, err := s.client.Do(ctx, req, m)
if err != nil {
return nil, resp, err
}
@@ -103,7 +104,7 @@ func (s *MigrationService) StartMigration(org string, repos []string, opt *Migra
// ListMigrations lists the most recent migrations.
//
// GitHub API docs: https://developer.github.com/v3/migration/migrations/#get-a-list-of-migrations
-func (s *MigrationService) ListMigrations(org string) ([]*Migration, *Response, error) {
+func (s *MigrationService) ListMigrations(ctx context.Context, org string) ([]*Migration, *Response, error) {
u := fmt.Sprintf("orgs/%v/migrations", org)
req, err := s.client.NewRequest("GET", u, nil)
@@ -115,7 +116,7 @@ func (s *MigrationService) ListMigrations(org string) ([]*Migration, *Response,
req.Header.Set("Accept", mediaTypeMigrationsPreview)
var m []*Migration
- resp, err := s.client.Do(req, &m)
+ resp, err := s.client.Do(ctx, req, &m)
if err != nil {
return nil, resp, err
}
@@ -127,7 +128,7 @@ func (s *MigrationService) ListMigrations(org string) ([]*Migration, *Response,
// id is the migration ID.
//
// GitHub API docs: https://developer.github.com/v3/migration/migrations/#get-the-status-of-a-migration
-func (s *MigrationService) MigrationStatus(org string, id int) (*Migration, *Response, error) {
+func (s *MigrationService) MigrationStatus(ctx context.Context, org string, id int) (*Migration, *Response, error) {
u := fmt.Sprintf("orgs/%v/migrations/%v", org, id)
req, err := s.client.NewRequest("GET", u, nil)
@@ -139,7 +140,7 @@ func (s *MigrationService) MigrationStatus(org string, id int) (*Migration, *Res
req.Header.Set("Accept", mediaTypeMigrationsPreview)
m := &Migration{}
- resp, err := s.client.Do(req, m)
+ resp, err := s.client.Do(ctx, req, m)
if err != nil {
return nil, resp, err
}
@@ -151,7 +152,7 @@ func (s *MigrationService) MigrationStatus(org string, id int) (*Migration, *Res
// id is the migration ID.
//
// GitHub API docs: https://developer.github.com/v3/migration/migrations/#download-a-migration-archive
-func (s *MigrationService) MigrationArchiveURL(org string, id int) (url string, err error) {
+func (s *MigrationService) MigrationArchiveURL(ctx context.Context, org string, id int) (url string, err error) {
u := fmt.Sprintf("orgs/%v/migrations/%v/archive", org, id)
req, err := s.client.NewRequest("GET", u, nil)
@@ -174,7 +175,7 @@ func (s *MigrationService) MigrationArchiveURL(org string, id int) (url string,
}
defer func() { s.client.client.CheckRedirect = saveRedirect }()
- _, err = s.client.Do(req, nil) // expect error from disable redirect
+ _, err = s.client.Do(ctx, req, nil) // expect error from disable redirect
if err == nil {
return "", errors.New("expected redirect, none provided")
}
@@ -188,7 +189,7 @@ func (s *MigrationService) MigrationArchiveURL(org string, id int) (url string,
// id is the migration ID.
//
// GitHub API docs: https://developer.github.com/v3/migration/migrations/#delete-a-migration-archive
-func (s *MigrationService) DeleteMigration(org string, id int) (*Response, error) {
+func (s *MigrationService) DeleteMigration(ctx context.Context, org string, id int) (*Response, error) {
u := fmt.Sprintf("orgs/%v/migrations/%v/archive", org, id)
req, err := s.client.NewRequest("DELETE", u, nil)
@@ -199,7 +200,7 @@ func (s *MigrationService) DeleteMigration(org string, id int) (*Response, error
// TODO: remove custom Accept header when this API fully launches.
req.Header.Set("Accept", mediaTypeMigrationsPreview)
- return s.client.Do(req, nil)
+ return s.client.Do(ctx, req, nil)
}
// UnlockRepo unlocks a repository that was locked for migration.
@@ -208,7 +209,7 @@ func (s *MigrationService) DeleteMigration(org string, id int) (*Response, error
// is complete and you no longer need the source data.
//
// GitHub API docs: https://developer.github.com/v3/migration/migrations/#unlock-a-repository
-func (s *MigrationService) UnlockRepo(org string, id int, repo string) (*Response, error) {
+func (s *MigrationService) UnlockRepo(ctx context.Context, org string, id int, repo string) (*Response, error) {
u := fmt.Sprintf("orgs/%v/migrations/%v/repos/%v/lock", org, id, repo)
req, err := s.client.NewRequest("DELETE", u, nil)
@@ -219,5 +220,5 @@ func (s *MigrationService) UnlockRepo(org string, id int, repo string) (*Respons
// TODO: remove custom Accept header when this API fully launches.
req.Header.Set("Accept", mediaTypeMigrationsPreview)
- return s.client.Do(req, nil)
+ return s.client.Do(ctx, req, nil)
}
diff --git a/github/migrations_source_import.go b/github/migrations_source_import.go
index d593e405236..aa45a5a3645 100644
--- a/github/migrations_source_import.go
+++ b/github/migrations_source_import.go
@@ -5,7 +5,10 @@
package github
-import "fmt"
+import (
+ "context"
+ "fmt"
+)
// Import represents a repository import request.
type Import struct {
@@ -144,7 +147,7 @@ func (f LargeFile) String() string {
// StartImport initiates a repository import.
//
// GitHub API docs: https://developer.github.com/v3/migration/source_imports/#start-an-import
-func (s *MigrationService) StartImport(owner, repo string, in *Import) (*Import, *Response, error) {
+func (s *MigrationService) StartImport(ctx context.Context, owner, repo string, in *Import) (*Import, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/import", owner, repo)
req, err := s.client.NewRequest("PUT", u, in)
if err != nil {
@@ -155,7 +158,7 @@ func (s *MigrationService) StartImport(owner, repo string, in *Import) (*Import,
req.Header.Set("Accept", mediaTypeImportPreview)
out := new(Import)
- resp, err := s.client.Do(req, out)
+ resp, err := s.client.Do(ctx, req, out)
if err != nil {
return nil, resp, err
}
@@ -166,7 +169,7 @@ func (s *MigrationService) StartImport(owner, repo string, in *Import) (*Import,
// ImportProgress queries for the status and progress of an ongoing repository import.
//
// GitHub API docs: https://developer.github.com/v3/migration/source_imports/#get-import-progress
-func (s *MigrationService) ImportProgress(owner, repo string) (*Import, *Response, error) {
+func (s *MigrationService) ImportProgress(ctx context.Context, owner, repo string) (*Import, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/import", owner, repo)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
@@ -177,7 +180,7 @@ func (s *MigrationService) ImportProgress(owner, repo string) (*Import, *Respons
req.Header.Set("Accept", mediaTypeImportPreview)
out := new(Import)
- resp, err := s.client.Do(req, out)
+ resp, err := s.client.Do(ctx, req, out)
if err != nil {
return nil, resp, err
}
@@ -188,7 +191,7 @@ func (s *MigrationService) ImportProgress(owner, repo string) (*Import, *Respons
// UpdateImport initiates a repository import.
//
// GitHub API docs: https://developer.github.com/v3/migration/source_imports/#update-existing-import
-func (s *MigrationService) UpdateImport(owner, repo string, in *Import) (*Import, *Response, error) {
+func (s *MigrationService) UpdateImport(ctx context.Context, owner, repo string, in *Import) (*Import, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/import", owner, repo)
req, err := s.client.NewRequest("PATCH", u, in)
if err != nil {
@@ -199,7 +202,7 @@ func (s *MigrationService) UpdateImport(owner, repo string, in *Import) (*Import
req.Header.Set("Accept", mediaTypeImportPreview)
out := new(Import)
- resp, err := s.client.Do(req, out)
+ resp, err := s.client.Do(ctx, req, out)
if err != nil {
return nil, resp, err
}
@@ -220,7 +223,7 @@ func (s *MigrationService) UpdateImport(owner, repo string, in *Import) (*Import
// information.
//
// GitHub API docs: https://developer.github.com/v3/migration/source_imports/#get-commit-authors
-func (s *MigrationService) CommitAuthors(owner, repo string) ([]*SourceImportAuthor, *Response, error) {
+func (s *MigrationService) CommitAuthors(ctx context.Context, owner, repo string) ([]*SourceImportAuthor, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/import/authors", owner, repo)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
@@ -231,7 +234,7 @@ func (s *MigrationService) CommitAuthors(owner, repo string) ([]*SourceImportAut
req.Header.Set("Accept", mediaTypeImportPreview)
var authors []*SourceImportAuthor
- resp, err := s.client.Do(req, &authors)
+ resp, err := s.client.Do(ctx, req, &authors)
if err != nil {
return nil, resp, err
}
@@ -244,7 +247,7 @@ func (s *MigrationService) CommitAuthors(owner, repo string) ([]*SourceImportAut
// commits to the repository.
//
// GitHub API docs: https://developer.github.com/v3/migration/source_imports/#map-a-commit-author
-func (s *MigrationService) MapCommitAuthor(owner, repo string, id int, author *SourceImportAuthor) (*SourceImportAuthor, *Response, error) {
+func (s *MigrationService) MapCommitAuthor(ctx context.Context, owner, repo string, id int, author *SourceImportAuthor) (*SourceImportAuthor, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/import/authors/%v", owner, repo, id)
req, err := s.client.NewRequest("PATCH", u, author)
if err != nil {
@@ -255,7 +258,7 @@ func (s *MigrationService) MapCommitAuthor(owner, repo string, id int, author *S
req.Header.Set("Accept", mediaTypeImportPreview)
out := new(SourceImportAuthor)
- resp, err := s.client.Do(req, out)
+ resp, err := s.client.Do(ctx, req, out)
if err != nil {
return nil, resp, err
}
@@ -268,7 +271,7 @@ func (s *MigrationService) MapCommitAuthor(owner, repo string, id int, author *S
// used.
//
// GitHub API docs: https://developer.github.com/v3/migration/source_imports/#set-git-lfs-preference
-func (s *MigrationService) SetLFSPreference(owner, repo string, in *Import) (*Import, *Response, error) {
+func (s *MigrationService) SetLFSPreference(ctx context.Context, owner, repo string, in *Import) (*Import, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/import/lfs", owner, repo)
req, err := s.client.NewRequest("PATCH", u, in)
if err != nil {
@@ -279,7 +282,7 @@ func (s *MigrationService) SetLFSPreference(owner, repo string, in *Import) (*Im
req.Header.Set("Accept", mediaTypeImportPreview)
out := new(Import)
- resp, err := s.client.Do(req, out)
+ resp, err := s.client.Do(ctx, req, out)
if err != nil {
return nil, resp, err
}
@@ -290,7 +293,7 @@ func (s *MigrationService) SetLFSPreference(owner, repo string, in *Import) (*Im
// LargeFiles lists files larger than 100MB found during the import.
//
// GitHub API docs: https://developer.github.com/v3/migration/source_imports/#get-large-files
-func (s *MigrationService) LargeFiles(owner, repo string) ([]*LargeFile, *Response, error) {
+func (s *MigrationService) LargeFiles(ctx context.Context, owner, repo string) ([]*LargeFile, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/import/large_files", owner, repo)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
@@ -301,7 +304,7 @@ func (s *MigrationService) LargeFiles(owner, repo string) ([]*LargeFile, *Respon
req.Header.Set("Accept", mediaTypeImportPreview)
var files []*LargeFile
- resp, err := s.client.Do(req, &files)
+ resp, err := s.client.Do(ctx, req, &files)
if err != nil {
return nil, resp, err
}
@@ -312,7 +315,7 @@ func (s *MigrationService) LargeFiles(owner, repo string) ([]*LargeFile, *Respon
// CancelImport stops an import for a repository.
//
// GitHub API docs: https://developer.github.com/v3/migration/source_imports/#cancel-an-import
-func (s *MigrationService) CancelImport(owner, repo string) (*Response, error) {
+func (s *MigrationService) CancelImport(ctx context.Context, owner, repo string) (*Response, error) {
u := fmt.Sprintf("repos/%v/%v/import", owner, repo)
req, err := s.client.NewRequest("DELETE", u, nil)
if err != nil {
@@ -322,5 +325,5 @@ func (s *MigrationService) CancelImport(owner, repo string) (*Response, error) {
// TODO: remove custom Accept header when this API fully launches
req.Header.Set("Accept", mediaTypeImportPreview)
- return s.client.Do(req, nil)
+ return s.client.Do(ctx, req, nil)
}
diff --git a/github/migrations_source_import_test.go b/github/migrations_source_import_test.go
index 4995b597ca1..67b98fb42b9 100644
--- a/github/migrations_source_import_test.go
+++ b/github/migrations_source_import_test.go
@@ -6,6 +6,7 @@
package github
import (
+ "context"
"encoding/json"
"fmt"
"net/http"
@@ -38,7 +39,7 @@ func TestMigrationService_StartImport(t *testing.T) {
fmt.Fprint(w, `{"status":"importing"}`)
})
- got, _, err := client.Migrations.StartImport("o", "r", input)
+ got, _, err := client.Migrations.StartImport(context.Background(), "o", "r", input)
if err != nil {
t.Errorf("StartImport returned error: %v", err)
}
@@ -58,7 +59,7 @@ func TestMigrationService_ImportProgress(t *testing.T) {
fmt.Fprint(w, `{"status":"complete"}`)
})
- got, _, err := client.Migrations.ImportProgress("o", "r")
+ got, _, err := client.Migrations.ImportProgress(context.Background(), "o", "r")
if err != nil {
t.Errorf("ImportProgress returned error: %v", err)
}
@@ -93,7 +94,7 @@ func TestMigrationService_UpdateImport(t *testing.T) {
fmt.Fprint(w, `{"status":"importing"}`)
})
- got, _, err := client.Migrations.UpdateImport("o", "r", input)
+ got, _, err := client.Migrations.UpdateImport(context.Background(), "o", "r", input)
if err != nil {
t.Errorf("UpdateImport returned error: %v", err)
}
@@ -113,7 +114,7 @@ func TestMigrationService_CommitAuthors(t *testing.T) {
fmt.Fprint(w, `[{"id":1,"name":"a"},{"id":2,"name":"b"}]`)
})
- got, _, err := client.Migrations.CommitAuthors("o", "r")
+ got, _, err := client.Migrations.CommitAuthors(context.Background(), "o", "r")
if err != nil {
t.Errorf("CommitAuthors returned error: %v", err)
}
@@ -145,7 +146,7 @@ func TestMigrationService_MapCommitAuthor(t *testing.T) {
fmt.Fprint(w, `{"id": 1}`)
})
- got, _, err := client.Migrations.MapCommitAuthor("o", "r", 1, input)
+ got, _, err := client.Migrations.MapCommitAuthor(context.Background(), "o", "r", 1, input)
if err != nil {
t.Errorf("MapCommitAuthor returned error: %v", err)
}
@@ -175,7 +176,7 @@ func TestMigrationService_SetLFSPreference(t *testing.T) {
fmt.Fprint(w, `{"status":"importing"}`)
})
- got, _, err := client.Migrations.SetLFSPreference("o", "r", input)
+ got, _, err := client.Migrations.SetLFSPreference(context.Background(), "o", "r", input)
if err != nil {
t.Errorf("SetLFSPreference returned error: %v", err)
}
@@ -195,7 +196,7 @@ func TestMigrationService_LargeFiles(t *testing.T) {
fmt.Fprint(w, `[{"oid":"a"},{"oid":"b"}]`)
})
- got, _, err := client.Migrations.LargeFiles("o", "r")
+ got, _, err := client.Migrations.LargeFiles(context.Background(), "o", "r")
if err != nil {
t.Errorf("LargeFiles returned error: %v", err)
}
@@ -218,7 +219,7 @@ func TestMigrationService_CancelImport(t *testing.T) {
w.WriteHeader(http.StatusNoContent)
})
- _, err := client.Migrations.CancelImport("o", "r")
+ _, err := client.Migrations.CancelImport(context.Background(), "o", "r")
if err != nil {
t.Errorf("CancelImport returned error: %v", err)
}
diff --git a/github/migrations_test.go b/github/migrations_test.go
index 9a902e410db..7e0ac0f7506 100644
--- a/github/migrations_test.go
+++ b/github/migrations_test.go
@@ -6,6 +6,7 @@
package github
import (
+ "context"
"fmt"
"net/http"
"reflect"
@@ -29,7 +30,7 @@ func TestMigrationService_StartMigration(t *testing.T) {
LockRepositories: true,
ExcludeAttachments: false,
}
- got, _, err := client.Migrations.StartMigration("o", []string{"r"}, opt)
+ got, _, err := client.Migrations.StartMigration(context.Background(), "o", []string{"r"}, opt)
if err != nil {
t.Errorf("StartMigration returned error: %v", err)
}
@@ -50,7 +51,7 @@ func TestMigrationService_ListMigrations(t *testing.T) {
w.Write([]byte(fmt.Sprintf("[%s]", migrationJSON)))
})
- got, _, err := client.Migrations.ListMigrations("o")
+ got, _, err := client.Migrations.ListMigrations(context.Background(), "o")
if err != nil {
t.Errorf("ListMigrations returned error: %v", err)
}
@@ -71,7 +72,7 @@ func TestMigrationService_MigrationStatus(t *testing.T) {
w.Write(migrationJSON)
})
- got, _, err := client.Migrations.MigrationStatus("o", 1)
+ got, _, err := client.Migrations.MigrationStatus(context.Background(), "o", 1)
if err != nil {
t.Errorf("MigrationStatus returned error: %v", err)
}
@@ -97,7 +98,7 @@ func TestMigrationService_MigrationArchiveURL(t *testing.T) {
w.Write([]byte("0123456789abcdef"))
})
- got, err := client.Migrations.MigrationArchiveURL("o", 1)
+ got, err := client.Migrations.MigrationArchiveURL(context.Background(), "o", 1)
if err != nil {
t.Errorf("MigrationStatus returned error: %v", err)
}
@@ -117,7 +118,7 @@ func TestMigrationService_DeleteMigration(t *testing.T) {
w.WriteHeader(http.StatusNoContent)
})
- if _, err := client.Migrations.DeleteMigration("o", 1); err != nil {
+ if _, err := client.Migrations.DeleteMigration(context.Background(), "o", 1); err != nil {
t.Errorf("DeleteMigration returned error: %v", err)
}
}
@@ -133,7 +134,7 @@ func TestMigrationService_UnlockRepo(t *testing.T) {
w.WriteHeader(http.StatusNoContent)
})
- if _, err := client.Migrations.UnlockRepo("o", 1, "r"); err != nil {
+ if _, err := client.Migrations.UnlockRepo(context.Background(), "o", 1, "r"); err != nil {
t.Errorf("UnlockRepo returned error: %v", err)
}
}
diff --git a/github/misc.go b/github/misc.go
index 0cdb3f77895..42d0d303393 100644
--- a/github/misc.go
+++ b/github/misc.go
@@ -7,6 +7,7 @@ package github
import (
"bytes"
+ "context"
"fmt"
"net/url"
)
@@ -39,7 +40,7 @@ type markdownRequest struct {
// Markdown renders an arbitrary Markdown document.
//
// GitHub API docs: https://developer.github.com/v3/markdown/
-func (c *Client) Markdown(text string, opt *MarkdownOptions) (string, *Response, error) {
+func (c *Client) Markdown(ctx context.Context, text string, opt *MarkdownOptions) (string, *Response, error) {
request := &markdownRequest{Text: String(text)}
if opt != nil {
if opt.Mode != "" {
@@ -56,7 +57,7 @@ func (c *Client) Markdown(text string, opt *MarkdownOptions) (string, *Response,
}
buf := new(bytes.Buffer)
- resp, err := c.Do(req, buf)
+ resp, err := c.Do(ctx, req, buf)
if err != nil {
return "", resp, err
}
@@ -67,14 +68,14 @@ func (c *Client) Markdown(text string, opt *MarkdownOptions) (string, *Response,
// ListEmojis returns the emojis available to use on GitHub.
//
// GitHub API docs: https://developer.github.com/v3/emojis/
-func (c *Client) ListEmojis() (map[string]string, *Response, error) {
+func (c *Client) ListEmojis(ctx context.Context) (map[string]string, *Response, error) {
req, err := c.NewRequest("GET", "emojis", nil)
if err != nil {
return nil, nil, err
}
var emoji map[string]string
- resp, err := c.Do(req, &emoji)
+ resp, err := c.Do(ctx, req, &emoji)
if err != nil {
return nil, resp, err
}
@@ -109,14 +110,14 @@ type APIMeta struct {
// endpoint provides information about that installation.
//
// GitHub API docs: https://developer.github.com/v3/meta/
-func (c *Client) APIMeta() (*APIMeta, *Response, error) {
+func (c *Client) APIMeta(ctx context.Context) (*APIMeta, *Response, error) {
req, err := c.NewRequest("GET", "meta", nil)
if err != nil {
return nil, nil, err
}
meta := new(APIMeta)
- resp, err := c.Do(req, meta)
+ resp, err := c.Do(ctx, req, meta)
if err != nil {
return nil, resp, err
}
@@ -126,7 +127,7 @@ func (c *Client) APIMeta() (*APIMeta, *Response, error) {
// Octocat returns an ASCII art octocat with the specified message in a speech
// bubble. If message is empty, a random zen phrase is used.
-func (c *Client) Octocat(message string) (string, *Response, error) {
+func (c *Client) Octocat(ctx context.Context, message string) (string, *Response, error) {
u := "octocat"
if message != "" {
u = fmt.Sprintf("%s?s=%s", u, url.QueryEscape(message))
@@ -138,7 +139,7 @@ func (c *Client) Octocat(message string) (string, *Response, error) {
}
buf := new(bytes.Buffer)
- resp, err := c.Do(req, buf)
+ resp, err := c.Do(ctx, req, buf)
if err != nil {
return "", resp, err
}
@@ -149,14 +150,14 @@ func (c *Client) Octocat(message string) (string, *Response, error) {
// Zen returns a random line from The Zen of GitHub.
//
// see also: http://warpspire.com/posts/taste/
-func (c *Client) Zen() (string, *Response, error) {
+func (c *Client) Zen(ctx context.Context) (string, *Response, error) {
req, err := c.NewRequest("GET", "zen", nil)
if err != nil {
return "", nil, err
}
buf := new(bytes.Buffer)
- resp, err := c.Do(req, buf)
+ resp, err := c.Do(ctx, req, buf)
if err != nil {
return "", resp, err
}
@@ -180,7 +181,7 @@ func (s *ServiceHook) String() string {
// ListServiceHooks lists all of the available service hooks.
//
// GitHub API docs: https://developer.github.com/webhooks/#services
-func (c *Client) ListServiceHooks() ([]*ServiceHook, *Response, error) {
+func (c *Client) ListServiceHooks(ctx context.Context) ([]*ServiceHook, *Response, error) {
u := "hooks"
req, err := c.NewRequest("GET", u, nil)
if err != nil {
@@ -188,7 +189,7 @@ func (c *Client) ListServiceHooks() ([]*ServiceHook, *Response, error) {
}
var hooks []*ServiceHook
- resp, err := c.Do(req, &hooks)
+ resp, err := c.Do(ctx, req, &hooks)
if err != nil {
return nil, resp, err
}
diff --git a/github/misc_test.go b/github/misc_test.go
index 71eb2f7054e..af72acf7218 100644
--- a/github/misc_test.go
+++ b/github/misc_test.go
@@ -6,6 +6,7 @@
package github
import (
+ "context"
"encoding/json"
"fmt"
"net/http"
@@ -33,7 +34,7 @@ func TestMarkdown(t *testing.T) {
fmt.Fprint(w, `
text
`)
})
- md, _, err := client.Markdown("# text #", &MarkdownOptions{
+ md, _, err := client.Markdown(context.Background(), "# text #", &MarkdownOptions{
Mode: "gfm",
Context: "google/go-github",
})
@@ -55,7 +56,7 @@ func TestListEmojis(t *testing.T) {
fmt.Fprint(w, `{"+1": "+1.png"}`)
})
- emoji, _, err := client.ListEmojis()
+ emoji, _, err := client.ListEmojis(context.Background())
if err != nil {
t.Errorf("ListEmojis returned error: %v", err)
}
@@ -75,7 +76,7 @@ func TestAPIMeta(t *testing.T) {
fmt.Fprint(w, `{"hooks":["h"], "git":["g"], "pages":["p"], "verifiable_password_authentication": true}`)
})
- meta, _, err := client.APIMeta()
+ meta, _, err := client.APIMeta(context.Background())
if err != nil {
t.Errorf("APIMeta returned error: %v", err)
}
@@ -105,7 +106,7 @@ func TestOctocat(t *testing.T) {
fmt.Fprint(w, output)
})
- got, _, err := client.Octocat(input)
+ got, _, err := client.Octocat(context.Background(), input)
if err != nil {
t.Errorf("Octocat returned error: %v", err)
}
@@ -127,7 +128,7 @@ func TestZen(t *testing.T) {
fmt.Fprint(w, output)
})
- got, _, err := client.Zen()
+ got, _, err := client.Zen(context.Background())
if err != nil {
t.Errorf("Zen returned error: %v", err)
}
@@ -153,7 +154,7 @@ func TestListServiceHooks(t *testing.T) {
}]`)
})
- hooks, _, err := client.ListServiceHooks()
+ hooks, _, err := client.ListServiceHooks(context.Background())
if err != nil {
t.Errorf("ListServiceHooks returned error: %v", err)
}
diff --git a/github/orgs.go b/github/orgs.go
index 7421605cdc6..8b126f00f14 100644
--- a/github/orgs.go
+++ b/github/orgs.go
@@ -6,6 +6,7 @@
package github
import (
+ "context"
"fmt"
"time"
)
@@ -85,7 +86,7 @@ type OrganizationsListOptions struct {
// as the opts.Since parameter for the next call.
//
// GitHub API docs: https://developer.github.com/v3/orgs/#list-all-organizations
-func (s *OrganizationsService) ListAll(opt *OrganizationsListOptions) ([]*Organization, *Response, error) {
+func (s *OrganizationsService) ListAll(ctx context.Context, opt *OrganizationsListOptions) ([]*Organization, *Response, error) {
u, err := addOptions("organizations", opt)
if err != nil {
return nil, nil, err
@@ -97,7 +98,7 @@ func (s *OrganizationsService) ListAll(opt *OrganizationsListOptions) ([]*Organi
}
orgs := []*Organization{}
- resp, err := s.client.Do(req, &orgs)
+ resp, err := s.client.Do(ctx, req, &orgs)
if err != nil {
return nil, resp, err
}
@@ -108,7 +109,7 @@ func (s *OrganizationsService) ListAll(opt *OrganizationsListOptions) ([]*Organi
// organizations for the authenticated user.
//
// GitHub API docs: https://developer.github.com/v3/orgs/#list-user-organizations
-func (s *OrganizationsService) List(user string, opt *ListOptions) ([]*Organization, *Response, error) {
+func (s *OrganizationsService) List(ctx context.Context, user string, opt *ListOptions) ([]*Organization, *Response, error) {
var u string
if user != "" {
u = fmt.Sprintf("users/%v/orgs", user)
@@ -126,7 +127,7 @@ func (s *OrganizationsService) List(user string, opt *ListOptions) ([]*Organizat
}
var orgs []*Organization
- resp, err := s.client.Do(req, &orgs)
+ resp, err := s.client.Do(ctx, req, &orgs)
if err != nil {
return nil, resp, err
}
@@ -137,7 +138,7 @@ func (s *OrganizationsService) List(user string, opt *ListOptions) ([]*Organizat
// Get fetches an organization by name.
//
// GitHub API docs: https://developer.github.com/v3/orgs/#get-an-organization
-func (s *OrganizationsService) Get(org string) (*Organization, *Response, error) {
+func (s *OrganizationsService) Get(ctx context.Context, org string) (*Organization, *Response, error) {
u := fmt.Sprintf("orgs/%v", org)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
@@ -145,7 +146,7 @@ func (s *OrganizationsService) Get(org string) (*Organization, *Response, error)
}
organization := new(Organization)
- resp, err := s.client.Do(req, organization)
+ resp, err := s.client.Do(ctx, req, organization)
if err != nil {
return nil, resp, err
}
@@ -156,7 +157,7 @@ func (s *OrganizationsService) Get(org string) (*Organization, *Response, error)
// Edit an organization.
//
// GitHub API docs: https://developer.github.com/v3/orgs/#edit-an-organization
-func (s *OrganizationsService) Edit(name string, org *Organization) (*Organization, *Response, error) {
+func (s *OrganizationsService) Edit(ctx context.Context, name string, org *Organization) (*Organization, *Response, error) {
u := fmt.Sprintf("orgs/%v", name)
req, err := s.client.NewRequest("PATCH", u, org)
if err != nil {
@@ -164,7 +165,7 @@ func (s *OrganizationsService) Edit(name string, org *Organization) (*Organizati
}
o := new(Organization)
- resp, err := s.client.Do(req, o)
+ resp, err := s.client.Do(ctx, req, o)
if err != nil {
return nil, resp, err
}
diff --git a/github/orgs_hooks.go b/github/orgs_hooks.go
index 6dc1052172d..4fc692e0f63 100644
--- a/github/orgs_hooks.go
+++ b/github/orgs_hooks.go
@@ -5,12 +5,15 @@
package github
-import "fmt"
+import (
+ "context"
+ "fmt"
+)
// ListHooks lists all Hooks for the specified organization.
//
// GitHub API docs: https://developer.github.com/v3/orgs/hooks/#list-hooks
-func (s *OrganizationsService) ListHooks(org string, opt *ListOptions) ([]*Hook, *Response, error) {
+func (s *OrganizationsService) ListHooks(ctx context.Context, org string, opt *ListOptions) ([]*Hook, *Response, error) {
u := fmt.Sprintf("orgs/%v/hooks", org)
u, err := addOptions(u, opt)
if err != nil {
@@ -23,7 +26,7 @@ func (s *OrganizationsService) ListHooks(org string, opt *ListOptions) ([]*Hook,
}
var hooks []*Hook
- resp, err := s.client.Do(req, &hooks)
+ resp, err := s.client.Do(ctx, req, &hooks)
if err != nil {
return nil, resp, err
}
@@ -34,14 +37,14 @@ func (s *OrganizationsService) ListHooks(org string, opt *ListOptions) ([]*Hook,
// GetHook returns a single specified Hook.
//
// GitHub API docs: https://developer.github.com/v3/orgs/hooks/#get-single-hook
-func (s *OrganizationsService) GetHook(org string, id int) (*Hook, *Response, error) {
+func (s *OrganizationsService) GetHook(ctx context.Context, org string, id int) (*Hook, *Response, error) {
u := fmt.Sprintf("orgs/%v/hooks/%d", org, id)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}
hook := new(Hook)
- resp, err := s.client.Do(req, hook)
+ resp, err := s.client.Do(ctx, req, hook)
return hook, resp, err
}
@@ -49,7 +52,7 @@ func (s *OrganizationsService) GetHook(org string, id int) (*Hook, *Response, er
// Name and Config are required fields.
//
// GitHub API docs: https://developer.github.com/v3/orgs/hooks/#create-a-hook
-func (s *OrganizationsService) CreateHook(org string, hook *Hook) (*Hook, *Response, error) {
+func (s *OrganizationsService) CreateHook(ctx context.Context, org string, hook *Hook) (*Hook, *Response, error) {
u := fmt.Sprintf("orgs/%v/hooks", org)
req, err := s.client.NewRequest("POST", u, hook)
if err != nil {
@@ -57,7 +60,7 @@ func (s *OrganizationsService) CreateHook(org string, hook *Hook) (*Hook, *Respo
}
h := new(Hook)
- resp, err := s.client.Do(req, h)
+ resp, err := s.client.Do(ctx, req, h)
if err != nil {
return nil, resp, err
}
@@ -68,37 +71,37 @@ func (s *OrganizationsService) CreateHook(org string, hook *Hook) (*Hook, *Respo
// EditHook updates a specified Hook.
//
// GitHub API docs: https://developer.github.com/v3/orgs/hooks/#edit-a-hook
-func (s *OrganizationsService) EditHook(org string, id int, hook *Hook) (*Hook, *Response, error) {
+func (s *OrganizationsService) EditHook(ctx context.Context, org string, id int, hook *Hook) (*Hook, *Response, error) {
u := fmt.Sprintf("orgs/%v/hooks/%d", org, id)
req, err := s.client.NewRequest("PATCH", u, hook)
if err != nil {
return nil, nil, err
}
h := new(Hook)
- resp, err := s.client.Do(req, h)
+ resp, err := s.client.Do(ctx, req, h)
return h, resp, err
}
// PingHook triggers a 'ping' event to be sent to the Hook.
//
// GitHub API docs: https://developer.github.com/v3/orgs/hooks/#ping-a-hook
-func (s *OrganizationsService) PingHook(org string, id int) (*Response, error) {
+func (s *OrganizationsService) PingHook(ctx context.Context, org string, id int) (*Response, error) {
u := fmt.Sprintf("orgs/%v/hooks/%d/pings", org, id)
req, err := s.client.NewRequest("POST", u, nil)
if err != nil {
return nil, err
}
- return s.client.Do(req, nil)
+ return s.client.Do(ctx, req, nil)
}
// DeleteHook deletes a specified Hook.
//
// GitHub API docs: https://developer.github.com/v3/orgs/hooks/#delete-a-hook
-func (s *OrganizationsService) DeleteHook(org string, id int) (*Response, error) {
+func (s *OrganizationsService) DeleteHook(ctx context.Context, org string, id int) (*Response, error) {
u := fmt.Sprintf("orgs/%v/hooks/%d", org, id)
req, err := s.client.NewRequest("DELETE", u, nil)
if err != nil {
return nil, err
}
- return s.client.Do(req, nil)
+ return s.client.Do(ctx, req, nil)
}
diff --git a/github/orgs_hooks_test.go b/github/orgs_hooks_test.go
index b4c3af77789..69e75f9f4ac 100644
--- a/github/orgs_hooks_test.go
+++ b/github/orgs_hooks_test.go
@@ -6,6 +6,7 @@
package github
import (
+ "context"
"encoding/json"
"fmt"
"net/http"
@@ -25,7 +26,7 @@ func TestOrganizationsService_ListHooks(t *testing.T) {
opt := &ListOptions{Page: 2}
- hooks, _, err := client.Organizations.ListHooks("o", opt)
+ hooks, _, err := client.Organizations.ListHooks(context.Background(), "o", opt)
if err != nil {
t.Errorf("Organizations.ListHooks returned error: %v", err)
}
@@ -37,7 +38,7 @@ func TestOrganizationsService_ListHooks(t *testing.T) {
}
func TestOrganizationsService_ListHooks_invalidOrg(t *testing.T) {
- _, _, err := client.Organizations.ListHooks("%", nil)
+ _, _, err := client.Organizations.ListHooks(context.Background(), "%", nil)
testURLParseError(t, err)
}
@@ -50,7 +51,7 @@ func TestOrganizationsService_GetHook(t *testing.T) {
fmt.Fprint(w, `{"id":1}`)
})
- hook, _, err := client.Organizations.GetHook("o", 1)
+ hook, _, err := client.Organizations.GetHook(context.Background(), "o", 1)
if err != nil {
t.Errorf("Organizations.GetHook returned error: %v", err)
}
@@ -62,7 +63,7 @@ func TestOrganizationsService_GetHook(t *testing.T) {
}
func TestOrganizationsService_GetHook_invalidOrg(t *testing.T) {
- _, _, err := client.Organizations.GetHook("%", 1)
+ _, _, err := client.Organizations.GetHook(context.Background(), "%", 1)
testURLParseError(t, err)
}
@@ -84,7 +85,7 @@ func TestOrganizationsService_EditHook(t *testing.T) {
fmt.Fprint(w, `{"id":1}`)
})
- hook, _, err := client.Organizations.EditHook("o", 1, input)
+ hook, _, err := client.Organizations.EditHook(context.Background(), "o", 1, input)
if err != nil {
t.Errorf("Organizations.EditHook returned error: %v", err)
}
@@ -96,7 +97,7 @@ func TestOrganizationsService_EditHook(t *testing.T) {
}
func TestOrganizationsService_EditHook_invalidOrg(t *testing.T) {
- _, _, err := client.Organizations.EditHook("%", 1, nil)
+ _, _, err := client.Organizations.EditHook(context.Background(), "%", 1, nil)
testURLParseError(t, err)
}
@@ -108,7 +109,7 @@ func TestOrganizationsService_PingHook(t *testing.T) {
testMethod(t, r, "POST")
})
- _, err := client.Organizations.PingHook("o", 1)
+ _, err := client.Organizations.PingHook(context.Background(), "o", 1)
if err != nil {
t.Errorf("Organizations.PingHook returned error: %v", err)
}
@@ -122,13 +123,13 @@ func TestOrganizationsService_DeleteHook(t *testing.T) {
testMethod(t, r, "DELETE")
})
- _, err := client.Organizations.DeleteHook("o", 1)
+ _, err := client.Organizations.DeleteHook(context.Background(), "o", 1)
if err != nil {
t.Errorf("Organizations.DeleteHook returned error: %v", err)
}
}
func TestOrganizationsService_DeleteHook_invalidOrg(t *testing.T) {
- _, err := client.Organizations.DeleteHook("%", 1)
+ _, err := client.Organizations.DeleteHook(context.Background(), "%", 1)
testURLParseError(t, err)
}
diff --git a/github/orgs_members.go b/github/orgs_members.go
index 40dfc56fb5e..75d531ca119 100644
--- a/github/orgs_members.go
+++ b/github/orgs_members.go
@@ -5,7 +5,10 @@
package github
-import "fmt"
+import (
+ "context"
+ "fmt"
+)
// Membership represents the status of a user's membership in an organization or team.
type Membership struct {
@@ -69,7 +72,7 @@ type ListMembersOptions struct {
// public members, otherwise it will only return public members.
//
// GitHub API docs: https://developer.github.com/v3/orgs/members/#members-list
-func (s *OrganizationsService) ListMembers(org string, opt *ListMembersOptions) ([]*User, *Response, error) {
+func (s *OrganizationsService) ListMembers(ctx context.Context, org string, opt *ListMembersOptions) ([]*User, *Response, error) {
var u string
if opt != nil && opt.PublicOnly {
u = fmt.Sprintf("orgs/%v/public_members", org)
@@ -87,7 +90,7 @@ func (s *OrganizationsService) ListMembers(org string, opt *ListMembersOptions)
}
var members []*User
- resp, err := s.client.Do(req, &members)
+ resp, err := s.client.Do(ctx, req, &members)
if err != nil {
return nil, resp, err
}
@@ -98,14 +101,14 @@ func (s *OrganizationsService) ListMembers(org string, opt *ListMembersOptions)
// IsMember checks if a user is a member of an organization.
//
// GitHub API docs: https://developer.github.com/v3/orgs/members/#check-membership
-func (s *OrganizationsService) IsMember(org, user string) (bool, *Response, error) {
+func (s *OrganizationsService) IsMember(ctx context.Context, org, user string) (bool, *Response, error) {
u := fmt.Sprintf("orgs/%v/members/%v", org, user)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return false, nil, err
}
- resp, err := s.client.Do(req, nil)
+ resp, err := s.client.Do(ctx, req, nil)
member, err := parseBoolResponse(err)
return member, resp, err
}
@@ -113,14 +116,14 @@ func (s *OrganizationsService) IsMember(org, user string) (bool, *Response, erro
// IsPublicMember checks if a user is a public member of an organization.
//
// GitHub API docs: https://developer.github.com/v3/orgs/members/#check-public-membership
-func (s *OrganizationsService) IsPublicMember(org, user string) (bool, *Response, error) {
+func (s *OrganizationsService) IsPublicMember(ctx context.Context, org, user string) (bool, *Response, error) {
u := fmt.Sprintf("orgs/%v/public_members/%v", org, user)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return false, nil, err
}
- resp, err := s.client.Do(req, nil)
+ resp, err := s.client.Do(ctx, req, nil)
member, err := parseBoolResponse(err)
return member, resp, err
}
@@ -128,41 +131,41 @@ func (s *OrganizationsService) IsPublicMember(org, user string) (bool, *Response
// RemoveMember removes a user from all teams of an organization.
//
// GitHub API docs: https://developer.github.com/v3/orgs/members/#remove-a-member
-func (s *OrganizationsService) RemoveMember(org, user string) (*Response, error) {
+func (s *OrganizationsService) RemoveMember(ctx context.Context, org, user string) (*Response, error) {
u := fmt.Sprintf("orgs/%v/members/%v", org, user)
req, err := s.client.NewRequest("DELETE", u, nil)
if err != nil {
return nil, err
}
- return s.client.Do(req, nil)
+ return s.client.Do(ctx, req, nil)
}
// PublicizeMembership publicizes a user's membership in an organization. (A
// user cannot publicize the membership for another user.)
//
// GitHub API docs: https://developer.github.com/v3/orgs/members/#publicize-a-users-membership
-func (s *OrganizationsService) PublicizeMembership(org, user string) (*Response, error) {
+func (s *OrganizationsService) PublicizeMembership(ctx context.Context, org, user string) (*Response, error) {
u := fmt.Sprintf("orgs/%v/public_members/%v", org, user)
req, err := s.client.NewRequest("PUT", u, nil)
if err != nil {
return nil, err
}
- return s.client.Do(req, nil)
+ return s.client.Do(ctx, req, nil)
}
// ConcealMembership conceals a user's membership in an organization.
//
// GitHub API docs: https://developer.github.com/v3/orgs/members/#conceal-a-users-membership
-func (s *OrganizationsService) ConcealMembership(org, user string) (*Response, error) {
+func (s *OrganizationsService) ConcealMembership(ctx context.Context, org, user string) (*Response, error) {
u := fmt.Sprintf("orgs/%v/public_members/%v", org, user)
req, err := s.client.NewRequest("DELETE", u, nil)
if err != nil {
return nil, err
}
- return s.client.Do(req, nil)
+ return s.client.Do(ctx, req, nil)
}
// ListOrgMembershipsOptions specifies optional parameters to the
@@ -178,7 +181,7 @@ type ListOrgMembershipsOptions struct {
// ListOrgMemberships lists the organization memberships for the authenticated user.
//
// GitHub API docs: https://developer.github.com/v3/orgs/members/#list-your-organization-memberships
-func (s *OrganizationsService) ListOrgMemberships(opt *ListOrgMembershipsOptions) ([]*Membership, *Response, error) {
+func (s *OrganizationsService) ListOrgMemberships(ctx context.Context, opt *ListOrgMembershipsOptions) ([]*Membership, *Response, error) {
u := "user/memberships/orgs"
u, err := addOptions(u, opt)
if err != nil {
@@ -191,7 +194,7 @@ func (s *OrganizationsService) ListOrgMemberships(opt *ListOrgMembershipsOptions
}
var memberships []*Membership
- resp, err := s.client.Do(req, &memberships)
+ resp, err := s.client.Do(ctx, req, &memberships)
if err != nil {
return nil, resp, err
}
@@ -205,7 +208,7 @@ func (s *OrganizationsService) ListOrgMemberships(opt *ListOrgMembershipsOptions
//
// GitHub API docs: https://developer.github.com/v3/orgs/members/#get-organization-membership
// GitHub API docs: https://developer.github.com/v3/orgs/members/#get-your-organization-membership
-func (s *OrganizationsService) GetOrgMembership(user, org string) (*Membership, *Response, error) {
+func (s *OrganizationsService) GetOrgMembership(ctx context.Context, user, org string) (*Membership, *Response, error) {
var u string
if user != "" {
u = fmt.Sprintf("orgs/%v/memberships/%v", org, user)
@@ -219,7 +222,7 @@ func (s *OrganizationsService) GetOrgMembership(user, org string) (*Membership,
}
membership := new(Membership)
- resp, err := s.client.Do(req, membership)
+ resp, err := s.client.Do(ctx, req, membership)
if err != nil {
return nil, resp, err
}
@@ -233,7 +236,7 @@ func (s *OrganizationsService) GetOrgMembership(user, org string) (*Membership,
//
// GitHub API docs: https://developer.github.com/v3/orgs/members/#add-or-update-organization-membership
// GitHub API docs: https://developer.github.com/v3/orgs/members/#edit-your-organization-membership
-func (s *OrganizationsService) EditOrgMembership(user, org string, membership *Membership) (*Membership, *Response, error) {
+func (s *OrganizationsService) EditOrgMembership(ctx context.Context, user, org string, membership *Membership) (*Membership, *Response, error) {
var u, method string
if user != "" {
u = fmt.Sprintf("orgs/%v/memberships/%v", org, user)
@@ -249,7 +252,7 @@ func (s *OrganizationsService) EditOrgMembership(user, org string, membership *M
}
m := new(Membership)
- resp, err := s.client.Do(req, m)
+ resp, err := s.client.Do(ctx, req, m)
if err != nil {
return nil, resp, err
}
@@ -261,20 +264,20 @@ func (s *OrganizationsService) EditOrgMembership(user, org string, membership *M
// user has been invited to the organization, this will cancel their invitation.
//
// GitHub API docs: https://developer.github.com/v3/orgs/members/#remove-organization-membership
-func (s *OrganizationsService) RemoveOrgMembership(user, org string) (*Response, error) {
+func (s *OrganizationsService) RemoveOrgMembership(ctx context.Context, user, org string) (*Response, error) {
u := fmt.Sprintf("orgs/%v/memberships/%v", org, user)
req, err := s.client.NewRequest("DELETE", u, nil)
if err != nil {
return nil, err
}
- return s.client.Do(req, nil)
+ return s.client.Do(ctx, req, nil)
}
// ListPendingOrgInvitations returns a list of pending invitations.
//
// GitHub API docs: https://developer.github.com/v3/orgs/members/#list-pending-organization-invitations
-func (s *OrganizationsService) ListPendingOrgInvitations(org int, opt *ListOptions) ([]*Invitation, *Response, error) {
+func (s *OrganizationsService) ListPendingOrgInvitations(ctx context.Context, org int, opt *ListOptions) ([]*Invitation, *Response, error) {
u := fmt.Sprintf("orgs/%v/invitations", org)
u, err := addOptions(u, opt)
if err != nil {
@@ -290,7 +293,7 @@ func (s *OrganizationsService) ListPendingOrgInvitations(org int, opt *ListOptio
req.Header.Set("Accept", mediaTypeOrgMembershipPreview)
var pendingInvitations []*Invitation
- resp, err := s.client.Do(req, &pendingInvitations)
+ resp, err := s.client.Do(ctx, req, &pendingInvitations)
if err != nil {
return nil, resp, err
}
diff --git a/github/orgs_members_test.go b/github/orgs_members_test.go
index 8a3ff3df560..ee1d2e68f9b 100644
--- a/github/orgs_members_test.go
+++ b/github/orgs_members_test.go
@@ -6,6 +6,7 @@
package github
import (
+ "context"
"encoding/json"
"fmt"
"net/http"
@@ -34,7 +35,7 @@ func TestOrganizationsService_ListMembers(t *testing.T) {
Role: "admin",
ListOptions: ListOptions{Page: 2},
}
- members, _, err := client.Organizations.ListMembers("o", opt)
+ members, _, err := client.Organizations.ListMembers(context.Background(), "o", opt)
if err != nil {
t.Errorf("Organizations.ListMembers returned error: %v", err)
}
@@ -46,7 +47,7 @@ func TestOrganizationsService_ListMembers(t *testing.T) {
}
func TestOrganizationsService_ListMembers_invalidOrg(t *testing.T) {
- _, _, err := client.Organizations.ListMembers("%", nil)
+ _, _, err := client.Organizations.ListMembers(context.Background(), "%", nil)
testURLParseError(t, err)
}
@@ -60,7 +61,7 @@ func TestOrganizationsService_ListMembers_public(t *testing.T) {
})
opt := &ListMembersOptions{PublicOnly: true}
- members, _, err := client.Organizations.ListMembers("o", opt)
+ members, _, err := client.Organizations.ListMembers(context.Background(), "o", opt)
if err != nil {
t.Errorf("Organizations.ListMembers returned error: %v", err)
}
@@ -80,7 +81,7 @@ func TestOrganizationsService_IsMember(t *testing.T) {
w.WriteHeader(http.StatusNoContent)
})
- member, _, err := client.Organizations.IsMember("o", "u")
+ member, _, err := client.Organizations.IsMember(context.Background(), "o", "u")
if err != nil {
t.Errorf("Organizations.IsMember returned error: %v", err)
}
@@ -99,7 +100,7 @@ func TestOrganizationsService_IsMember_notMember(t *testing.T) {
w.WriteHeader(http.StatusNotFound)
})
- member, _, err := client.Organizations.IsMember("o", "u")
+ member, _, err := client.Organizations.IsMember(context.Background(), "o", "u")
if err != nil {
t.Errorf("Organizations.IsMember returned error: %+v", err)
}
@@ -119,7 +120,7 @@ func TestOrganizationsService_IsMember_error(t *testing.T) {
http.Error(w, "BadRequest", http.StatusBadRequest)
})
- member, _, err := client.Organizations.IsMember("o", "u")
+ member, _, err := client.Organizations.IsMember(context.Background(), "o", "u")
if err == nil {
t.Errorf("Expected HTTP 400 response")
}
@@ -129,7 +130,7 @@ func TestOrganizationsService_IsMember_error(t *testing.T) {
}
func TestOrganizationsService_IsMember_invalidOrg(t *testing.T) {
- _, _, err := client.Organizations.IsMember("%", "u")
+ _, _, err := client.Organizations.IsMember(context.Background(), "%", "u")
testURLParseError(t, err)
}
@@ -142,7 +143,7 @@ func TestOrganizationsService_IsPublicMember(t *testing.T) {
w.WriteHeader(http.StatusNoContent)
})
- member, _, err := client.Organizations.IsPublicMember("o", "u")
+ member, _, err := client.Organizations.IsPublicMember(context.Background(), "o", "u")
if err != nil {
t.Errorf("Organizations.IsPublicMember returned error: %v", err)
}
@@ -161,7 +162,7 @@ func TestOrganizationsService_IsPublicMember_notMember(t *testing.T) {
w.WriteHeader(http.StatusNotFound)
})
- member, _, err := client.Organizations.IsPublicMember("o", "u")
+ member, _, err := client.Organizations.IsPublicMember(context.Background(), "o", "u")
if err != nil {
t.Errorf("Organizations.IsPublicMember returned error: %v", err)
}
@@ -181,7 +182,7 @@ func TestOrganizationsService_IsPublicMember_error(t *testing.T) {
http.Error(w, "BadRequest", http.StatusBadRequest)
})
- member, _, err := client.Organizations.IsPublicMember("o", "u")
+ member, _, err := client.Organizations.IsPublicMember(context.Background(), "o", "u")
if err == nil {
t.Errorf("Expected HTTP 400 response")
}
@@ -191,7 +192,7 @@ func TestOrganizationsService_IsPublicMember_error(t *testing.T) {
}
func TestOrganizationsService_IsPublicMember_invalidOrg(t *testing.T) {
- _, _, err := client.Organizations.IsPublicMember("%", "u")
+ _, _, err := client.Organizations.IsPublicMember(context.Background(), "%", "u")
testURLParseError(t, err)
}
@@ -203,14 +204,14 @@ func TestOrganizationsService_RemoveMember(t *testing.T) {
testMethod(t, r, "DELETE")
})
- _, err := client.Organizations.RemoveMember("o", "u")
+ _, err := client.Organizations.RemoveMember(context.Background(), "o", "u")
if err != nil {
t.Errorf("Organizations.RemoveMember returned error: %v", err)
}
}
func TestOrganizationsService_RemoveMember_invalidOrg(t *testing.T) {
- _, err := client.Organizations.RemoveMember("%", "u")
+ _, err := client.Organizations.RemoveMember(context.Background(), "%", "u")
testURLParseError(t, err)
}
@@ -231,7 +232,7 @@ func TestOrganizationsService_ListOrgMemberships(t *testing.T) {
State: "active",
ListOptions: ListOptions{Page: 2},
}
- memberships, _, err := client.Organizations.ListOrgMemberships(opt)
+ memberships, _, err := client.Organizations.ListOrgMemberships(context.Background(), opt)
if err != nil {
t.Errorf("Organizations.ListOrgMemberships returned error: %v", err)
}
@@ -251,7 +252,7 @@ func TestOrganizationsService_GetOrgMembership_AuthenticatedUser(t *testing.T) {
fmt.Fprint(w, `{"url":"u"}`)
})
- membership, _, err := client.Organizations.GetOrgMembership("", "o")
+ membership, _, err := client.Organizations.GetOrgMembership(context.Background(), "", "o")
if err != nil {
t.Errorf("Organizations.GetOrgMembership returned error: %v", err)
}
@@ -271,7 +272,7 @@ func TestOrganizationsService_GetOrgMembership_SpecifiedUser(t *testing.T) {
fmt.Fprint(w, `{"url":"u"}`)
})
- membership, _, err := client.Organizations.GetOrgMembership("u", "o")
+ membership, _, err := client.Organizations.GetOrgMembership(context.Background(), "u", "o")
if err != nil {
t.Errorf("Organizations.GetOrgMembership returned error: %v", err)
}
@@ -300,7 +301,7 @@ func TestOrganizationsService_EditOrgMembership_AuthenticatedUser(t *testing.T)
fmt.Fprint(w, `{"url":"u"}`)
})
- membership, _, err := client.Organizations.EditOrgMembership("", "o", input)
+ membership, _, err := client.Organizations.EditOrgMembership(context.Background(), "", "o", input)
if err != nil {
t.Errorf("Organizations.EditOrgMembership returned error: %v", err)
}
@@ -329,7 +330,7 @@ func TestOrganizationsService_EditOrgMembership_SpecifiedUser(t *testing.T) {
fmt.Fprint(w, `{"url":"u"}`)
})
- membership, _, err := client.Organizations.EditOrgMembership("u", "o", input)
+ membership, _, err := client.Organizations.EditOrgMembership(context.Background(), "u", "o", input)
if err != nil {
t.Errorf("Organizations.EditOrgMembership returned error: %v", err)
}
@@ -349,7 +350,7 @@ func TestOrganizationsService_RemoveOrgMembership(t *testing.T) {
w.WriteHeader(http.StatusNoContent)
})
- _, err := client.Organizations.RemoveOrgMembership("u", "o")
+ _, err := client.Organizations.RemoveOrgMembership(context.Background(), "u", "o")
if err != nil {
t.Errorf("Organizations.RemoveOrgMembership returned error: %v", err)
}
@@ -394,7 +395,7 @@ func TestOrganizationsService_ListPendingOrgInvitations(t *testing.T) {
})
opt := &ListOptions{Page: 1}
- invitations, _, err := client.Organizations.ListPendingOrgInvitations(1, opt)
+ invitations, _, err := client.Organizations.ListPendingOrgInvitations(context.Background(), 1, opt)
if err != nil {
t.Errorf("Organizations.ListPendingOrgInvitations returned error: %v", err)
}
diff --git a/github/orgs_teams.go b/github/orgs_teams.go
index c1818e523ff..5bdd66dd215 100644
--- a/github/orgs_teams.go
+++ b/github/orgs_teams.go
@@ -6,6 +6,7 @@
package github
import (
+ "context"
"fmt"
"time"
)
@@ -62,7 +63,7 @@ func (i Invitation) String() string {
// ListTeams lists all of the teams for an organization.
//
// GitHub API docs: https://developer.github.com/v3/orgs/teams/#list-teams
-func (s *OrganizationsService) ListTeams(org string, opt *ListOptions) ([]*Team, *Response, error) {
+func (s *OrganizationsService) ListTeams(ctx context.Context, org string, opt *ListOptions) ([]*Team, *Response, error) {
u := fmt.Sprintf("orgs/%v/teams", org)
u, err := addOptions(u, opt)
if err != nil {
@@ -75,7 +76,7 @@ func (s *OrganizationsService) ListTeams(org string, opt *ListOptions) ([]*Team,
}
var teams []*Team
- resp, err := s.client.Do(req, &teams)
+ resp, err := s.client.Do(ctx, req, &teams)
if err != nil {
return nil, resp, err
}
@@ -86,7 +87,7 @@ func (s *OrganizationsService) ListTeams(org string, opt *ListOptions) ([]*Team,
// GetTeam fetches a team by ID.
//
// GitHub API docs: https://developer.github.com/v3/orgs/teams/#get-team
-func (s *OrganizationsService) GetTeam(team int) (*Team, *Response, error) {
+func (s *OrganizationsService) GetTeam(ctx context.Context, team int) (*Team, *Response, error) {
u := fmt.Sprintf("teams/%v", team)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
@@ -94,7 +95,7 @@ func (s *OrganizationsService) GetTeam(team int) (*Team, *Response, error) {
}
t := new(Team)
- resp, err := s.client.Do(req, t)
+ resp, err := s.client.Do(ctx, req, t)
if err != nil {
return nil, resp, err
}
@@ -105,7 +106,7 @@ func (s *OrganizationsService) GetTeam(team int) (*Team, *Response, error) {
// CreateTeam creates a new team within an organization.
//
// GitHub API docs: https://developer.github.com/v3/orgs/teams/#create-team
-func (s *OrganizationsService) CreateTeam(org string, team *Team) (*Team, *Response, error) {
+func (s *OrganizationsService) CreateTeam(ctx context.Context, org string, team *Team) (*Team, *Response, error) {
u := fmt.Sprintf("orgs/%v/teams", org)
req, err := s.client.NewRequest("POST", u, team)
if err != nil {
@@ -113,7 +114,7 @@ func (s *OrganizationsService) CreateTeam(org string, team *Team) (*Team, *Respo
}
t := new(Team)
- resp, err := s.client.Do(req, t)
+ resp, err := s.client.Do(ctx, req, t)
if err != nil {
return nil, resp, err
}
@@ -124,7 +125,7 @@ func (s *OrganizationsService) CreateTeam(org string, team *Team) (*Team, *Respo
// EditTeam edits a team.
//
// GitHub API docs: https://developer.github.com/v3/orgs/teams/#edit-team
-func (s *OrganizationsService) EditTeam(id int, team *Team) (*Team, *Response, error) {
+func (s *OrganizationsService) EditTeam(ctx context.Context, id int, team *Team) (*Team, *Response, error) {
u := fmt.Sprintf("teams/%v", id)
req, err := s.client.NewRequest("PATCH", u, team)
if err != nil {
@@ -132,7 +133,7 @@ func (s *OrganizationsService) EditTeam(id int, team *Team) (*Team, *Response, e
}
t := new(Team)
- resp, err := s.client.Do(req, t)
+ resp, err := s.client.Do(ctx, req, t)
if err != nil {
return nil, resp, err
}
@@ -143,14 +144,14 @@ func (s *OrganizationsService) EditTeam(id int, team *Team) (*Team, *Response, e
// DeleteTeam deletes a team.
//
// GitHub API docs: https://developer.github.com/v3/orgs/teams/#delete-team
-func (s *OrganizationsService) DeleteTeam(team int) (*Response, error) {
+func (s *OrganizationsService) DeleteTeam(ctx context.Context, team int) (*Response, error) {
u := fmt.Sprintf("teams/%v", team)
req, err := s.client.NewRequest("DELETE", u, nil)
if err != nil {
return nil, err
}
- return s.client.Do(req, nil)
+ return s.client.Do(ctx, req, nil)
}
// OrganizationListTeamMembersOptions specifies the optional parameters to the
@@ -167,7 +168,7 @@ type OrganizationListTeamMembersOptions struct {
// team.
//
// GitHub API docs: https://developer.github.com/v3/orgs/teams/#list-team-members
-func (s *OrganizationsService) ListTeamMembers(team int, opt *OrganizationListTeamMembersOptions) ([]*User, *Response, error) {
+func (s *OrganizationsService) ListTeamMembers(ctx context.Context, team int, opt *OrganizationListTeamMembersOptions) ([]*User, *Response, error) {
u := fmt.Sprintf("teams/%v/members", team)
u, err := addOptions(u, opt)
if err != nil {
@@ -180,7 +181,7 @@ func (s *OrganizationsService) ListTeamMembers(team int, opt *OrganizationListTe
}
var members []*User
- resp, err := s.client.Do(req, &members)
+ resp, err := s.client.Do(ctx, req, &members)
if err != nil {
return nil, resp, err
}
@@ -191,14 +192,14 @@ func (s *OrganizationsService) ListTeamMembers(team int, opt *OrganizationListTe
// IsTeamMember checks if a user is a member of the specified team.
//
// GitHub API docs: https://developer.github.com/v3/orgs/teams/#get-team-member
-func (s *OrganizationsService) IsTeamMember(team int, user string) (bool, *Response, error) {
+func (s *OrganizationsService) IsTeamMember(ctx context.Context, team int, user string) (bool, *Response, error) {
u := fmt.Sprintf("teams/%v/members/%v", team, user)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return false, nil, err
}
- resp, err := s.client.Do(req, nil)
+ resp, err := s.client.Do(ctx, req, nil)
member, err := parseBoolResponse(err)
return member, resp, err
}
@@ -206,7 +207,7 @@ func (s *OrganizationsService) IsTeamMember(team int, user string) (bool, *Respo
// ListTeamRepos lists the repositories that the specified team has access to.
//
// GitHub API docs: https://developer.github.com/v3/orgs/teams/#list-team-repos
-func (s *OrganizationsService) ListTeamRepos(team int, opt *ListOptions) ([]*Repository, *Response, error) {
+func (s *OrganizationsService) ListTeamRepos(ctx context.Context, team int, opt *ListOptions) ([]*Repository, *Response, error) {
u := fmt.Sprintf("teams/%v/repos", team)
u, err := addOptions(u, opt)
if err != nil {
@@ -219,7 +220,7 @@ func (s *OrganizationsService) ListTeamRepos(team int, opt *ListOptions) ([]*Rep
}
var repos []*Repository
- resp, err := s.client.Do(req, &repos)
+ resp, err := s.client.Do(ctx, req, &repos)
if err != nil {
return nil, resp, err
}
@@ -232,7 +233,7 @@ func (s *OrganizationsService) ListTeamRepos(team int, opt *ListOptions) ([]*Rep
// permissions team has for that repo.
//
// GitHub API docs: https://developer.github.com/v3/orgs/teams/#check-if-a-team-manages-a-repository
-func (s *OrganizationsService) IsTeamRepo(team int, owner string, repo string) (*Repository, *Response, error) {
+func (s *OrganizationsService) IsTeamRepo(ctx context.Context, team int, owner string, repo string) (*Repository, *Response, error) {
u := fmt.Sprintf("teams/%v/repos/%v/%v", team, owner, repo)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
@@ -242,7 +243,7 @@ func (s *OrganizationsService) IsTeamRepo(team int, owner string, repo string) (
req.Header.Set("Accept", mediaTypeOrgPermissionRepo)
repository := new(Repository)
- resp, err := s.client.Do(req, repository)
+ resp, err := s.client.Do(ctx, req, repository)
if err != nil {
return nil, resp, err
}
@@ -268,14 +269,14 @@ type OrganizationAddTeamRepoOptions struct {
// belongs, or a direct fork of a repository owned by the organization.
//
// GitHub API docs: https://developer.github.com/v3/orgs/teams/#add-team-repo
-func (s *OrganizationsService) AddTeamRepo(team int, owner string, repo string, opt *OrganizationAddTeamRepoOptions) (*Response, error) {
+func (s *OrganizationsService) AddTeamRepo(ctx context.Context, team int, owner string, repo string, opt *OrganizationAddTeamRepoOptions) (*Response, error) {
u := fmt.Sprintf("teams/%v/repos/%v/%v", team, owner, repo)
req, err := s.client.NewRequest("PUT", u, opt)
if err != nil {
return nil, err
}
- return s.client.Do(req, nil)
+ return s.client.Do(ctx, req, nil)
}
// RemoveTeamRepo removes a repository from being managed by the specified
@@ -283,19 +284,19 @@ func (s *OrganizationsService) AddTeamRepo(team int, owner string, repo string,
// from the team.
//
// GitHub API docs: https://developer.github.com/v3/orgs/teams/#remove-team-repo
-func (s *OrganizationsService) RemoveTeamRepo(team int, owner string, repo string) (*Response, error) {
+func (s *OrganizationsService) RemoveTeamRepo(ctx context.Context, team int, owner string, repo string) (*Response, error) {
u := fmt.Sprintf("teams/%v/repos/%v/%v", team, owner, repo)
req, err := s.client.NewRequest("DELETE", u, nil)
if err != nil {
return nil, err
}
- return s.client.Do(req, nil)
+ return s.client.Do(ctx, req, nil)
}
// ListUserTeams lists a user's teams
// GitHub API docs: https://developer.github.com/v3/orgs/teams/#list-user-teams
-func (s *OrganizationsService) ListUserTeams(opt *ListOptions) ([]*Team, *Response, error) {
+func (s *OrganizationsService) ListUserTeams(ctx context.Context, opt *ListOptions) ([]*Team, *Response, error) {
u := "user/teams"
u, err := addOptions(u, opt)
if err != nil {
@@ -308,7 +309,7 @@ func (s *OrganizationsService) ListUserTeams(opt *ListOptions) ([]*Team, *Respon
}
var teams []*Team
- resp, err := s.client.Do(req, &teams)
+ resp, err := s.client.Do(ctx, req, &teams)
if err != nil {
return nil, resp, err
}
@@ -319,7 +320,7 @@ func (s *OrganizationsService) ListUserTeams(opt *ListOptions) ([]*Team, *Respon
// GetTeamMembership returns the membership status for a user in a team.
//
// GitHub API docs: https://developer.github.com/v3/orgs/teams/#get-team-membership
-func (s *OrganizationsService) GetTeamMembership(team int, user string) (*Membership, *Response, error) {
+func (s *OrganizationsService) GetTeamMembership(ctx context.Context, team int, user string) (*Membership, *Response, error) {
u := fmt.Sprintf("teams/%v/memberships/%v", team, user)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
@@ -327,7 +328,7 @@ func (s *OrganizationsService) GetTeamMembership(team int, user string) (*Member
}
t := new(Membership)
- resp, err := s.client.Do(req, t)
+ resp, err := s.client.Do(ctx, req, t)
if err != nil {
return nil, resp, err
}
@@ -367,7 +368,7 @@ type OrganizationAddTeamMembershipOptions struct {
// added as a member of the team.
//
// GitHub API docs: https://developer.github.com/v3/orgs/teams/#add-team-membership
-func (s *OrganizationsService) AddTeamMembership(team int, user string, opt *OrganizationAddTeamMembershipOptions) (*Membership, *Response, error) {
+func (s *OrganizationsService) AddTeamMembership(ctx context.Context, team int, user string, opt *OrganizationAddTeamMembershipOptions) (*Membership, *Response, error) {
u := fmt.Sprintf("teams/%v/memberships/%v", team, user)
req, err := s.client.NewRequest("PUT", u, opt)
if err != nil {
@@ -375,7 +376,7 @@ func (s *OrganizationsService) AddTeamMembership(team int, user string, opt *Org
}
t := new(Membership)
- resp, err := s.client.Do(req, t)
+ resp, err := s.client.Do(ctx, req, t)
if err != nil {
return nil, resp, err
}
@@ -386,14 +387,14 @@ func (s *OrganizationsService) AddTeamMembership(team int, user string, opt *Org
// RemoveTeamMembership removes a user from a team.
//
// GitHub API docs: https://developer.github.com/v3/orgs/teams/#remove-team-membership
-func (s *OrganizationsService) RemoveTeamMembership(team int, user string) (*Response, error) {
+func (s *OrganizationsService) RemoveTeamMembership(ctx context.Context, team int, user string) (*Response, error) {
u := fmt.Sprintf("teams/%v/memberships/%v", team, user)
req, err := s.client.NewRequest("DELETE", u, nil)
if err != nil {
return nil, err
}
- return s.client.Do(req, nil)
+ return s.client.Do(ctx, req, nil)
}
// ListPendingTeamInvitations get pending invitaion list in team.
@@ -401,7 +402,7 @@ func (s *OrganizationsService) RemoveTeamMembership(team int, user string) (*Res
// Preview features are not supported for production use.
//
// GitHub API docs: https://developer.github.com/v3/orgs/teams/#list-pending-team-invitations
-func (s *OrganizationsService) ListPendingTeamInvitations(team int, opt *ListOptions) ([]*Invitation, *Response, error) {
+func (s *OrganizationsService) ListPendingTeamInvitations(ctx context.Context, team int, opt *ListOptions) ([]*Invitation, *Response, error) {
u := fmt.Sprintf("teams/%v/invitations", team)
u, err := addOptions(u, opt)
if err != nil {
@@ -417,7 +418,7 @@ func (s *OrganizationsService) ListPendingTeamInvitations(team int, opt *ListOpt
req.Header.Set("Accept", mediaTypeOrgMembershipPreview)
var pendingInvitations []*Invitation
- resp, err := s.client.Do(req, &pendingInvitations)
+ resp, err := s.client.Do(ctx, req, &pendingInvitations)
if err != nil {
return nil, resp, err
}
diff --git a/github/orgs_teams_test.go b/github/orgs_teams_test.go
index 3e8cd30980f..1a95973d5b9 100644
--- a/github/orgs_teams_test.go
+++ b/github/orgs_teams_test.go
@@ -6,6 +6,7 @@
package github
import (
+ "context"
"encoding/json"
"fmt"
"net/http"
@@ -25,7 +26,7 @@ func TestOrganizationsService_ListTeams(t *testing.T) {
})
opt := &ListOptions{Page: 2}
- teams, _, err := client.Organizations.ListTeams("o", opt)
+ teams, _, err := client.Organizations.ListTeams(context.Background(), "o", opt)
if err != nil {
t.Errorf("Organizations.ListTeams returned error: %v", err)
}
@@ -37,7 +38,7 @@ func TestOrganizationsService_ListTeams(t *testing.T) {
}
func TestOrganizationsService_ListTeams_invalidOrg(t *testing.T) {
- _, _, err := client.Organizations.ListTeams("%", nil)
+ _, _, err := client.Organizations.ListTeams(context.Background(), "%", nil)
testURLParseError(t, err)
}
@@ -50,7 +51,7 @@ func TestOrganizationsService_GetTeam(t *testing.T) {
fmt.Fprint(w, `{"id":1, "name":"n", "description": "d", "url":"u", "slug": "s", "permission":"p"}`)
})
- team, _, err := client.Organizations.GetTeam(1)
+ team, _, err := client.Organizations.GetTeam(context.Background(), 1)
if err != nil {
t.Errorf("Organizations.GetTeam returned error: %v", err)
}
@@ -79,7 +80,7 @@ func TestOrganizationsService_CreateTeam(t *testing.T) {
fmt.Fprint(w, `{"id":1}`)
})
- team, _, err := client.Organizations.CreateTeam("o", input)
+ team, _, err := client.Organizations.CreateTeam(context.Background(), "o", input)
if err != nil {
t.Errorf("Organizations.CreateTeam returned error: %v", err)
}
@@ -91,7 +92,7 @@ func TestOrganizationsService_CreateTeam(t *testing.T) {
}
func TestOrganizationsService_CreateTeam_invalidOrg(t *testing.T) {
- _, _, err := client.Organizations.CreateTeam("%", nil)
+ _, _, err := client.Organizations.CreateTeam(context.Background(), "%", nil)
testURLParseError(t, err)
}
@@ -113,7 +114,7 @@ func TestOrganizationsService_EditTeam(t *testing.T) {
fmt.Fprint(w, `{"id":1}`)
})
- team, _, err := client.Organizations.EditTeam(1, input)
+ team, _, err := client.Organizations.EditTeam(context.Background(), 1, input)
if err != nil {
t.Errorf("Organizations.EditTeam returned error: %v", err)
}
@@ -132,7 +133,7 @@ func TestOrganizationsService_DeleteTeam(t *testing.T) {
testMethod(t, r, "DELETE")
})
- _, err := client.Organizations.DeleteTeam(1)
+ _, err := client.Organizations.DeleteTeam(context.Background(), 1)
if err != nil {
t.Errorf("Organizations.DeleteTeam returned error: %v", err)
}
@@ -149,7 +150,7 @@ func TestOrganizationsService_ListTeamMembers(t *testing.T) {
})
opt := &OrganizationListTeamMembersOptions{Role: "member", ListOptions: ListOptions{Page: 2}}
- members, _, err := client.Organizations.ListTeamMembers(1, opt)
+ members, _, err := client.Organizations.ListTeamMembers(context.Background(), 1, opt)
if err != nil {
t.Errorf("Organizations.ListTeamMembers returned error: %v", err)
}
@@ -168,7 +169,7 @@ func TestOrganizationsService_IsTeamMember_true(t *testing.T) {
testMethod(t, r, "GET")
})
- member, _, err := client.Organizations.IsTeamMember(1, "u")
+ member, _, err := client.Organizations.IsTeamMember(context.Background(), 1, "u")
if err != nil {
t.Errorf("Organizations.IsTeamMember returned error: %v", err)
}
@@ -187,7 +188,7 @@ func TestOrganizationsService_IsTeamMember_false(t *testing.T) {
w.WriteHeader(http.StatusNotFound)
})
- member, _, err := client.Organizations.IsTeamMember(1, "u")
+ member, _, err := client.Organizations.IsTeamMember(context.Background(), 1, "u")
if err != nil {
t.Errorf("Organizations.IsTeamMember returned error: %+v", err)
}
@@ -207,7 +208,7 @@ func TestOrganizationsService_IsTeamMember_error(t *testing.T) {
http.Error(w, "BadRequest", http.StatusBadRequest)
})
- member, _, err := client.Organizations.IsTeamMember(1, "u")
+ member, _, err := client.Organizations.IsTeamMember(context.Background(), 1, "u")
if err == nil {
t.Errorf("Expected HTTP 400 response")
}
@@ -217,7 +218,7 @@ func TestOrganizationsService_IsTeamMember_error(t *testing.T) {
}
func TestOrganizationsService_IsTeamMember_invalidUser(t *testing.T) {
- _, _, err := client.Organizations.IsTeamMember(1, "%")
+ _, _, err := client.Organizations.IsTeamMember(context.Background(), 1, "%")
testURLParseError(t, err)
}
@@ -230,14 +231,14 @@ func TestOrganizationsService_PublicizeMembership(t *testing.T) {
w.WriteHeader(http.StatusNoContent)
})
- _, err := client.Organizations.PublicizeMembership("o", "u")
+ _, err := client.Organizations.PublicizeMembership(context.Background(), "o", "u")
if err != nil {
t.Errorf("Organizations.PublicizeMembership returned error: %v", err)
}
}
func TestOrganizationsService_PublicizeMembership_invalidOrg(t *testing.T) {
- _, err := client.Organizations.PublicizeMembership("%", "u")
+ _, err := client.Organizations.PublicizeMembership(context.Background(), "%", "u")
testURLParseError(t, err)
}
@@ -250,14 +251,14 @@ func TestOrganizationsService_ConcealMembership(t *testing.T) {
w.WriteHeader(http.StatusNoContent)
})
- _, err := client.Organizations.ConcealMembership("o", "u")
+ _, err := client.Organizations.ConcealMembership(context.Background(), "o", "u")
if err != nil {
t.Errorf("Organizations.ConcealMembership returned error: %v", err)
}
}
func TestOrganizationsService_ConcealMembership_invalidOrg(t *testing.T) {
- _, err := client.Organizations.ConcealMembership("%", "u")
+ _, err := client.Organizations.ConcealMembership(context.Background(), "%", "u")
testURLParseError(t, err)
}
@@ -272,7 +273,7 @@ func TestOrganizationsService_ListTeamRepos(t *testing.T) {
})
opt := &ListOptions{Page: 2}
- members, _, err := client.Organizations.ListTeamRepos(1, opt)
+ members, _, err := client.Organizations.ListTeamRepos(context.Background(), 1, opt)
if err != nil {
t.Errorf("Organizations.ListTeamRepos returned error: %v", err)
}
@@ -293,7 +294,7 @@ func TestOrganizationsService_IsTeamRepo_true(t *testing.T) {
fmt.Fprint(w, `{"id":1}`)
})
- repo, _, err := client.Organizations.IsTeamRepo(1, "o", "r")
+ repo, _, err := client.Organizations.IsTeamRepo(context.Background(), 1, "o", "r")
if err != nil {
t.Errorf("Organizations.IsTeamRepo returned error: %v", err)
}
@@ -313,7 +314,7 @@ func TestOrganizationsService_IsTeamRepo_false(t *testing.T) {
w.WriteHeader(http.StatusNotFound)
})
- repo, resp, err := client.Organizations.IsTeamRepo(1, "o", "r")
+ repo, resp, err := client.Organizations.IsTeamRepo(context.Background(), 1, "o", "r")
if err == nil {
t.Errorf("Expected HTTP 404 response")
}
@@ -334,7 +335,7 @@ func TestOrganizationsService_IsTeamRepo_error(t *testing.T) {
http.Error(w, "BadRequest", http.StatusBadRequest)
})
- repo, resp, err := client.Organizations.IsTeamRepo(1, "o", "r")
+ repo, resp, err := client.Organizations.IsTeamRepo(context.Background(), 1, "o", "r")
if err == nil {
t.Errorf("Expected HTTP 400 response")
}
@@ -347,7 +348,7 @@ func TestOrganizationsService_IsTeamRepo_error(t *testing.T) {
}
func TestOrganizationsService_IsTeamRepo_invalidOwner(t *testing.T) {
- _, _, err := client.Organizations.IsTeamRepo(1, "%", "r")
+ _, _, err := client.Organizations.IsTeamRepo(context.Background(), 1, "%", "r")
testURLParseError(t, err)
}
@@ -369,7 +370,7 @@ func TestOrganizationsService_AddTeamRepo(t *testing.T) {
w.WriteHeader(http.StatusNoContent)
})
- _, err := client.Organizations.AddTeamRepo(1, "o", "r", opt)
+ _, err := client.Organizations.AddTeamRepo(context.Background(), 1, "o", "r", opt)
if err != nil {
t.Errorf("Organizations.AddTeamRepo returned error: %v", err)
}
@@ -384,14 +385,14 @@ func TestOrganizationsService_AddTeamRepo_noAccess(t *testing.T) {
w.WriteHeader(http.StatusUnprocessableEntity)
})
- _, err := client.Organizations.AddTeamRepo(1, "o", "r", nil)
+ _, err := client.Organizations.AddTeamRepo(context.Background(), 1, "o", "r", nil)
if err == nil {
t.Errorf("Expcted error to be returned")
}
}
func TestOrganizationsService_AddTeamRepo_invalidOwner(t *testing.T) {
- _, err := client.Organizations.AddTeamRepo(1, "%", "r", nil)
+ _, err := client.Organizations.AddTeamRepo(context.Background(), 1, "%", "r", nil)
testURLParseError(t, err)
}
@@ -404,14 +405,14 @@ func TestOrganizationsService_RemoveTeamRepo(t *testing.T) {
w.WriteHeader(http.StatusNoContent)
})
- _, err := client.Organizations.RemoveTeamRepo(1, "o", "r")
+ _, err := client.Organizations.RemoveTeamRepo(context.Background(), 1, "o", "r")
if err != nil {
t.Errorf("Organizations.RemoveTeamRepo returned error: %v", err)
}
}
func TestOrganizationsService_RemoveTeamRepo_invalidOwner(t *testing.T) {
- _, err := client.Organizations.RemoveTeamRepo(1, "%", "r")
+ _, err := client.Organizations.RemoveTeamRepo(context.Background(), 1, "%", "r")
testURLParseError(t, err)
}
@@ -424,7 +425,7 @@ func TestOrganizationsService_GetTeamMembership(t *testing.T) {
fmt.Fprint(w, `{"url":"u", "state":"active"}`)
})
- membership, _, err := client.Organizations.GetTeamMembership(1, "u")
+ membership, _, err := client.Organizations.GetTeamMembership(context.Background(), 1, "u")
if err != nil {
t.Errorf("Organizations.GetTeamMembership returned error: %v", err)
}
@@ -453,7 +454,7 @@ func TestOrganizationsService_AddTeamMembership(t *testing.T) {
fmt.Fprint(w, `{"url":"u", "state":"pending"}`)
})
- membership, _, err := client.Organizations.AddTeamMembership(1, "u", opt)
+ membership, _, err := client.Organizations.AddTeamMembership(context.Background(), 1, "u", opt)
if err != nil {
t.Errorf("Organizations.AddTeamMembership returned error: %v", err)
}
@@ -473,7 +474,7 @@ func TestOrganizationsService_RemoveTeamMembership(t *testing.T) {
w.WriteHeader(http.StatusNoContent)
})
- _, err := client.Organizations.RemoveTeamMembership(1, "u")
+ _, err := client.Organizations.RemoveTeamMembership(context.Background(), 1, "u")
if err != nil {
t.Errorf("Organizations.RemoveTeamMembership returned error: %v", err)
}
@@ -490,7 +491,7 @@ func TestOrganizationsService_ListUserTeams(t *testing.T) {
})
opt := &ListOptions{Page: 1}
- teams, _, err := client.Organizations.ListUserTeams(opt)
+ teams, _, err := client.Organizations.ListUserTeams(context.Background(), opt)
if err != nil {
t.Errorf("Organizations.ListUserTeams returned error: %v", err)
}
@@ -540,7 +541,7 @@ func TestOrganizationsService_ListPendingTeamInvitations(t *testing.T) {
})
opt := &ListOptions{Page: 1}
- invitations, _, err := client.Organizations.ListPendingTeamInvitations(1, opt)
+ invitations, _, err := client.Organizations.ListPendingTeamInvitations(context.Background(), 1, opt)
if err != nil {
t.Errorf("Organizations.ListPendingTeamInvitations returned error: %v", err)
}
diff --git a/github/orgs_test.go b/github/orgs_test.go
index 8e02619de0f..f80c9496a80 100644
--- a/github/orgs_test.go
+++ b/github/orgs_test.go
@@ -6,6 +6,7 @@
package github
import (
+ "context"
"encoding/json"
"fmt"
"net/http"
@@ -25,7 +26,7 @@ func TestOrganizationsService_ListAll(t *testing.T) {
})
opt := &OrganizationsListOptions{Since: since}
- orgs, _, err := client.Organizations.ListAll(opt)
+ orgs, _, err := client.Organizations.ListAll(context.Background(), opt)
if err != nil {
t.Errorf("Organizations.ListAll returned error: %v", err)
}
@@ -45,7 +46,7 @@ func TestOrganizationsService_List_authenticatedUser(t *testing.T) {
fmt.Fprint(w, `[{"id":1},{"id":2}]`)
})
- orgs, _, err := client.Organizations.List("", nil)
+ orgs, _, err := client.Organizations.List(context.Background(), "", nil)
if err != nil {
t.Errorf("Organizations.List returned error: %v", err)
}
@@ -67,7 +68,7 @@ func TestOrganizationsService_List_specifiedUser(t *testing.T) {
})
opt := &ListOptions{Page: 2}
- orgs, _, err := client.Organizations.List("u", opt)
+ orgs, _, err := client.Organizations.List(context.Background(), "u", opt)
if err != nil {
t.Errorf("Organizations.List returned error: %v", err)
}
@@ -79,7 +80,7 @@ func TestOrganizationsService_List_specifiedUser(t *testing.T) {
}
func TestOrganizationsService_List_invalidUser(t *testing.T) {
- _, _, err := client.Organizations.List("%", nil)
+ _, _, err := client.Organizations.List(context.Background(), "%", nil)
testURLParseError(t, err)
}
@@ -92,7 +93,7 @@ func TestOrganizationsService_Get(t *testing.T) {
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(context.Background(), "o")
if err != nil {
t.Errorf("Organizations.Get returned error: %v", err)
}
@@ -104,7 +105,7 @@ func TestOrganizationsService_Get(t *testing.T) {
}
func TestOrganizationsService_Get_invalidOrg(t *testing.T) {
- _, _, err := client.Organizations.Get("%")
+ _, _, err := client.Organizations.Get(context.Background(), "%")
testURLParseError(t, err)
}
@@ -126,7 +127,7 @@ func TestOrganizationsService_Edit(t *testing.T) {
fmt.Fprint(w, `{"id":1}`)
})
- org, _, err := client.Organizations.Edit("o", input)
+ org, _, err := client.Organizations.Edit(context.Background(), "o", input)
if err != nil {
t.Errorf("Organizations.Edit returned error: %v", err)
}
@@ -138,6 +139,6 @@ func TestOrganizationsService_Edit(t *testing.T) {
}
func TestOrganizationsService_Edit_invalidOrg(t *testing.T) {
- _, _, err := client.Organizations.Edit("%", nil)
+ _, _, err := client.Organizations.Edit(context.Background(), "%", nil)
testURLParseError(t, err)
}
diff --git a/github/projects.go b/github/projects.go
index 766f0028019..58b638eb8c6 100644
--- a/github/projects.go
+++ b/github/projects.go
@@ -5,7 +5,10 @@
package github
-import "fmt"
+import (
+ "context"
+ "fmt"
+)
// ProjectsService provides access to the projects functions in the
// GitHub API.
@@ -35,7 +38,7 @@ func (p Project) String() string {
// GetProject gets a GitHub Project for a repo.
//
// GitHub API docs: https://developer.github.com/v3/projects/#get-a-project
-func (s *ProjectsService) GetProject(id int) (*Project, *Response, error) {
+func (s *ProjectsService) GetProject(ctx context.Context, id int) (*Project, *Response, error) {
u := fmt.Sprintf("projects/%v", id)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
@@ -46,7 +49,7 @@ func (s *ProjectsService) GetProject(id int) (*Project, *Response, error) {
req.Header.Set("Accept", mediaTypeProjectsPreview)
project := &Project{}
- resp, err := s.client.Do(req, project)
+ resp, err := s.client.Do(ctx, req, project)
if err != nil {
return nil, resp, err
}
@@ -67,7 +70,7 @@ type ProjectOptions struct {
// UpdateProject updates a repository project.
//
// GitHub API docs: https://developer.github.com/v3/projects/#update-a-project
-func (s *ProjectsService) UpdateProject(id int, opt *ProjectOptions) (*Project, *Response, error) {
+func (s *ProjectsService) UpdateProject(ctx context.Context, id int, opt *ProjectOptions) (*Project, *Response, error) {
u := fmt.Sprintf("projects/%v", id)
req, err := s.client.NewRequest("PATCH", u, opt)
if err != nil {
@@ -78,7 +81,7 @@ func (s *ProjectsService) UpdateProject(id int, opt *ProjectOptions) (*Project,
req.Header.Set("Accept", mediaTypeProjectsPreview)
project := &Project{}
- resp, err := s.client.Do(req, project)
+ resp, err := s.client.Do(ctx, req, project)
if err != nil {
return nil, resp, err
}
@@ -89,7 +92,7 @@ func (s *ProjectsService) UpdateProject(id int, opt *ProjectOptions) (*Project,
// DeleteProject deletes a GitHub Project from a repository.
//
// GitHub API docs: https://developer.github.com/v3/projects/#delete-a-project
-func (s *ProjectsService) DeleteProject(id int) (*Response, error) {
+func (s *ProjectsService) DeleteProject(ctx context.Context, id int) (*Response, error) {
u := fmt.Sprintf("projects/%v", id)
req, err := s.client.NewRequest("DELETE", u, nil)
if err != nil {
@@ -99,7 +102,7 @@ func (s *ProjectsService) DeleteProject(id int) (*Response, error) {
// TODO: remove custom Accept header when this API fully launches.
req.Header.Set("Accept", mediaTypeProjectsPreview)
- return s.client.Do(req, nil)
+ return s.client.Do(ctx, req, nil)
}
// ProjectColumn represents a column of a GitHub Project.
@@ -116,7 +119,7 @@ type ProjectColumn struct {
// ListProjectColumns lists the columns of a GitHub Project for a repo.
//
// GitHub API docs: https://developer.github.com/v3/projects/columns/#list-project-columns
-func (s *ProjectsService) ListProjectColumns(projectID int, opt *ListOptions) ([]*ProjectColumn, *Response, error) {
+func (s *ProjectsService) ListProjectColumns(ctx context.Context, projectID int, opt *ListOptions) ([]*ProjectColumn, *Response, error) {
u := fmt.Sprintf("projects/%v/columns", projectID)
u, err := addOptions(u, opt)
if err != nil {
@@ -132,7 +135,7 @@ func (s *ProjectsService) ListProjectColumns(projectID int, opt *ListOptions) ([
req.Header.Set("Accept", mediaTypeProjectsPreview)
columns := []*ProjectColumn{}
- resp, err := s.client.Do(req, &columns)
+ resp, err := s.client.Do(ctx, req, &columns)
if err != nil {
return nil, resp, err
}
@@ -143,7 +146,7 @@ func (s *ProjectsService) ListProjectColumns(projectID int, opt *ListOptions) ([
// GetProjectColumn gets a column of a GitHub Project for a repo.
//
// GitHub API docs: https://developer.github.com/v3/projects/columns/#get-a-project-column
-func (s *ProjectsService) GetProjectColumn(id int) (*ProjectColumn, *Response, error) {
+func (s *ProjectsService) GetProjectColumn(ctx context.Context, id int) (*ProjectColumn, *Response, error) {
u := fmt.Sprintf("projects/columns/%v", id)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
@@ -154,7 +157,7 @@ func (s *ProjectsService) GetProjectColumn(id int) (*ProjectColumn, *Response, e
req.Header.Set("Accept", mediaTypeProjectsPreview)
column := &ProjectColumn{}
- resp, err := s.client.Do(req, column)
+ resp, err := s.client.Do(ctx, req, column)
if err != nil {
return nil, resp, err
}
@@ -173,7 +176,7 @@ type ProjectColumnOptions struct {
// CreateProjectColumn creates a column for the specified (by number) project.
//
// GitHub API docs: https://developer.github.com/v3/projects/columns/#create-a-project-column
-func (s *ProjectsService) CreateProjectColumn(projectID int, opt *ProjectColumnOptions) (*ProjectColumn, *Response, error) {
+func (s *ProjectsService) CreateProjectColumn(ctx context.Context, projectID int, opt *ProjectColumnOptions) (*ProjectColumn, *Response, error) {
u := fmt.Sprintf("projects/%v/columns", projectID)
req, err := s.client.NewRequest("POST", u, opt)
if err != nil {
@@ -184,7 +187,7 @@ func (s *ProjectsService) CreateProjectColumn(projectID int, opt *ProjectColumnO
req.Header.Set("Accept", mediaTypeProjectsPreview)
column := &ProjectColumn{}
- resp, err := s.client.Do(req, column)
+ resp, err := s.client.Do(ctx, req, column)
if err != nil {
return nil, resp, err
}
@@ -195,7 +198,7 @@ func (s *ProjectsService) CreateProjectColumn(projectID int, opt *ProjectColumnO
// UpdateProjectColumn updates a column of a GitHub Project.
//
// GitHub API docs: https://developer.github.com/v3/projects/columns/#update-a-project-column
-func (s *ProjectsService) UpdateProjectColumn(columnID int, opt *ProjectColumnOptions) (*ProjectColumn, *Response, error) {
+func (s *ProjectsService) UpdateProjectColumn(ctx context.Context, columnID int, opt *ProjectColumnOptions) (*ProjectColumn, *Response, error) {
u := fmt.Sprintf("projects/columns/%v", columnID)
req, err := s.client.NewRequest("PATCH", u, opt)
if err != nil {
@@ -206,7 +209,7 @@ func (s *ProjectsService) UpdateProjectColumn(columnID int, opt *ProjectColumnOp
req.Header.Set("Accept", mediaTypeProjectsPreview)
column := &ProjectColumn{}
- resp, err := s.client.Do(req, column)
+ resp, err := s.client.Do(ctx, req, column)
if err != nil {
return nil, resp, err
}
@@ -217,7 +220,7 @@ func (s *ProjectsService) UpdateProjectColumn(columnID int, opt *ProjectColumnOp
// DeleteProjectColumn deletes a column from a GitHub Project.
//
// GitHub API docs: https://developer.github.com/v3/projects/columns/#delete-a-project-column
-func (s *ProjectsService) DeleteProjectColumn(columnID int) (*Response, error) {
+func (s *ProjectsService) DeleteProjectColumn(ctx context.Context, columnID int) (*Response, error) {
u := fmt.Sprintf("projects/columns/%v", columnID)
req, err := s.client.NewRequest("DELETE", u, nil)
if err != nil {
@@ -227,7 +230,7 @@ func (s *ProjectsService) DeleteProjectColumn(columnID int) (*Response, error) {
// TODO: remove custom Accept header when this API fully launches.
req.Header.Set("Accept", mediaTypeProjectsPreview)
- return s.client.Do(req, nil)
+ return s.client.Do(ctx, req, nil)
}
// ProjectColumnMoveOptions specifies the parameters to the
@@ -241,7 +244,7 @@ type ProjectColumnMoveOptions struct {
// MoveProjectColumn moves a column within a GitHub Project.
//
// GitHub API docs: https://developer.github.com/v3/projects/columns/#move-a-project-column
-func (s *ProjectsService) MoveProjectColumn(columnID int, opt *ProjectColumnMoveOptions) (*Response, error) {
+func (s *ProjectsService) MoveProjectColumn(ctx context.Context, columnID int, opt *ProjectColumnMoveOptions) (*Response, error) {
u := fmt.Sprintf("projects/columns/%v/moves", columnID)
req, err := s.client.NewRequest("POST", u, opt)
if err != nil {
@@ -251,7 +254,7 @@ func (s *ProjectsService) MoveProjectColumn(columnID int, opt *ProjectColumnMove
// TODO: remove custom Accept header when this API fully launches.
req.Header.Set("Accept", mediaTypeProjectsPreview)
- return s.client.Do(req, nil)
+ return s.client.Do(ctx, req, nil)
}
// ProjectCard represents a card in a column of a GitHub Project.
@@ -269,7 +272,7 @@ type ProjectCard struct {
// ListProjectCards lists the cards in a column of a GitHub Project.
//
// GitHub API docs: https://developer.github.com/v3/projects/cards/#list-project-cards
-func (s *ProjectsService) ListProjectCards(columnID int, opt *ListOptions) ([]*ProjectCard, *Response, error) {
+func (s *ProjectsService) ListProjectCards(ctx context.Context, columnID int, opt *ListOptions) ([]*ProjectCard, *Response, error) {
u := fmt.Sprintf("projects/columns/%v/cards", columnID)
u, err := addOptions(u, opt)
if err != nil {
@@ -285,7 +288,7 @@ func (s *ProjectsService) ListProjectCards(columnID int, opt *ListOptions) ([]*P
req.Header.Set("Accept", mediaTypeProjectsPreview)
cards := []*ProjectCard{}
- resp, err := s.client.Do(req, &cards)
+ resp, err := s.client.Do(ctx, req, &cards)
if err != nil {
return nil, resp, err
}
@@ -296,7 +299,7 @@ func (s *ProjectsService) ListProjectCards(columnID int, opt *ListOptions) ([]*P
// GetProjectCard gets a card in a column of a GitHub Project.
//
// GitHub API docs: https://developer.github.com/v3/projects/cards/#get-a-project-card
-func (s *ProjectsService) GetProjectCard(columnID int) (*ProjectCard, *Response, error) {
+func (s *ProjectsService) GetProjectCard(ctx context.Context, columnID int) (*ProjectCard, *Response, error) {
u := fmt.Sprintf("projects/columns/cards/%v", columnID)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
@@ -307,7 +310,7 @@ func (s *ProjectsService) GetProjectCard(columnID int) (*ProjectCard, *Response,
req.Header.Set("Accept", mediaTypeProjectsPreview)
card := &ProjectCard{}
- resp, err := s.client.Do(req, card)
+ resp, err := s.client.Do(ctx, req, card)
if err != nil {
return nil, resp, err
}
@@ -331,7 +334,7 @@ type ProjectCardOptions struct {
// CreateProjectCard creates a card in the specified column of a GitHub Project.
//
// GitHub API docs: https://developer.github.com/v3/projects/cards/#create-a-project-card
-func (s *ProjectsService) CreateProjectCard(columnID int, opt *ProjectCardOptions) (*ProjectCard, *Response, error) {
+func (s *ProjectsService) CreateProjectCard(ctx context.Context, columnID int, opt *ProjectCardOptions) (*ProjectCard, *Response, error) {
u := fmt.Sprintf("projects/columns/%v/cards", columnID)
req, err := s.client.NewRequest("POST", u, opt)
if err != nil {
@@ -342,7 +345,7 @@ func (s *ProjectsService) CreateProjectCard(columnID int, opt *ProjectCardOption
req.Header.Set("Accept", mediaTypeProjectsPreview)
card := &ProjectCard{}
- resp, err := s.client.Do(req, card)
+ resp, err := s.client.Do(ctx, req, card)
if err != nil {
return nil, resp, err
}
@@ -353,7 +356,7 @@ func (s *ProjectsService) CreateProjectCard(columnID int, opt *ProjectCardOption
// UpdateProjectCard updates a card of a GitHub Project.
//
// GitHub API docs: https://developer.github.com/v3/projects/cards/#update-a-project-card
-func (s *ProjectsService) UpdateProjectCard(cardID int, opt *ProjectCardOptions) (*ProjectCard, *Response, error) {
+func (s *ProjectsService) UpdateProjectCard(ctx context.Context, cardID int, opt *ProjectCardOptions) (*ProjectCard, *Response, error) {
u := fmt.Sprintf("projects/columns/cards/%v", cardID)
req, err := s.client.NewRequest("PATCH", u, opt)
if err != nil {
@@ -364,7 +367,7 @@ func (s *ProjectsService) UpdateProjectCard(cardID int, opt *ProjectCardOptions)
req.Header.Set("Accept", mediaTypeProjectsPreview)
card := &ProjectCard{}
- resp, err := s.client.Do(req, card)
+ resp, err := s.client.Do(ctx, req, card)
if err != nil {
return nil, resp, err
}
@@ -375,7 +378,7 @@ func (s *ProjectsService) UpdateProjectCard(cardID int, opt *ProjectCardOptions)
// DeleteProjectCard deletes a card from a GitHub Project.
//
// GitHub API docs: https://developer.github.com/v3/projects/cards/#delete-a-project-card
-func (s *ProjectsService) DeleteProjectCard(cardID int) (*Response, error) {
+func (s *ProjectsService) DeleteProjectCard(ctx context.Context, cardID int) (*Response, error) {
u := fmt.Sprintf("projects/columns/cards/%v", cardID)
req, err := s.client.NewRequest("DELETE", u, nil)
if err != nil {
@@ -385,7 +388,7 @@ func (s *ProjectsService) DeleteProjectCard(cardID int) (*Response, error) {
// TODO: remove custom Accept header when this API fully launches.
req.Header.Set("Accept", mediaTypeProjectsPreview)
- return s.client.Do(req, nil)
+ return s.client.Do(ctx, req, nil)
}
// ProjectCardMoveOptions specifies the parameters to the
@@ -403,7 +406,7 @@ type ProjectCardMoveOptions struct {
// MoveProjectCard moves a card within a GitHub Project.
//
// GitHub API docs: https://developer.github.com/v3/projects/cards/#move-a-project-card
-func (s *ProjectsService) MoveProjectCard(cardID int, opt *ProjectCardMoveOptions) (*Response, error) {
+func (s *ProjectsService) MoveProjectCard(ctx context.Context, cardID int, opt *ProjectCardMoveOptions) (*Response, error) {
u := fmt.Sprintf("projects/columns/cards/%v/moves", cardID)
req, err := s.client.NewRequest("POST", u, opt)
if err != nil {
@@ -413,5 +416,5 @@ func (s *ProjectsService) MoveProjectCard(cardID int, opt *ProjectCardMoveOption
// TODO: remove custom Accept header when this API fully launches.
req.Header.Set("Accept", mediaTypeProjectsPreview)
- return s.client.Do(req, nil)
+ return s.client.Do(ctx, req, nil)
}
diff --git a/github/projects_test.go b/github/projects_test.go
index f6bb3b0a02f..1045ca9befa 100644
--- a/github/projects_test.go
+++ b/github/projects_test.go
@@ -6,6 +6,7 @@
package github
import (
+ "context"
"encoding/json"
"fmt"
"net/http"
@@ -32,7 +33,7 @@ func TestProjectsService_UpdateProject(t *testing.T) {
fmt.Fprint(w, `{"id":1}`)
})
- project, _, err := client.Projects.UpdateProject(1, input)
+ project, _, err := client.Projects.UpdateProject(context.Background(), 1, input)
if err != nil {
t.Errorf("Projects.UpdateProject returned error: %v", err)
}
@@ -53,7 +54,7 @@ func TestProjectsService_GetProject(t *testing.T) {
fmt.Fprint(w, `{"id":1}`)
})
- project, _, err := client.Projects.GetProject(1)
+ project, _, err := client.Projects.GetProject(context.Background(), 1)
if err != nil {
t.Errorf("Projects.GetProject returned error: %v", err)
}
@@ -73,7 +74,7 @@ func TestProjectsService_DeleteProject(t *testing.T) {
testHeader(t, r, "Accept", mediaTypeProjectsPreview)
})
- _, err := client.Projects.DeleteProject(1)
+ _, err := client.Projects.DeleteProject(context.Background(), 1)
if err != nil {
t.Errorf("Projects.DeleteProject returned error: %v", err)
}
@@ -91,7 +92,7 @@ func TestProjectsService_ListProjectColumns(t *testing.T) {
})
opt := &ListOptions{Page: 2}
- columns, _, err := client.Projects.ListProjectColumns(1, opt)
+ columns, _, err := client.Projects.ListProjectColumns(context.Background(), 1, opt)
if err != nil {
t.Errorf("Projects.ListProjectColumns returned error: %v", err)
}
@@ -112,7 +113,7 @@ func TestProjectsService_GetProjectColumn(t *testing.T) {
fmt.Fprint(w, `{"id":1}`)
})
- column, _, err := client.Projects.GetProjectColumn(1)
+ column, _, err := client.Projects.GetProjectColumn(context.Background(), 1)
if err != nil {
t.Errorf("Projects.GetProjectColumn returned error: %v", err)
}
@@ -142,7 +143,7 @@ func TestProjectsService_CreateProjectColumn(t *testing.T) {
fmt.Fprint(w, `{"id":1}`)
})
- column, _, err := client.Projects.CreateProjectColumn(1, input)
+ column, _, err := client.Projects.CreateProjectColumn(context.Background(), 1, input)
if err != nil {
t.Errorf("Projects.CreateProjectColumn returned error: %v", err)
}
@@ -172,7 +173,7 @@ func TestProjectsService_UpdateProjectColumn(t *testing.T) {
fmt.Fprint(w, `{"id":1}`)
})
- column, _, err := client.Projects.UpdateProjectColumn(1, input)
+ column, _, err := client.Projects.UpdateProjectColumn(context.Background(), 1, input)
if err != nil {
t.Errorf("Projects.UpdateProjectColumn returned error: %v", err)
}
@@ -192,7 +193,7 @@ func TestProjectsService_DeleteProjectColumn(t *testing.T) {
testHeader(t, r, "Accept", mediaTypeProjectsPreview)
})
- _, err := client.Projects.DeleteProjectColumn(1)
+ _, err := client.Projects.DeleteProjectColumn(context.Background(), 1)
if err != nil {
t.Errorf("Projects.DeleteProjectColumn returned error: %v", err)
}
@@ -215,7 +216,7 @@ func TestProjectsService_MoveProjectColumn(t *testing.T) {
}
})
- _, err := client.Projects.MoveProjectColumn(1, input)
+ _, err := client.Projects.MoveProjectColumn(context.Background(), 1, input)
if err != nil {
t.Errorf("Projects.MoveProjectColumn returned error: %v", err)
}
@@ -233,7 +234,7 @@ func TestProjectsService_ListProjectCards(t *testing.T) {
})
opt := &ListOptions{Page: 2}
- cards, _, err := client.Projects.ListProjectCards(1, opt)
+ cards, _, err := client.Projects.ListProjectCards(context.Background(), 1, opt)
if err != nil {
t.Errorf("Projects.ListProjectCards returned error: %v", err)
}
@@ -254,7 +255,7 @@ func TestProjectsService_GetProjectCard(t *testing.T) {
fmt.Fprint(w, `{"id":1}`)
})
- card, _, err := client.Projects.GetProjectCard(1)
+ card, _, err := client.Projects.GetProjectCard(context.Background(), 1)
if err != nil {
t.Errorf("Projects.GetProjectCard returned error: %v", err)
}
@@ -287,7 +288,7 @@ func TestProjectsService_CreateProjectCard(t *testing.T) {
fmt.Fprint(w, `{"id":1}`)
})
- card, _, err := client.Projects.CreateProjectCard(1, input)
+ card, _, err := client.Projects.CreateProjectCard(context.Background(), 1, input)
if err != nil {
t.Errorf("Projects.CreateProjectCard returned error: %v", err)
}
@@ -320,7 +321,7 @@ func TestProjectsService_UpdateProjectCard(t *testing.T) {
fmt.Fprint(w, `{"id":1}`)
})
- card, _, err := client.Projects.UpdateProjectCard(1, input)
+ card, _, err := client.Projects.UpdateProjectCard(context.Background(), 1, input)
if err != nil {
t.Errorf("Projects.UpdateProjectCard returned error: %v", err)
}
@@ -340,7 +341,7 @@ func TestProjectsService_DeleteProjectCard(t *testing.T) {
testHeader(t, r, "Accept", mediaTypeProjectsPreview)
})
- _, err := client.Projects.DeleteProjectCard(1)
+ _, err := client.Projects.DeleteProjectCard(context.Background(), 1)
if err != nil {
t.Errorf("Projects.DeleteProjectCard returned error: %v", err)
}
@@ -363,7 +364,7 @@ func TestProjectsService_MoveProjectCard(t *testing.T) {
}
})
- _, err := client.Projects.MoveProjectCard(1, input)
+ _, err := client.Projects.MoveProjectCard(context.Background(), 1, input)
if err != nil {
t.Errorf("Projects.MoveProjectCard returned error: %v", err)
}
diff --git a/github/pulls.go b/github/pulls.go
index 5b5667b788e..ed9d11e3bab 100644
--- a/github/pulls.go
+++ b/github/pulls.go
@@ -7,6 +7,7 @@ package github
import (
"bytes"
+ "context"
"fmt"
"time"
)
@@ -95,7 +96,7 @@ type PullRequestListOptions struct {
// List the pull requests for the specified repository.
//
// GitHub API docs: https://developer.github.com/v3/pulls/#list-pull-requests
-func (s *PullRequestsService) List(owner string, repo string, opt *PullRequestListOptions) ([]*PullRequest, *Response, error) {
+func (s *PullRequestsService) List(ctx context.Context, owner string, repo string, opt *PullRequestListOptions) ([]*PullRequest, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/pulls", owner, repo)
u, err := addOptions(u, opt)
if err != nil {
@@ -108,7 +109,7 @@ func (s *PullRequestsService) List(owner string, repo string, opt *PullRequestLi
}
var pulls []*PullRequest
- resp, err := s.client.Do(req, &pulls)
+ resp, err := s.client.Do(ctx, req, &pulls)
if err != nil {
return nil, resp, err
}
@@ -119,7 +120,7 @@ func (s *PullRequestsService) List(owner string, repo string, opt *PullRequestLi
// 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, *Response, error) {
+func (s *PullRequestsService) Get(ctx context.Context, owner string, repo string, number int) (*PullRequest, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/pulls/%d", owner, repo, number)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
@@ -127,7 +128,7 @@ func (s *PullRequestsService) Get(owner string, repo string, number int) (*PullR
}
pull := new(PullRequest)
- resp, err := s.client.Do(req, pull)
+ resp, err := s.client.Do(ctx, req, pull)
if err != nil {
return nil, resp, err
}
@@ -136,7 +137,7 @@ func (s *PullRequestsService) Get(owner string, repo string, number int) (*PullR
}
// GetRaw gets raw (diff or patch) format of a pull request.
-func (s *PullRequestsService) GetRaw(owner string, repo string, number int, opt RawOptions) (string, *Response, error) {
+func (s *PullRequestsService) GetRaw(ctx context.Context, owner string, repo string, number int, opt RawOptions) (string, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/pulls/%d", owner, repo, number)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
@@ -153,7 +154,7 @@ func (s *PullRequestsService) GetRaw(owner string, repo string, number int, opt
}
ret := new(bytes.Buffer)
- resp, err := s.client.Do(req, ret)
+ resp, err := s.client.Do(ctx, req, ret)
if err != nil {
return "", resp, err
}
@@ -173,7 +174,7 @@ type NewPullRequest struct {
// Create a new pull request on the specified repository.
//
// GitHub API docs: https://developer.github.com/v3/pulls/#create-a-pull-request
-func (s *PullRequestsService) Create(owner string, repo string, pull *NewPullRequest) (*PullRequest, *Response, error) {
+func (s *PullRequestsService) Create(ctx context.Context, owner string, repo string, pull *NewPullRequest) (*PullRequest, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/pulls", owner, repo)
req, err := s.client.NewRequest("POST", u, pull)
if err != nil {
@@ -181,7 +182,7 @@ func (s *PullRequestsService) Create(owner string, repo string, pull *NewPullReq
}
p := new(PullRequest)
- resp, err := s.client.Do(req, p)
+ resp, err := s.client.Do(ctx, req, p)
if err != nil {
return nil, resp, err
}
@@ -202,7 +203,7 @@ type pullRequestUpdate struct {
// Base.Ref updates the base branch of the 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, *Response, error) {
+func (s *PullRequestsService) Edit(ctx context.Context, owner string, repo string, number int, pull *PullRequest) (*PullRequest, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/pulls/%d", owner, repo, number)
update := new(pullRequestUpdate)
@@ -221,7 +222,7 @@ func (s *PullRequestsService) Edit(owner string, repo string, number int, pull *
}
p := new(PullRequest)
- resp, err := s.client.Do(req, p)
+ resp, err := s.client.Do(ctx, req, p)
if err != nil {
return nil, resp, err
}
@@ -232,7 +233,7 @@ func (s *PullRequestsService) Edit(owner string, repo string, number int, pull *
// ListCommits lists the commits in a pull request.
//
// GitHub API docs: https://developer.github.com/v3/pulls/#list-commits-on-a-pull-request
-func (s *PullRequestsService) ListCommits(owner string, repo string, number int, opt *ListOptions) ([]*RepositoryCommit, *Response, error) {
+func (s *PullRequestsService) ListCommits(ctx context.Context, owner string, repo string, number int, opt *ListOptions) ([]*RepositoryCommit, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/pulls/%d/commits", owner, repo, number)
u, err := addOptions(u, opt)
if err != nil {
@@ -245,7 +246,7 @@ func (s *PullRequestsService) ListCommits(owner string, repo string, number int,
}
var commits []*RepositoryCommit
- resp, err := s.client.Do(req, &commits)
+ resp, err := s.client.Do(ctx, req, &commits)
if err != nil {
return nil, resp, err
}
@@ -256,7 +257,7 @@ func (s *PullRequestsService) ListCommits(owner string, repo string, number int,
// ListFiles lists the files in a pull request.
//
// GitHub API docs: https://developer.github.com/v3/pulls/#list-pull-requests-files
-func (s *PullRequestsService) ListFiles(owner string, repo string, number int, opt *ListOptions) ([]*CommitFile, *Response, error) {
+func (s *PullRequestsService) ListFiles(ctx context.Context, owner string, repo string, number int, opt *ListOptions) ([]*CommitFile, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/pulls/%d/files", owner, repo, number)
u, err := addOptions(u, opt)
if err != nil {
@@ -269,7 +270,7 @@ func (s *PullRequestsService) ListFiles(owner string, repo string, number int, o
}
var commitFiles []*CommitFile
- resp, err := s.client.Do(req, &commitFiles)
+ resp, err := s.client.Do(ctx, req, &commitFiles)
if err != nil {
return nil, resp, err
}
@@ -280,14 +281,14 @@ func (s *PullRequestsService) ListFiles(owner string, repo string, number int, o
// IsMerged checks if a pull request has been merged.
//
// GitHub API docs: https://developer.github.com/v3/pulls/#get-if-a-pull-request-has-been-merged
-func (s *PullRequestsService) IsMerged(owner string, repo string, number int) (bool, *Response, error) {
+func (s *PullRequestsService) IsMerged(ctx context.Context, owner string, repo string, number int) (bool, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/pulls/%d/merge", owner, repo, number)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return false, nil, err
}
- resp, err := s.client.Do(req, nil)
+ resp, err := s.client.Do(ctx, req, nil)
merged, err := parseBoolResponse(err)
return merged, resp, err
}
@@ -319,7 +320,7 @@ type pullRequestMergeRequest struct {
// commitMessage is the title for the automatic commit message.
//
// GitHub API docs: https://developer.github.com/v3/pulls/#merge-a-pull-request-merge-buttontrade
-func (s *PullRequestsService) Merge(owner string, repo string, number int, commitMessage string, options *PullRequestOptions) (*PullRequestMergeResult, *Response, error) {
+func (s *PullRequestsService) Merge(ctx context.Context, owner string, repo string, number int, commitMessage string, options *PullRequestOptions) (*PullRequestMergeResult, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/pulls/%d/merge", owner, repo, number)
pullRequestBody := &pullRequestMergeRequest{CommitMessage: commitMessage}
@@ -337,7 +338,7 @@ func (s *PullRequestsService) Merge(owner string, repo string, number int, commi
req.Header.Set("Accept", mediaTypeSquashPreview)
mergeResult := new(PullRequestMergeResult)
- resp, err := s.client.Do(req, mergeResult)
+ resp, err := s.client.Do(ctx, req, mergeResult)
if err != nil {
return nil, resp, err
}
diff --git a/github/pulls_comments.go b/github/pulls_comments.go
index 05953890233..bc0bc2d4a2f 100644
--- a/github/pulls_comments.go
+++ b/github/pulls_comments.go
@@ -6,6 +6,7 @@
package github
import (
+ "context"
"fmt"
"time"
)
@@ -54,7 +55,7 @@ type PullRequestListCommentsOptions struct {
// the repository.
//
// 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, *Response, error) {
+func (s *PullRequestsService) ListComments(ctx context.Context, owner string, repo string, number int, opt *PullRequestListCommentsOptions) ([]*PullRequestComment, *Response, error) {
var u string
if number == 0 {
u = fmt.Sprintf("repos/%v/%v/pulls/comments", owner, repo)
@@ -75,7 +76,7 @@ func (s *PullRequestsService) ListComments(owner string, repo string, number int
req.Header.Set("Accept", mediaTypeReactionsPreview)
var comments []*PullRequestComment
- resp, err := s.client.Do(req, &comments)
+ resp, err := s.client.Do(ctx, req, &comments)
if err != nil {
return nil, resp, err
}
@@ -86,7 +87,7 @@ func (s *PullRequestsService) ListComments(owner string, repo string, number int
// GetComment fetches the specified pull request 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, *Response, error) {
+func (s *PullRequestsService) GetComment(ctx context.Context, owner string, repo string, number int) (*PullRequestComment, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/pulls/comments/%d", owner, repo, number)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
@@ -97,7 +98,7 @@ func (s *PullRequestsService) GetComment(owner string, repo string, number int)
req.Header.Set("Accept", mediaTypeReactionsPreview)
comment := new(PullRequestComment)
- resp, err := s.client.Do(req, comment)
+ resp, err := s.client.Do(ctx, req, comment)
if err != nil {
return nil, resp, err
}
@@ -108,7 +109,7 @@ func (s *PullRequestsService) GetComment(owner string, repo string, number int)
// CreateComment creates a new comment on the specified pull request.
//
// GitHub API docs: https://developer.github.com/v3/pulls/comments/#create-a-comment
-func (s *PullRequestsService) CreateComment(owner string, repo string, number int, comment *PullRequestComment) (*PullRequestComment, *Response, error) {
+func (s *PullRequestsService) CreateComment(ctx context.Context, owner string, repo string, number int, comment *PullRequestComment) (*PullRequestComment, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/pulls/%d/comments", owner, repo, number)
req, err := s.client.NewRequest("POST", u, comment)
if err != nil {
@@ -116,7 +117,7 @@ func (s *PullRequestsService) CreateComment(owner string, repo string, number in
}
c := new(PullRequestComment)
- resp, err := s.client.Do(req, c)
+ resp, err := s.client.Do(ctx, req, c)
if err != nil {
return nil, resp, err
}
@@ -127,7 +128,7 @@ func (s *PullRequestsService) CreateComment(owner string, repo string, number in
// EditComment updates a pull request 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, *Response, error) {
+func (s *PullRequestsService) EditComment(ctx context.Context, owner string, repo string, number int, comment *PullRequestComment) (*PullRequestComment, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/pulls/comments/%d", owner, repo, number)
req, err := s.client.NewRequest("PATCH", u, comment)
if err != nil {
@@ -135,7 +136,7 @@ func (s *PullRequestsService) EditComment(owner string, repo string, number int,
}
c := new(PullRequestComment)
- resp, err := s.client.Do(req, c)
+ resp, err := s.client.Do(ctx, req, c)
if err != nil {
return nil, resp, err
}
@@ -146,11 +147,11 @@ func (s *PullRequestsService) EditComment(owner string, repo string, number int,
// DeleteComment deletes a pull request comment.
//
// GitHub API docs: https://developer.github.com/v3/pulls/comments/#delete-a-comment
-func (s *PullRequestsService) DeleteComment(owner string, repo string, number int) (*Response, error) {
+func (s *PullRequestsService) DeleteComment(ctx context.Context, owner string, repo string, number int) (*Response, error) {
u := fmt.Sprintf("repos/%v/%v/pulls/comments/%d", owner, repo, number)
req, err := s.client.NewRequest("DELETE", u, nil)
if err != nil {
return nil, err
}
- return s.client.Do(req, nil)
+ return s.client.Do(ctx, req, nil)
}
diff --git a/github/pulls_comments_test.go b/github/pulls_comments_test.go
index 5412ac88164..e35b04f7b7b 100644
--- a/github/pulls_comments_test.go
+++ b/github/pulls_comments_test.go
@@ -6,6 +6,7 @@
package github
import (
+ "context"
"encoding/json"
"fmt"
"net/http"
@@ -36,7 +37,7 @@ func TestPullRequestsService_ListComments_allPulls(t *testing.T) {
Since: time.Date(2002, time.February, 10, 15, 30, 0, 0, time.UTC),
ListOptions: ListOptions{Page: 2},
}
- pulls, _, err := client.PullRequests.ListComments("o", "r", 0, opt)
+ pulls, _, err := client.PullRequests.ListComments(context.Background(), "o", "r", 0, opt)
if err != nil {
t.Errorf("PullRequests.ListComments returned error: %v", err)
}
@@ -57,7 +58,7 @@ func TestPullRequestsService_ListComments_specificPull(t *testing.T) {
fmt.Fprint(w, `[{"id":1}]`)
})
- pulls, _, err := client.PullRequests.ListComments("o", "r", 1, nil)
+ pulls, _, err := client.PullRequests.ListComments(context.Background(), "o", "r", 1, nil)
if err != nil {
t.Errorf("PullRequests.ListComments returned error: %v", err)
}
@@ -69,7 +70,7 @@ func TestPullRequestsService_ListComments_specificPull(t *testing.T) {
}
func TestPullRequestsService_ListComments_invalidOwner(t *testing.T) {
- _, _, err := client.PullRequests.ListComments("%", "r", 1, nil)
+ _, _, err := client.PullRequests.ListComments(context.Background(), "%", "r", 1, nil)
testURLParseError(t, err)
}
@@ -83,7 +84,7 @@ func TestPullRequestsService_GetComment(t *testing.T) {
fmt.Fprint(w, `{"id":1}`)
})
- comment, _, err := client.PullRequests.GetComment("o", "r", 1)
+ comment, _, err := client.PullRequests.GetComment(context.Background(), "o", "r", 1)
if err != nil {
t.Errorf("PullRequests.GetComment returned error: %v", err)
}
@@ -95,7 +96,7 @@ func TestPullRequestsService_GetComment(t *testing.T) {
}
func TestPullRequestsService_GetComment_invalidOwner(t *testing.T) {
- _, _, err := client.PullRequests.GetComment("%", "r", 1)
+ _, _, err := client.PullRequests.GetComment(context.Background(), "%", "r", 1)
testURLParseError(t, err)
}
@@ -117,7 +118,7 @@ func TestPullRequestsService_CreateComment(t *testing.T) {
fmt.Fprint(w, `{"id":1}`)
})
- comment, _, err := client.PullRequests.CreateComment("o", "r", 1, input)
+ comment, _, err := client.PullRequests.CreateComment(context.Background(), "o", "r", 1, input)
if err != nil {
t.Errorf("PullRequests.CreateComment returned error: %v", err)
}
@@ -129,7 +130,7 @@ func TestPullRequestsService_CreateComment(t *testing.T) {
}
func TestPullRequestsService_CreateComment_invalidOwner(t *testing.T) {
- _, _, err := client.PullRequests.CreateComment("%", "r", 1, nil)
+ _, _, err := client.PullRequests.CreateComment(context.Background(), "%", "r", 1, nil)
testURLParseError(t, err)
}
@@ -151,7 +152,7 @@ func TestPullRequestsService_EditComment(t *testing.T) {
fmt.Fprint(w, `{"id":1}`)
})
- comment, _, err := client.PullRequests.EditComment("o", "r", 1, input)
+ comment, _, err := client.PullRequests.EditComment(context.Background(), "o", "r", 1, input)
if err != nil {
t.Errorf("PullRequests.EditComment returned error: %v", err)
}
@@ -163,7 +164,7 @@ func TestPullRequestsService_EditComment(t *testing.T) {
}
func TestPullRequestsService_EditComment_invalidOwner(t *testing.T) {
- _, _, err := client.PullRequests.EditComment("%", "r", 1, nil)
+ _, _, err := client.PullRequests.EditComment(context.Background(), "%", "r", 1, nil)
testURLParseError(t, err)
}
@@ -175,13 +176,13 @@ func TestPullRequestsService_DeleteComment(t *testing.T) {
testMethod(t, r, "DELETE")
})
- _, err := client.PullRequests.DeleteComment("o", "r", 1)
+ _, err := client.PullRequests.DeleteComment(context.Background(), "o", "r", 1)
if err != nil {
t.Errorf("PullRequests.DeleteComment returned error: %v", err)
}
}
func TestPullRequestsService_DeleteComment_invalidOwner(t *testing.T) {
- _, err := client.PullRequests.DeleteComment("%", "r", 1)
+ _, err := client.PullRequests.DeleteComment(context.Background(), "%", "r", 1)
testURLParseError(t, err)
}
diff --git a/github/pulls_reviews.go b/github/pulls_reviews.go
index be57af88c72..c27b6a8c473 100644
--- a/github/pulls_reviews.go
+++ b/github/pulls_reviews.go
@@ -6,6 +6,7 @@
package github
import (
+ "context"
"fmt"
"time"
)
@@ -64,7 +65,7 @@ func (r PullRequestReviewDismissalRequest) String() string {
// Read more about it here - https://github.com/google/go-github/issues/540
//
// GitHub API docs: https://developer.github.com/v3/pulls/reviews/#list-reviews-on-a-pull-request
-func (s *PullRequestsService) ListReviews(owner, repo string, number int) ([]*PullRequestReview, *Response, error) {
+func (s *PullRequestsService) ListReviews(ctx context.Context, owner, repo string, number int) ([]*PullRequestReview, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/pulls/%d/reviews", owner, repo, number)
req, err := s.client.NewRequest("GET", u, nil)
@@ -76,7 +77,7 @@ func (s *PullRequestsService) ListReviews(owner, repo string, number int) ([]*Pu
req.Header.Set("Accept", mediaTypePullRequestReviewsPreview)
var reviews []*PullRequestReview
- resp, err := s.client.Do(req, &reviews)
+ resp, err := s.client.Do(ctx, req, &reviews)
if err != nil {
return nil, resp, err
}
@@ -91,7 +92,7 @@ func (s *PullRequestsService) ListReviews(owner, repo string, number int) ([]*Pu
// Read more about it here - https://github.com/google/go-github/issues/540
//
// GitHub API docs: https://developer.github.com/v3/pulls/reviews/#get-a-single-review
-func (s *PullRequestsService) GetReview(owner, repo string, number, reviewID int) (*PullRequestReview, *Response, error) {
+func (s *PullRequestsService) GetReview(ctx context.Context, owner, repo string, number, reviewID int) (*PullRequestReview, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/pulls/%d/reviews/%d", owner, repo, number, reviewID)
req, err := s.client.NewRequest("GET", u, nil)
@@ -103,7 +104,7 @@ func (s *PullRequestsService) GetReview(owner, repo string, number, reviewID int
req.Header.Set("Accept", mediaTypePullRequestReviewsPreview)
review := new(PullRequestReview)
- resp, err := s.client.Do(req, review)
+ resp, err := s.client.Do(ctx, req, review)
if err != nil {
return nil, resp, err
}
@@ -118,7 +119,7 @@ func (s *PullRequestsService) GetReview(owner, repo string, number, reviewID int
// Read more about it here - https://github.com/google/go-github/issues/540
//
// GitHub API docs: https://developer.github.com/v3/pulls/reviews/#delete-a-pending-review
-func (s *PullRequestsService) DeletePendingReview(owner, repo string, number, reviewID int) (*PullRequestReview, *Response, error) {
+func (s *PullRequestsService) DeletePendingReview(ctx context.Context, owner, repo string, number, reviewID int) (*PullRequestReview, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/pulls/%d/reviews/%d", owner, repo, number, reviewID)
req, err := s.client.NewRequest("DELETE", u, nil)
@@ -130,7 +131,7 @@ func (s *PullRequestsService) DeletePendingReview(owner, repo string, number, re
req.Header.Set("Accept", mediaTypePullRequestReviewsPreview)
review := new(PullRequestReview)
- resp, err := s.client.Do(req, review)
+ resp, err := s.client.Do(ctx, req, review)
if err != nil {
return nil, resp, err
}
@@ -145,7 +146,7 @@ func (s *PullRequestsService) DeletePendingReview(owner, repo string, number, re
// Read more about it here - https://github.com/google/go-github/issues/540
//
// GitHub API docs: https://developer.github.com/v3/pulls/reviews/#get-a-single-reviews-comments
-func (s *PullRequestsService) ListReviewComments(owner, repo string, number, reviewID int) ([]*PullRequestComment, *Response, error) {
+func (s *PullRequestsService) ListReviewComments(ctx context.Context, owner, repo string, number, reviewID int) ([]*PullRequestComment, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/pulls/%d/reviews/%d/comments", owner, repo, number, reviewID)
req, err := s.client.NewRequest("GET", u, nil)
@@ -157,7 +158,7 @@ func (s *PullRequestsService) ListReviewComments(owner, repo string, number, rev
req.Header.Set("Accept", mediaTypePullRequestReviewsPreview)
var comments []*PullRequestComment
- resp, err := s.client.Do(req, &comments)
+ resp, err := s.client.Do(ctx, req, &comments)
if err != nil {
return nil, resp, err
}
@@ -172,7 +173,7 @@ func (s *PullRequestsService) ListReviewComments(owner, repo string, number, rev
// Read more about it here - https://github.com/google/go-github/issues/540
//
// GitHub API docs: https://developer.github.com/v3/pulls/reviews/#create-a-pull-request-review
-func (s *PullRequestsService) CreateReview(owner, repo string, number int, review *PullRequestReviewRequest) (*PullRequestReview, *Response, error) {
+func (s *PullRequestsService) CreateReview(ctx context.Context, owner, repo string, number int, review *PullRequestReviewRequest) (*PullRequestReview, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/pulls/%d/reviews", owner, repo, number)
req, err := s.client.NewRequest("POST", u, review)
@@ -184,7 +185,7 @@ func (s *PullRequestsService) CreateReview(owner, repo string, number int, revie
req.Header.Set("Accept", mediaTypePullRequestReviewsPreview)
r := new(PullRequestReview)
- resp, err := s.client.Do(req, r)
+ resp, err := s.client.Do(ctx, req, r)
if err != nil {
return nil, resp, err
}
@@ -199,7 +200,7 @@ func (s *PullRequestsService) CreateReview(owner, repo string, number int, revie
// Read more about it here - https://github.com/google/go-github/issues/540
//
// GitHub API docs: https://developer.github.com/v3/pulls/reviews/#submit-a-pull-request-review
-func (s *PullRequestsService) SubmitReview(owner, repo string, number, reviewID int, review *PullRequestReviewRequest) (*PullRequestReview, *Response, error) {
+func (s *PullRequestsService) SubmitReview(ctx context.Context, owner, repo string, number, reviewID int, review *PullRequestReviewRequest) (*PullRequestReview, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/pulls/%d/reviews/%d/events", owner, repo, number, reviewID)
req, err := s.client.NewRequest("POST", u, review)
@@ -211,7 +212,7 @@ func (s *PullRequestsService) SubmitReview(owner, repo string, number, reviewID
req.Header.Set("Accept", mediaTypePullRequestReviewsPreview)
r := new(PullRequestReview)
- resp, err := s.client.Do(req, r)
+ resp, err := s.client.Do(ctx, req, r)
if err != nil {
return nil, resp, err
}
@@ -226,7 +227,7 @@ func (s *PullRequestsService) SubmitReview(owner, repo string, number, reviewID
// Read more about it here - https://github.com/google/go-github/issues/540
//
// GitHub API docs: https://developer.github.com/v3/pulls/reviews/#dismiss-a-pull-request-review
-func (s *PullRequestsService) DismissReview(owner, repo string, number, reviewID int, review *PullRequestReviewDismissalRequest) (*PullRequestReview, *Response, error) {
+func (s *PullRequestsService) DismissReview(ctx context.Context, owner, repo string, number, reviewID int, review *PullRequestReviewDismissalRequest) (*PullRequestReview, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/pulls/%d/reviews/%d/dismissals", owner, repo, number, reviewID)
req, err := s.client.NewRequest("PUT", u, review)
@@ -238,7 +239,7 @@ func (s *PullRequestsService) DismissReview(owner, repo string, number, reviewID
req.Header.Set("Accept", mediaTypePullRequestReviewsPreview)
r := new(PullRequestReview)
- resp, err := s.client.Do(req, r)
+ resp, err := s.client.Do(ctx, req, r)
if err != nil {
return nil, resp, err
}
diff --git a/github/pulls_reviews_test.go b/github/pulls_reviews_test.go
index 707fd5a6689..0045c8b05b7 100644
--- a/github/pulls_reviews_test.go
+++ b/github/pulls_reviews_test.go
@@ -6,6 +6,7 @@
package github
import (
+ "context"
"encoding/json"
"fmt"
"net/http"
@@ -23,7 +24,7 @@ func TestPullRequestsService_ListReviews(t *testing.T) {
fmt.Fprint(w, `[{"id":1},{"id":2}]`)
})
- reviews, _, err := client.PullRequests.ListReviews("o", "r", 1)
+ reviews, _, err := client.PullRequests.ListReviews(context.Background(), "o", "r", 1)
if err != nil {
t.Errorf("PullRequests.ListReviews returned error: %v", err)
}
@@ -38,7 +39,7 @@ func TestPullRequestsService_ListReviews(t *testing.T) {
}
func TestPullRequestsService_ListReviews_invalidOwner(t *testing.T) {
- _, _, err := client.PullRequests.ListReviews("%", "r", 1)
+ _, _, err := client.PullRequests.ListReviews(context.Background(), "%", "r", 1)
testURLParseError(t, err)
}
@@ -52,7 +53,7 @@ func TestPullRequestsService_GetReview(t *testing.T) {
fmt.Fprint(w, `{"id":1}`)
})
- review, _, err := client.PullRequests.GetReview("o", "r", 1, 1)
+ review, _, err := client.PullRequests.GetReview(context.Background(), "o", "r", 1, 1)
if err != nil {
t.Errorf("PullRequests.GetReview returned error: %v", err)
}
@@ -64,7 +65,7 @@ func TestPullRequestsService_GetReview(t *testing.T) {
}
func TestPullRequestsService_GetReview_invalidOwner(t *testing.T) {
- _, _, err := client.PullRequests.GetReview("%", "r", 1, 1)
+ _, _, err := client.PullRequests.GetReview(context.Background(), "%", "r", 1, 1)
testURLParseError(t, err)
}
@@ -78,7 +79,7 @@ func TestPullRequestsService_DeletePendingReview(t *testing.T) {
fmt.Fprint(w, `{"id":1}`)
})
- review, _, err := client.PullRequests.DeletePendingReview("o", "r", 1, 1)
+ review, _, err := client.PullRequests.DeletePendingReview(context.Background(), "o", "r", 1, 1)
if err != nil {
t.Errorf("PullRequests.DeletePendingReview returned error: %v", err)
}
@@ -90,7 +91,7 @@ func TestPullRequestsService_DeletePendingReview(t *testing.T) {
}
func TestPullRequestsService_DeletePendingReview_invalidOwner(t *testing.T) {
- _, _, err := client.PullRequests.DeletePendingReview("%", "r", 1, 1)
+ _, _, err := client.PullRequests.DeletePendingReview(context.Background(), "%", "r", 1, 1)
testURLParseError(t, err)
}
@@ -104,7 +105,7 @@ func TestPullRequestsService_ListReviewComments(t *testing.T) {
fmt.Fprint(w, `[{"id":1},{"id":2}]`)
})
- comments, _, err := client.PullRequests.ListReviewComments("o", "r", 1, 1)
+ comments, _, err := client.PullRequests.ListReviewComments(context.Background(), "o", "r", 1, 1)
if err != nil {
t.Errorf("PullRequests.ListReviewComments returned error: %v", err)
}
@@ -119,7 +120,7 @@ func TestPullRequestsService_ListReviewComments(t *testing.T) {
}
func TestPullRequestsService_ListReviewComments_invalidOwner(t *testing.T) {
- _, _, err := client.PullRequests.ListReviewComments("%", "r", 1, 1)
+ _, _, err := client.PullRequests.ListReviewComments(context.Background(), "%", "r", 1, 1)
testURLParseError(t, err)
}
@@ -145,7 +146,7 @@ func TestPullRequestsService_CreateReview(t *testing.T) {
fmt.Fprint(w, `{"id":1}`)
})
- review, _, err := client.PullRequests.CreateReview("o", "r", 1, input)
+ review, _, err := client.PullRequests.CreateReview(context.Background(), "o", "r", 1, input)
if err != nil {
t.Errorf("PullRequests.CreateReview returned error: %v", err)
}
@@ -157,7 +158,7 @@ func TestPullRequestsService_CreateReview(t *testing.T) {
}
func TestPullRequestsService_CreateReview_invalidOwner(t *testing.T) {
- _, _, err := client.PullRequests.CreateReview("%", "r", 1, &PullRequestReviewRequest{})
+ _, _, err := client.PullRequests.CreateReview(context.Background(), "%", "r", 1, &PullRequestReviewRequest{})
testURLParseError(t, err)
}
@@ -183,7 +184,7 @@ func TestPullRequestsService_SubmitReview(t *testing.T) {
fmt.Fprint(w, `{"id":1}`)
})
- review, _, err := client.PullRequests.SubmitReview("o", "r", 1, 1, input)
+ review, _, err := client.PullRequests.SubmitReview(context.Background(), "o", "r", 1, 1, input)
if err != nil {
t.Errorf("PullRequests.SubmitReview returned error: %v", err)
}
@@ -195,7 +196,7 @@ func TestPullRequestsService_SubmitReview(t *testing.T) {
}
func TestPullRequestsService_SubmitReview_invalidOwner(t *testing.T) {
- _, _, err := client.PullRequests.SubmitReview("%", "r", 1, 1, &PullRequestReviewRequest{})
+ _, _, err := client.PullRequests.SubmitReview(context.Background(), "%", "r", 1, 1, &PullRequestReviewRequest{})
testURLParseError(t, err)
}
@@ -218,7 +219,7 @@ func TestPullRequestsService_DismissReview(t *testing.T) {
fmt.Fprint(w, `{"id":1}`)
})
- review, _, err := client.PullRequests.DismissReview("o", "r", 1, 1, input)
+ review, _, err := client.PullRequests.DismissReview(context.Background(), "o", "r", 1, 1, input)
if err != nil {
t.Errorf("PullRequests.DismissReview returned error: %v", err)
}
@@ -230,6 +231,6 @@ func TestPullRequestsService_DismissReview(t *testing.T) {
}
func TestPullRequestsService_DismissReview_invalidOwner(t *testing.T) {
- _, _, err := client.PullRequests.DismissReview("%", "r", 1, 1, &PullRequestReviewDismissalRequest{})
+ _, _, err := client.PullRequests.DismissReview(context.Background(), "%", "r", 1, 1, &PullRequestReviewDismissalRequest{})
testURLParseError(t, err)
}
diff --git a/github/pulls_test.go b/github/pulls_test.go
index f1d78bdc7ed..b862b8031f7 100644
--- a/github/pulls_test.go
+++ b/github/pulls_test.go
@@ -6,6 +6,7 @@
package github
import (
+ "context"
"encoding/json"
"fmt"
"io"
@@ -33,7 +34,7 @@ func TestPullRequestsService_List(t *testing.T) {
})
opt := &PullRequestListOptions{"closed", "h", "b", "created", "desc", ListOptions{Page: 2}}
- pulls, _, err := client.PullRequests.List("o", "r", opt)
+ pulls, _, err := client.PullRequests.List(context.Background(), "o", "r", opt)
if err != nil {
t.Errorf("PullRequests.List returned error: %v", err)
}
@@ -45,7 +46,7 @@ func TestPullRequestsService_List(t *testing.T) {
}
func TestPullRequestsService_List_invalidOwner(t *testing.T) {
- _, _, err := client.PullRequests.List("%", "r", nil)
+ _, _, err := client.PullRequests.List(context.Background(), "%", "r", nil)
testURLParseError(t, err)
}
@@ -58,7 +59,7 @@ func TestPullRequestsService_Get(t *testing.T) {
fmt.Fprint(w, `{"number":1}`)
})
- pull, _, err := client.PullRequests.Get("o", "r", 1)
+ pull, _, err := client.PullRequests.Get(context.Background(), "o", "r", 1)
if err != nil {
t.Errorf("PullRequests.Get returned error: %v", err)
}
@@ -80,7 +81,7 @@ func TestPullRequestsService_GetRawDiff(t *testing.T) {
fmt.Fprint(w, rawStr)
})
- ret, _, err := client.PullRequests.GetRaw("o", "r", 1, RawOptions{Diff})
+ ret, _, err := client.PullRequests.GetRaw(context.Background(), "o", "r", 1, RawOptions{Diff})
if err != nil {
t.Fatalf("PullRequests.GetRaw returned error: %v", err)
}
@@ -101,7 +102,7 @@ func TestPullRequestsService_GetRawPatch(t *testing.T) {
fmt.Fprint(w, rawStr)
})
- ret, _, err := client.PullRequests.GetRaw("o", "r", 1, RawOptions{Patch})
+ ret, _, err := client.PullRequests.GetRaw(context.Background(), "o", "r", 1, RawOptions{Patch})
if err != nil {
t.Fatalf("PullRequests.GetRaw returned error: %v", err)
}
@@ -115,7 +116,7 @@ func TestPullRequestsService_GetRawInvalid(t *testing.T) {
setup()
defer teardown()
- _, _, err := client.PullRequests.GetRaw("o", "r", 1, RawOptions{100})
+ _, _, err := client.PullRequests.GetRaw(context.Background(), "o", "r", 1, RawOptions{100})
if err == nil {
t.Fatal("PullRequests.GetRaw should return error")
}
@@ -133,7 +134,7 @@ func TestPullRequestsService_Get_headAndBase(t *testing.T) {
fmt.Fprint(w, `{"number":1,"head":{"ref":"r2","repo":{"id":2}},"base":{"ref":"r1","repo":{"id":1}}}`)
})
- pull, _, err := client.PullRequests.Get("o", "r", 1)
+ pull, _, err := client.PullRequests.Get(context.Background(), "o", "r", 1)
if err != nil {
t.Errorf("PullRequests.Get returned error: %v", err)
}
@@ -171,7 +172,7 @@ func TestPullRequestsService_Get_urlFields(t *testing.T) {
"review_comment_url": "https://api.github.com/repos/octocat/Hello-World/pulls/comments{/number}"}`)
})
- pull, _, err := client.PullRequests.Get("o", "r", 1)
+ pull, _, err := client.PullRequests.Get(context.Background(), "o", "r", 1)
if err != nil {
t.Errorf("PullRequests.Get returned error: %v", err)
}
@@ -194,7 +195,7 @@ func TestPullRequestsService_Get_urlFields(t *testing.T) {
}
func TestPullRequestsService_Get_invalidOwner(t *testing.T) {
- _, _, err := client.PullRequests.Get("%", "r", 1)
+ _, _, err := client.PullRequests.Get(context.Background(), "%", "r", 1)
testURLParseError(t, err)
}
@@ -216,7 +217,7 @@ func TestPullRequestsService_Create(t *testing.T) {
fmt.Fprint(w, `{"number":1}`)
})
- pull, _, err := client.PullRequests.Create("o", "r", input)
+ pull, _, err := client.PullRequests.Create(context.Background(), "o", "r", input)
if err != nil {
t.Errorf("PullRequests.Create returned error: %v", err)
}
@@ -228,7 +229,7 @@ func TestPullRequestsService_Create(t *testing.T) {
}
func TestPullRequestsService_Create_invalidOwner(t *testing.T) {
- _, _, err := client.PullRequests.Create("%", "r", nil)
+ _, _, err := client.PullRequests.Create(context.Background(), "%", "r", nil)
testURLParseError(t, err)
}
@@ -276,7 +277,7 @@ func TestPullRequestsService_Edit(t *testing.T) {
madeRequest = true
})
- pull, _, err := client.PullRequests.Edit("o", "r", i, tt.input)
+ pull, _, err := client.PullRequests.Edit(context.Background(), "o", "r", i, tt.input)
if err != nil {
t.Errorf("%d: PullRequests.Edit returned error: %v", i, err)
}
@@ -292,7 +293,7 @@ func TestPullRequestsService_Edit(t *testing.T) {
}
func TestPullRequestsService_Edit_invalidOwner(t *testing.T) {
- _, _, err := client.PullRequests.Edit("%", "r", 1, nil)
+ _, _, err := client.PullRequests.Edit(context.Background(), "%", "r", 1, nil)
testURLParseError(t, err)
}
@@ -325,7 +326,7 @@ func TestPullRequestsService_ListCommits(t *testing.T) {
})
opt := &ListOptions{Page: 2}
- commits, _, err := client.PullRequests.ListCommits("o", "r", 1, opt)
+ commits, _, err := client.PullRequests.ListCommits(context.Background(), "o", "r", 1, opt)
if err != nil {
t.Errorf("PullRequests.ListCommits returned error: %v", err)
}
@@ -384,7 +385,7 @@ func TestPullRequestsService_ListFiles(t *testing.T) {
})
opt := &ListOptions{Page: 2}
- commitFiles, _, err := client.PullRequests.ListFiles("o", "r", 1, opt)
+ commitFiles, _, err := client.PullRequests.ListFiles(context.Background(), "o", "r", 1, opt)
if err != nil {
t.Errorf("PullRequests.ListFiles returned error: %v", err)
}
@@ -424,7 +425,7 @@ func TestPullRequestsService_IsMerged(t *testing.T) {
w.WriteHeader(http.StatusNoContent)
})
- isMerged, _, err := client.PullRequests.IsMerged("o", "r", 1)
+ isMerged, _, err := client.PullRequests.IsMerged(context.Background(), "o", "r", 1)
if err != nil {
t.Errorf("PullRequests.IsMerged returned error: %v", err)
}
@@ -451,7 +452,7 @@ func TestPullRequestsService_Merge(t *testing.T) {
})
options := &PullRequestOptions{MergeMethod: "rebase"}
- merge, _, err := client.PullRequests.Merge("o", "r", 1, "merging pull request", options)
+ merge, _, err := client.PullRequests.Merge(context.Background(), "o", "r", 1, "merging pull request", options)
if err != nil {
t.Errorf("PullRequests.Merge returned error: %v", err)
}
@@ -509,7 +510,7 @@ func TestPullRequestsService_Merge_options(t *testing.T) {
testBody(t, r, test.wantBody+"\n")
madeRequest = true
})
- _, _, _ = client.PullRequests.Merge("o", "r", i, "merging pull request", test.options)
+ _, _, _ = client.PullRequests.Merge(context.Background(), "o", "r", i, "merging pull request", test.options)
if !madeRequest {
t.Errorf("%d: PullRequests.Merge(%#v): expected request was not made", i, test.options)
}
diff --git a/github/reactions.go b/github/reactions.go
index 03b131be900..739413d716e 100644
--- a/github/reactions.go
+++ b/github/reactions.go
@@ -5,7 +5,10 @@
package github
-import "fmt"
+import (
+ "context"
+ "fmt"
+)
// ReactionsService provides access to the reactions-related functions in the
// GitHub API.
@@ -43,7 +46,7 @@ func (r Reaction) String() string {
// ListCommentReactions lists the reactions for a commit comment.
//
// GitHub API docs: https://developer.github.com/v3/reactions/#list-reactions-for-a-commit-comment
-func (s *ReactionsService) ListCommentReactions(owner, repo string, id int, opt *ListOptions) ([]*Reaction, *Response, error) {
+func (s *ReactionsService) ListCommentReactions(ctx context.Context, owner, repo string, id int, opt *ListOptions) ([]*Reaction, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/comments/%v/reactions", owner, repo, id)
u, err := addOptions(u, opt)
if err != nil {
@@ -59,7 +62,7 @@ func (s *ReactionsService) ListCommentReactions(owner, repo string, id int, opt
req.Header.Set("Accept", mediaTypeReactionsPreview)
var m []*Reaction
- resp, err := s.client.Do(req, &m)
+ resp, err := s.client.Do(ctx, req, &m)
if err != nil {
return nil, resp, err
}
@@ -72,7 +75,7 @@ func (s *ReactionsService) ListCommentReactions(owner, repo string, id int, opt
// previously created reaction will be returned with Status: 200 OK.
//
// GitHub API docs: https://developer.github.com/v3/reactions/#create-reaction-for-a-commit-comment
-func (s ReactionsService) CreateCommentReaction(owner, repo string, id int, content string) (*Reaction, *Response, error) {
+func (s ReactionsService) CreateCommentReaction(ctx context.Context, owner, repo string, id int, content string) (*Reaction, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/comments/%v/reactions", owner, repo, id)
body := &Reaction{Content: String(content)}
@@ -85,7 +88,7 @@ func (s ReactionsService) CreateCommentReaction(owner, repo string, id int, cont
req.Header.Set("Accept", mediaTypeReactionsPreview)
m := &Reaction{}
- resp, err := s.client.Do(req, m)
+ resp, err := s.client.Do(ctx, req, m)
if err != nil {
return nil, resp, err
}
@@ -96,7 +99,7 @@ func (s ReactionsService) CreateCommentReaction(owner, repo string, id int, cont
// ListIssueReactions lists the reactions for an issue.
//
// GitHub API docs: https://developer.github.com/v3/reactions/#list-reactions-for-an-issue
-func (s *ReactionsService) ListIssueReactions(owner, repo string, number int, opt *ListOptions) ([]*Reaction, *Response, error) {
+func (s *ReactionsService) ListIssueReactions(ctx context.Context, owner, repo string, number int, opt *ListOptions) ([]*Reaction, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/issues/%v/reactions", owner, repo, number)
u, err := addOptions(u, opt)
if err != nil {
@@ -112,7 +115,7 @@ func (s *ReactionsService) ListIssueReactions(owner, repo string, number int, op
req.Header.Set("Accept", mediaTypeReactionsPreview)
var m []*Reaction
- resp, err := s.client.Do(req, &m)
+ resp, err := s.client.Do(ctx, req, &m)
if err != nil {
return nil, resp, err
}
@@ -125,7 +128,7 @@ func (s *ReactionsService) ListIssueReactions(owner, repo string, number int, op
// previously created reaction will be returned with Status: 200 OK.
//
// GitHub API docs: https://developer.github.com/v3/reactions/#create-reaction-for-an-issue
-func (s ReactionsService) CreateIssueReaction(owner, repo string, number int, content string) (*Reaction, *Response, error) {
+func (s ReactionsService) CreateIssueReaction(ctx context.Context, owner, repo string, number int, content string) (*Reaction, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/issues/%v/reactions", owner, repo, number)
body := &Reaction{Content: String(content)}
@@ -138,7 +141,7 @@ func (s ReactionsService) CreateIssueReaction(owner, repo string, number int, co
req.Header.Set("Accept", mediaTypeReactionsPreview)
m := &Reaction{}
- resp, err := s.client.Do(req, m)
+ resp, err := s.client.Do(ctx, req, m)
if err != nil {
return nil, resp, err
}
@@ -149,7 +152,7 @@ func (s ReactionsService) CreateIssueReaction(owner, repo string, number int, co
// ListIssueCommentReactions lists the reactions for an issue comment.
//
// GitHub API docs: https://developer.github.com/v3/reactions/#list-reactions-for-an-issue-comment
-func (s *ReactionsService) ListIssueCommentReactions(owner, repo string, id int, opt *ListOptions) ([]*Reaction, *Response, error) {
+func (s *ReactionsService) ListIssueCommentReactions(ctx context.Context, owner, repo string, id int, opt *ListOptions) ([]*Reaction, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/issues/comments/%v/reactions", owner, repo, id)
u, err := addOptions(u, opt)
if err != nil {
@@ -165,7 +168,7 @@ func (s *ReactionsService) ListIssueCommentReactions(owner, repo string, id int,
req.Header.Set("Accept", mediaTypeReactionsPreview)
var m []*Reaction
- resp, err := s.client.Do(req, &m)
+ resp, err := s.client.Do(ctx, req, &m)
if err != nil {
return nil, resp, err
}
@@ -178,7 +181,7 @@ func (s *ReactionsService) ListIssueCommentReactions(owner, repo string, id int,
// previously created reaction will be returned with Status: 200 OK.
//
// GitHub API docs: https://developer.github.com/v3/reactions/#create-reaction-for-an-issue-comment
-func (s ReactionsService) CreateIssueCommentReaction(owner, repo string, id int, content string) (*Reaction, *Response, error) {
+func (s ReactionsService) CreateIssueCommentReaction(ctx context.Context, owner, repo string, id int, content string) (*Reaction, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/issues/comments/%v/reactions", owner, repo, id)
body := &Reaction{Content: String(content)}
@@ -191,7 +194,7 @@ func (s ReactionsService) CreateIssueCommentReaction(owner, repo string, id int,
req.Header.Set("Accept", mediaTypeReactionsPreview)
m := &Reaction{}
- resp, err := s.client.Do(req, m)
+ resp, err := s.client.Do(ctx, req, m)
if err != nil {
return nil, resp, err
}
@@ -202,7 +205,7 @@ func (s ReactionsService) CreateIssueCommentReaction(owner, repo string, id int,
// ListPullRequestCommentReactions lists the reactions for a pull request review comment.
//
// GitHub API docs: https://developer.github.com/v3/reactions/#list-reactions-for-an-issue-comment
-func (s *ReactionsService) ListPullRequestCommentReactions(owner, repo string, id int, opt *ListOptions) ([]*Reaction, *Response, error) {
+func (s *ReactionsService) ListPullRequestCommentReactions(ctx context.Context, owner, repo string, id int, opt *ListOptions) ([]*Reaction, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/pulls/comments/%v/reactions", owner, repo, id)
u, err := addOptions(u, opt)
if err != nil {
@@ -218,7 +221,7 @@ func (s *ReactionsService) ListPullRequestCommentReactions(owner, repo string, i
req.Header.Set("Accept", mediaTypeReactionsPreview)
var m []*Reaction
- resp, err := s.client.Do(req, &m)
+ resp, err := s.client.Do(ctx, req, &m)
if err != nil {
return nil, resp, err
}
@@ -231,7 +234,7 @@ func (s *ReactionsService) ListPullRequestCommentReactions(owner, repo string, i
// previously created reaction will be returned with Status: 200 OK.
//
// GitHub API docs: https://developer.github.com/v3/reactions/#create-reaction-for-an-issue-comment
-func (s ReactionsService) CreatePullRequestCommentReaction(owner, repo string, id int, content string) (*Reaction, *Response, error) {
+func (s ReactionsService) CreatePullRequestCommentReaction(ctx context.Context, owner, repo string, id int, content string) (*Reaction, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/pulls/comments/%v/reactions", owner, repo, id)
body := &Reaction{Content: String(content)}
@@ -244,7 +247,7 @@ func (s ReactionsService) CreatePullRequestCommentReaction(owner, repo string, i
req.Header.Set("Accept", mediaTypeReactionsPreview)
m := &Reaction{}
- resp, err := s.client.Do(req, m)
+ resp, err := s.client.Do(ctx, req, m)
if err != nil {
return nil, resp, err
}
@@ -255,7 +258,7 @@ func (s ReactionsService) CreatePullRequestCommentReaction(owner, repo string, i
// DeleteReaction deletes a reaction.
//
// GitHub API docs: https://developer.github.com/v3/reaction/reactions/#delete-a-reaction-archive
-func (s *ReactionsService) DeleteReaction(id int) (*Response, error) {
+func (s *ReactionsService) DeleteReaction(ctx context.Context, id int) (*Response, error) {
u := fmt.Sprintf("reactions/%v", id)
req, err := s.client.NewRequest("DELETE", u, nil)
@@ -266,5 +269,5 @@ func (s *ReactionsService) DeleteReaction(id int) (*Response, error) {
// TODO: remove custom Accept header when this API fully launches.
req.Header.Set("Accept", mediaTypeReactionsPreview)
- return s.client.Do(req, nil)
+ return s.client.Do(ctx, req, nil)
}
diff --git a/github/reactions_test.go b/github/reactions_test.go
index 91ef9b50fab..2725298279e 100644
--- a/github/reactions_test.go
+++ b/github/reactions_test.go
@@ -6,6 +6,7 @@
package github
import (
+ "context"
"net/http"
"reflect"
"testing"
@@ -23,7 +24,7 @@ func TestReactionsService_ListCommentReactions(t *testing.T) {
w.Write([]byte(`[{"id":1,"user":{"login":"l","id":2},"content":"+1"}]`))
})
- got, _, err := client.Reactions.ListCommentReactions("o", "r", 1, nil)
+ got, _, err := client.Reactions.ListCommentReactions(context.Background(), "o", "r", 1, nil)
if err != nil {
t.Errorf("ListCommentReactions returned error: %v", err)
}
@@ -44,7 +45,7 @@ func TestReactionsService_CreateCommentReaction(t *testing.T) {
w.Write([]byte(`{"id":1,"user":{"login":"l","id":2},"content":"+1"}`))
})
- got, _, err := client.Reactions.CreateCommentReaction("o", "r", 1, "+1")
+ got, _, err := client.Reactions.CreateCommentReaction(context.Background(), "o", "r", 1, "+1")
if err != nil {
t.Errorf("CreateCommentReaction returned error: %v", err)
}
@@ -66,7 +67,7 @@ func TestReactionsService_ListIssueReactions(t *testing.T) {
w.Write([]byte(`[{"id":1,"user":{"login":"l","id":2},"content":"+1"}]`))
})
- got, _, err := client.Reactions.ListIssueReactions("o", "r", 1, nil)
+ got, _, err := client.Reactions.ListIssueReactions(context.Background(), "o", "r", 1, nil)
if err != nil {
t.Errorf("ListIssueReactions returned error: %v", err)
}
@@ -87,7 +88,7 @@ func TestReactionsService_CreateIssueReaction(t *testing.T) {
w.Write([]byte(`{"id":1,"user":{"login":"l","id":2},"content":"+1"}`))
})
- got, _, err := client.Reactions.CreateIssueReaction("o", "r", 1, "+1")
+ got, _, err := client.Reactions.CreateIssueReaction(context.Background(), "o", "r", 1, "+1")
if err != nil {
t.Errorf("CreateIssueReaction returned error: %v", err)
}
@@ -109,7 +110,7 @@ func TestReactionsService_ListIssueCommentReactions(t *testing.T) {
w.Write([]byte(`[{"id":1,"user":{"login":"l","id":2},"content":"+1"}]`))
})
- got, _, err := client.Reactions.ListIssueCommentReactions("o", "r", 1, nil)
+ got, _, err := client.Reactions.ListIssueCommentReactions(context.Background(), "o", "r", 1, nil)
if err != nil {
t.Errorf("ListIssueCommentReactions returned error: %v", err)
}
@@ -130,7 +131,7 @@ func TestReactionsService_CreateIssueCommentReaction(t *testing.T) {
w.Write([]byte(`{"id":1,"user":{"login":"l","id":2},"content":"+1"}`))
})
- got, _, err := client.Reactions.CreateIssueCommentReaction("o", "r", 1, "+1")
+ got, _, err := client.Reactions.CreateIssueCommentReaction(context.Background(), "o", "r", 1, "+1")
if err != nil {
t.Errorf("CreateIssueCommentReaction returned error: %v", err)
}
@@ -152,7 +153,7 @@ func TestReactionsService_ListPullRequestCommentReactions(t *testing.T) {
w.Write([]byte(`[{"id":1,"user":{"login":"l","id":2},"content":"+1"}]`))
})
- got, _, err := client.Reactions.ListPullRequestCommentReactions("o", "r", 1, nil)
+ got, _, err := client.Reactions.ListPullRequestCommentReactions(context.Background(), "o", "r", 1, nil)
if err != nil {
t.Errorf("ListPullRequestCommentReactions returned error: %v", err)
}
@@ -173,7 +174,7 @@ func TestReactionsService_CreatePullRequestCommentReaction(t *testing.T) {
w.Write([]byte(`{"id":1,"user":{"login":"l","id":2},"content":"+1"}`))
})
- got, _, err := client.Reactions.CreatePullRequestCommentReaction("o", "r", 1, "+1")
+ got, _, err := client.Reactions.CreatePullRequestCommentReaction(context.Background(), "o", "r", 1, "+1")
if err != nil {
t.Errorf("CreatePullRequestCommentReaction returned error: %v", err)
}
@@ -194,7 +195,7 @@ func TestReactionsService_DeleteReaction(t *testing.T) {
w.WriteHeader(http.StatusNoContent)
})
- if _, err := client.Reactions.DeleteReaction(1); err != nil {
+ if _, err := client.Reactions.DeleteReaction(context.Background(), 1); err != nil {
t.Errorf("DeleteReaction returned error: %v", err)
}
}
diff --git a/github/repos.go b/github/repos.go
index 58d27f124f0..d69b7c75bec 100644
--- a/github/repos.go
+++ b/github/repos.go
@@ -6,6 +6,7 @@
package github
import (
+ "context"
"fmt"
"strings"
)
@@ -155,7 +156,7 @@ type RepositoryListOptions struct {
// repositories for the authenticated user.
//
// GitHub API docs: https://developer.github.com/v3/repos/#list-user-repositories
-func (s *RepositoriesService) List(user string, opt *RepositoryListOptions) ([]*Repository, *Response, error) {
+func (s *RepositoriesService) List(ctx context.Context, user string, opt *RepositoryListOptions) ([]*Repository, *Response, error) {
var u string
if user != "" {
u = fmt.Sprintf("users/%v/repos", user)
@@ -176,7 +177,7 @@ func (s *RepositoriesService) List(user string, opt *RepositoryListOptions) ([]*
req.Header.Set("Accept", mediaTypeLicensesPreview)
var repos []*Repository
- resp, err := s.client.Do(req, &repos)
+ resp, err := s.client.Do(ctx, req, &repos)
if err != nil {
return nil, resp, err
}
@@ -197,7 +198,7 @@ type RepositoryListByOrgOptions struct {
// ListByOrg lists the repositories for an organization.
//
// GitHub API docs: https://developer.github.com/v3/repos/#list-organization-repositories
-func (s *RepositoriesService) ListByOrg(org string, opt *RepositoryListByOrgOptions) ([]*Repository, *Response, error) {
+func (s *RepositoriesService) ListByOrg(ctx context.Context, org string, opt *RepositoryListByOrgOptions) ([]*Repository, *Response, error) {
u := fmt.Sprintf("orgs/%v/repos", org)
u, err := addOptions(u, opt)
if err != nil {
@@ -213,7 +214,7 @@ func (s *RepositoriesService) ListByOrg(org string, opt *RepositoryListByOrgOpti
req.Header.Set("Accept", mediaTypeLicensesPreview)
var repos []*Repository
- resp, err := s.client.Do(req, &repos)
+ resp, err := s.client.Do(ctx, req, &repos)
if err != nil {
return nil, resp, err
}
@@ -233,7 +234,7 @@ type RepositoryListAllOptions struct {
// ListAll lists all GitHub repositories in the order that they were created.
//
// GitHub API docs: https://developer.github.com/v3/repos/#list-all-public-repositories
-func (s *RepositoriesService) ListAll(opt *RepositoryListAllOptions) ([]*Repository, *Response, error) {
+func (s *RepositoriesService) ListAll(ctx context.Context, opt *RepositoryListAllOptions) ([]*Repository, *Response, error) {
u, err := addOptions("repositories", opt)
if err != nil {
return nil, nil, err
@@ -245,7 +246,7 @@ func (s *RepositoriesService) ListAll(opt *RepositoryListAllOptions) ([]*Reposit
}
var repos []*Repository
- resp, err := s.client.Do(req, &repos)
+ resp, err := s.client.Do(ctx, req, &repos)
if err != nil {
return nil, resp, err
}
@@ -258,7 +259,7 @@ func (s *RepositoriesService) ListAll(opt *RepositoryListAllOptions) ([]*Reposit
// specified, it will be created for the authenticated user.
//
// GitHub API docs: https://developer.github.com/v3/repos/#create
-func (s *RepositoriesService) Create(org string, repo *Repository) (*Repository, *Response, error) {
+func (s *RepositoriesService) Create(ctx context.Context, org string, repo *Repository) (*Repository, *Response, error) {
var u string
if org != "" {
u = fmt.Sprintf("orgs/%v/repos", org)
@@ -272,7 +273,7 @@ func (s *RepositoriesService) Create(org string, repo *Repository) (*Repository,
}
r := new(Repository)
- resp, err := s.client.Do(req, r)
+ resp, err := s.client.Do(ctx, req, r)
if err != nil {
return nil, resp, err
}
@@ -283,7 +284,7 @@ func (s *RepositoriesService) Create(org string, repo *Repository) (*Repository,
// Get fetches a repository.
//
// GitHub API docs: https://developer.github.com/v3/repos/#get
-func (s *RepositoriesService) Get(owner, repo string) (*Repository, *Response, error) {
+func (s *RepositoriesService) Get(ctx context.Context, owner, repo string) (*Repository, *Response, error) {
u := fmt.Sprintf("repos/%v/%v", owner, repo)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
@@ -296,7 +297,7 @@ func (s *RepositoriesService) Get(owner, repo string) (*Repository, *Response, e
req.Header.Set("Accept", strings.Join(acceptHeaders, ", "))
repository := new(Repository)
- resp, err := s.client.Do(req, repository)
+ resp, err := s.client.Do(ctx, req, repository)
if err != nil {
return nil, resp, err
}
@@ -307,7 +308,7 @@ func (s *RepositoriesService) Get(owner, repo string) (*Repository, *Response, e
// GetByID fetches a repository.
//
// Note: GetByID uses the undocumented GitHub API endpoint /repositories/:id.
-func (s *RepositoriesService) GetByID(id int) (*Repository, *Response, error) {
+func (s *RepositoriesService) GetByID(ctx context.Context, id int) (*Repository, *Response, error) {
u := fmt.Sprintf("repositories/%d", id)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
@@ -319,7 +320,7 @@ func (s *RepositoriesService) GetByID(id int) (*Repository, *Response, error) {
req.Header.Set("Accept", mediaTypeLicensesPreview)
repository := new(Repository)
- resp, err := s.client.Do(req, repository)
+ resp, err := s.client.Do(ctx, req, repository)
if err != nil {
return nil, resp, err
}
@@ -330,7 +331,7 @@ func (s *RepositoriesService) GetByID(id int) (*Repository, *Response, error) {
// Edit updates a repository.
//
// GitHub API docs: https://developer.github.com/v3/repos/#edit
-func (s *RepositoriesService) Edit(owner, repo string, repository *Repository) (*Repository, *Response, error) {
+func (s *RepositoriesService) Edit(ctx context.Context, owner, repo string, repository *Repository) (*Repository, *Response, error) {
u := fmt.Sprintf("repos/%v/%v", owner, repo)
req, err := s.client.NewRequest("PATCH", u, repository)
if err != nil {
@@ -341,7 +342,7 @@ func (s *RepositoriesService) Edit(owner, repo string, repository *Repository) (
req.Header.Add("Accept", mediaTypeSquashPreview)
r := new(Repository)
- resp, err := s.client.Do(req, r)
+ resp, err := s.client.Do(ctx, req, r)
if err != nil {
return nil, resp, err
}
@@ -352,14 +353,14 @@ func (s *RepositoriesService) Edit(owner, repo string, repository *Repository) (
// Delete a repository.
//
// GitHub API docs: https://developer.github.com/v3/repos/#delete-a-repository
-func (s *RepositoriesService) Delete(owner, repo string) (*Response, error) {
+func (s *RepositoriesService) Delete(ctx context.Context, owner, repo string) (*Response, error) {
u := fmt.Sprintf("repos/%v/%v", owner, repo)
req, err := s.client.NewRequest("DELETE", u, nil)
if err != nil {
return nil, err
}
- return s.client.Do(req, nil)
+ return s.client.Do(ctx, req, nil)
}
// Contributor represents a repository contributor
@@ -396,7 +397,7 @@ type ListContributorsOptions struct {
// ListContributors lists contributors for a repository.
//
// GitHub API docs: https://developer.github.com/v3/repos/#list-contributors
-func (s *RepositoriesService) ListContributors(owner string, repository string, opt *ListContributorsOptions) ([]*Contributor, *Response, error) {
+func (s *RepositoriesService) ListContributors(ctx context.Context, owner string, repository string, opt *ListContributorsOptions) ([]*Contributor, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/contributors", owner, repository)
u, err := addOptions(u, opt)
if err != nil {
@@ -409,7 +410,7 @@ func (s *RepositoriesService) ListContributors(owner string, repository string,
}
var contributor []*Contributor
- resp, err := s.client.Do(req, &contributor)
+ resp, err := s.client.Do(ctx, req, &contributor)
if err != nil {
return nil, nil, err
}
@@ -427,7 +428,7 @@ func (s *RepositoriesService) ListContributors(owner string, repository string,
// }
//
// GitHub API Docs: https://developer.github.com/v3/repos/#list-languages
-func (s *RepositoriesService) ListLanguages(owner string, repo string) (map[string]int, *Response, error) {
+func (s *RepositoriesService) ListLanguages(ctx context.Context, owner string, repo string) (map[string]int, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/languages", owner, repo)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
@@ -435,7 +436,7 @@ func (s *RepositoriesService) ListLanguages(owner string, repo string) (map[stri
}
languages := make(map[string]int)
- resp, err := s.client.Do(req, &languages)
+ resp, err := s.client.Do(ctx, req, &languages)
if err != nil {
return nil, resp, err
}
@@ -446,7 +447,7 @@ func (s *RepositoriesService) ListLanguages(owner string, repo string) (map[stri
// ListTeams lists the teams for the specified repository.
//
// GitHub API docs: https://developer.github.com/v3/repos/#list-teams
-func (s *RepositoriesService) ListTeams(owner string, repo string, opt *ListOptions) ([]*Team, *Response, error) {
+func (s *RepositoriesService) ListTeams(ctx context.Context, owner string, repo string, opt *ListOptions) ([]*Team, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/teams", owner, repo)
u, err := addOptions(u, opt)
if err != nil {
@@ -459,7 +460,7 @@ func (s *RepositoriesService) ListTeams(owner string, repo string, opt *ListOpti
}
var teams []*Team
- resp, err := s.client.Do(req, &teams)
+ resp, err := s.client.Do(ctx, req, &teams)
if err != nil {
return nil, resp, err
}
@@ -478,7 +479,7 @@ type RepositoryTag struct {
// ListTags lists tags for the specified repository.
//
// GitHub API docs: https://developer.github.com/v3/repos/#list-tags
-func (s *RepositoriesService) ListTags(owner string, repo string, opt *ListOptions) ([]*RepositoryTag, *Response, error) {
+func (s *RepositoriesService) ListTags(ctx context.Context, owner string, repo string, opt *ListOptions) ([]*RepositoryTag, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/tags", owner, repo)
u, err := addOptions(u, opt)
if err != nil {
@@ -491,7 +492,7 @@ func (s *RepositoriesService) ListTags(owner string, repo string, opt *ListOptio
}
var tags []*RepositoryTag
- resp, err := s.client.Do(req, &tags)
+ resp, err := s.client.Do(ctx, req, &tags)
if err != nil {
return nil, resp, err
}
@@ -560,7 +561,7 @@ type BranchRestrictionsRequest struct {
// ListBranches lists branches for the specified repository.
//
// GitHub API docs: https://developer.github.com/v3/repos/#list-branches
-func (s *RepositoriesService) ListBranches(owner string, repo string, opt *ListOptions) ([]*Branch, *Response, error) {
+func (s *RepositoriesService) ListBranches(ctx context.Context, owner string, repo string, opt *ListOptions) ([]*Branch, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/branches", owner, repo)
u, err := addOptions(u, opt)
if err != nil {
@@ -576,7 +577,7 @@ func (s *RepositoriesService) ListBranches(owner string, repo string, opt *ListO
req.Header.Set("Accept", mediaTypeProtectedBranchesPreview)
var branches []*Branch
- resp, err := s.client.Do(req, &branches)
+ resp, err := s.client.Do(ctx, req, &branches)
if err != nil {
return nil, resp, err
}
@@ -587,7 +588,7 @@ func (s *RepositoriesService) ListBranches(owner string, repo string, opt *ListO
// GetBranch gets the specified branch for a repository.
//
// GitHub API docs: https://developer.github.com/v3/repos/#get-branch
-func (s *RepositoriesService) GetBranch(owner, repo, branch string) (*Branch, *Response, error) {
+func (s *RepositoriesService) GetBranch(ctx context.Context, owner, repo, branch string) (*Branch, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/branches/%v", owner, repo, branch)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
@@ -598,7 +599,7 @@ func (s *RepositoriesService) GetBranch(owner, repo, branch string) (*Branch, *R
req.Header.Set("Accept", mediaTypeProtectedBranchesPreview)
b := new(Branch)
- resp, err := s.client.Do(req, b)
+ resp, err := s.client.Do(ctx, req, b)
if err != nil {
return nil, resp, err
}
@@ -609,7 +610,7 @@ func (s *RepositoriesService) GetBranch(owner, repo, branch string) (*Branch, *R
// GetBranchProtection gets the protection of a given branch.
//
// GitHub API docs: https://developer.github.com/v3/repos/branches/#get-branch-protection
-func (s *RepositoriesService) GetBranchProtection(owner, repo, branch string) (*Protection, *Response, error) {
+func (s *RepositoriesService) GetBranchProtection(ctx context.Context, owner, repo, branch string) (*Protection, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/branches/%v/protection", owner, repo, branch)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
@@ -620,7 +621,7 @@ func (s *RepositoriesService) GetBranchProtection(owner, repo, branch string) (*
req.Header.Set("Accept", mediaTypeProtectedBranchesPreview)
p := new(Protection)
- resp, err := s.client.Do(req, p)
+ resp, err := s.client.Do(ctx, req, p)
if err != nil {
return nil, resp, err
}
@@ -631,7 +632,7 @@ func (s *RepositoriesService) GetBranchProtection(owner, repo, branch string) (*
// UpdateBranchProtection updates the protection of a given branch.
//
// GitHub API docs: https://developer.github.com/v3/repos/branches/#update-branch-protection
-func (s *RepositoriesService) UpdateBranchProtection(owner, repo, branch string, preq *ProtectionRequest) (*Protection, *Response, error) {
+func (s *RepositoriesService) UpdateBranchProtection(ctx context.Context, owner, repo, branch string, preq *ProtectionRequest) (*Protection, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/branches/%v/protection", owner, repo, branch)
req, err := s.client.NewRequest("PUT", u, preq)
if err != nil {
@@ -642,7 +643,7 @@ func (s *RepositoriesService) UpdateBranchProtection(owner, repo, branch string,
req.Header.Set("Accept", mediaTypeProtectedBranchesPreview)
p := new(Protection)
- resp, err := s.client.Do(req, p)
+ resp, err := s.client.Do(ctx, req, p)
if err != nil {
return nil, resp, err
}
@@ -653,7 +654,7 @@ func (s *RepositoriesService) UpdateBranchProtection(owner, repo, branch string,
// RemoveBranchProtection removes the protection of a given branch.
//
// GitHub API docs: https://developer.github.com/v3/repos/branches/#remove-branch-protection
-func (s *RepositoriesService) RemoveBranchProtection(owner, repo, branch string) (*Response, error) {
+func (s *RepositoriesService) RemoveBranchProtection(ctx context.Context, owner, repo, branch string) (*Response, error) {
u := fmt.Sprintf("repos/%v/%v/branches/%v/protection", owner, repo, branch)
req, err := s.client.NewRequest("DELETE", u, nil)
if err != nil {
@@ -663,13 +664,13 @@ func (s *RepositoriesService) RemoveBranchProtection(owner, repo, branch string)
// TODO: remove custom Accept header when this API fully launches
req.Header.Set("Accept", mediaTypeProtectedBranchesPreview)
- return s.client.Do(req, nil)
+ return s.client.Do(ctx, req, nil)
}
// License gets the contents of a repository's license if one is detected.
//
// GitHub API docs: https://developer.github.com/v3/licenses/#get-the-contents-of-a-repositorys-license
-func (s *RepositoriesService) License(owner, repo string) (*RepositoryLicense, *Response, error) {
+func (s *RepositoriesService) License(ctx context.Context, owner, repo string) (*RepositoryLicense, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/license", owner, repo)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
@@ -677,7 +678,7 @@ func (s *RepositoriesService) License(owner, repo string) (*RepositoryLicense, *
}
r := &RepositoryLicense{}
- resp, err := s.client.Do(req, r)
+ resp, err := s.client.Do(ctx, req, r)
if err != nil {
return nil, resp, err
}
diff --git a/github/repos_collaborators.go b/github/repos_collaborators.go
index ddb88f578d3..04d3f3219a2 100644
--- a/github/repos_collaborators.go
+++ b/github/repos_collaborators.go
@@ -5,12 +5,15 @@
package github
-import "fmt"
+import (
+ "context"
+ "fmt"
+)
// ListCollaborators lists the Github users that have access to the repository.
//
// GitHub API docs: https://developer.github.com/v3/repos/collaborators/#list
-func (s *RepositoriesService) ListCollaborators(owner, repo string, opt *ListOptions) ([]*User, *Response, error) {
+func (s *RepositoriesService) ListCollaborators(ctx context.Context, owner, repo string, opt *ListOptions) ([]*User, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/collaborators", owner, repo)
u, err := addOptions(u, opt)
if err != nil {
@@ -23,7 +26,7 @@ func (s *RepositoriesService) ListCollaborators(owner, repo string, opt *ListOpt
}
var users []*User
- resp, err := s.client.Do(req, &users)
+ resp, err := s.client.Do(ctx, req, &users)
if err != nil {
return nil, resp, err
}
@@ -37,14 +40,14 @@ func (s *RepositoriesService) ListCollaborators(owner, repo string, opt *ListOpt
// is not a GitHub user.
//
// GitHub API docs: https://developer.github.com/v3/repos/collaborators/#get
-func (s *RepositoriesService) IsCollaborator(owner, repo, user string) (bool, *Response, error) {
+func (s *RepositoriesService) IsCollaborator(ctx context.Context, owner, repo, user string) (bool, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/collaborators/%v", owner, repo, user)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return false, nil, err
}
- resp, err := s.client.Do(req, nil)
+ resp, err := s.client.Do(ctx, req, nil)
isCollab, err := parseBoolResponse(err)
return isCollab, resp, err
}
@@ -60,7 +63,7 @@ type RepositoryPermissionLevel struct {
// GetPermissionLevel retrieves the specific permission level a collaborator has for a given repository.
// GitHub API docs: https://developer.github.com/v3/repos/collaborators/#review-a-users-permission-level
-func (s *RepositoriesService) GetPermissionLevel(owner, repo, user string) (*RepositoryPermissionLevel, *Response, error) {
+func (s *RepositoriesService) GetPermissionLevel(ctx context.Context, owner, repo, user string) (*RepositoryPermissionLevel, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/collaborators/%v/permission", owner, repo, user)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
@@ -71,7 +74,7 @@ func (s *RepositoriesService) GetPermissionLevel(owner, repo, user string) (*Rep
req.Header.Set("Accept", mediaTypeOrgMembershipPreview)
rpl := new(RepositoryPermissionLevel)
- resp, err := s.client.Do(req, rpl)
+ resp, err := s.client.Do(ctx, req, rpl)
if err != nil {
return nil, resp, err
}
@@ -94,7 +97,7 @@ type RepositoryAddCollaboratorOptions struct {
// AddCollaborator adds the specified Github user as collaborator to the given repo.
//
// GitHub API docs: https://developer.github.com/v3/repos/collaborators/#add-user-as-a-collaborator
-func (s *RepositoriesService) AddCollaborator(owner, repo, user string, opt *RepositoryAddCollaboratorOptions) (*Response, error) {
+func (s *RepositoriesService) AddCollaborator(ctx context.Context, owner, repo, user string, opt *RepositoryAddCollaboratorOptions) (*Response, error) {
u := fmt.Sprintf("repos/%v/%v/collaborators/%v", owner, repo, user)
req, err := s.client.NewRequest("PUT", u, opt)
if err != nil {
@@ -104,18 +107,18 @@ func (s *RepositoriesService) AddCollaborator(owner, repo, user string, opt *Rep
// 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)
}
// RemoveCollaborator removes the specified Github user as collaborator from the given repo.
// Note: Does not return error if a valid user that is not a collaborator is removed.
//
// GitHub API docs: https://developer.github.com/v3/repos/collaborators/#remove-collaborator
-func (s *RepositoriesService) RemoveCollaborator(owner, repo, user string) (*Response, error) {
+func (s *RepositoriesService) RemoveCollaborator(ctx context.Context, owner, repo, user string) (*Response, error) {
u := fmt.Sprintf("repos/%v/%v/collaborators/%v", owner, repo, user)
req, err := s.client.NewRequest("DELETE", u, nil)
if err != nil {
return nil, err
}
- return s.client.Do(req, nil)
+ return s.client.Do(ctx, req, nil)
}
diff --git a/github/repos_collaborators_test.go b/github/repos_collaborators_test.go
index 436d6f2607e..d4c70eee723 100644
--- a/github/repos_collaborators_test.go
+++ b/github/repos_collaborators_test.go
@@ -6,6 +6,7 @@
package github
import (
+ "context"
"encoding/json"
"fmt"
"net/http"
@@ -24,7 +25,7 @@ func TestRepositoriesService_ListCollaborators(t *testing.T) {
})
opt := &ListOptions{Page: 2}
- users, _, err := client.Repositories.ListCollaborators("o", "r", opt)
+ users, _, err := client.Repositories.ListCollaborators(context.Background(), "o", "r", opt)
if err != nil {
t.Errorf("Repositories.ListCollaborators returned error: %v", err)
}
@@ -36,7 +37,7 @@ func TestRepositoriesService_ListCollaborators(t *testing.T) {
}
func TestRepositoriesService_ListCollaborators_invalidOwner(t *testing.T) {
- _, _, err := client.Repositories.ListCollaborators("%", "%", nil)
+ _, _, err := client.Repositories.ListCollaborators(context.Background(), "%", "%", nil)
testURLParseError(t, err)
}
@@ -49,7 +50,7 @@ func TestRepositoriesService_IsCollaborator_True(t *testing.T) {
w.WriteHeader(http.StatusNoContent)
})
- isCollab, _, err := client.Repositories.IsCollaborator("o", "r", "u")
+ isCollab, _, err := client.Repositories.IsCollaborator(context.Background(), "o", "r", "u")
if err != nil {
t.Errorf("Repositories.IsCollaborator returned error: %v", err)
}
@@ -68,7 +69,7 @@ func TestRepositoriesService_IsCollaborator_False(t *testing.T) {
w.WriteHeader(http.StatusNotFound)
})
- isCollab, _, err := client.Repositories.IsCollaborator("o", "r", "u")
+ isCollab, _, err := client.Repositories.IsCollaborator(context.Background(), "o", "r", "u")
if err != nil {
t.Errorf("Repositories.IsCollaborator returned error: %v", err)
}
@@ -79,7 +80,7 @@ func TestRepositoriesService_IsCollaborator_False(t *testing.T) {
}
func TestRepositoriesService_IsCollaborator_invalidUser(t *testing.T) {
- _, _, err := client.Repositories.IsCollaborator("%", "%", "%")
+ _, _, err := client.Repositories.IsCollaborator(context.Background(), "%", "%", "%")
testURLParseError(t, err)
}
@@ -93,7 +94,7 @@ func TestRepositoryService_GetPermissionLevel(t *testing.T) {
fmt.Fprintf(w, `{"permission":"admin","user":{"login":"u"}}`)
})
- rpl, _, err := client.Repositories.GetPermissionLevel("o", "r", "u")
+ rpl, _, err := client.Repositories.GetPermissionLevel(context.Background(), "o", "r", "u")
if err != nil {
t.Errorf("Repositories.GetPermissionLevel returned error: %v", err)
}
@@ -129,14 +130,14 @@ func TestRepositoriesService_AddCollaborator(t *testing.T) {
w.WriteHeader(http.StatusNoContent)
})
- _, err := client.Repositories.AddCollaborator("o", "r", "u", opt)
+ _, err := client.Repositories.AddCollaborator(context.Background(), "o", "r", "u", opt)
if err != nil {
t.Errorf("Repositories.AddCollaborator returned error: %v", err)
}
}
func TestRepositoriesService_AddCollaborator_invalidUser(t *testing.T) {
- _, err := client.Repositories.AddCollaborator("%", "%", "%", nil)
+ _, err := client.Repositories.AddCollaborator(context.Background(), "%", "%", "%", nil)
testURLParseError(t, err)
}
@@ -149,13 +150,13 @@ func TestRepositoriesService_RemoveCollaborator(t *testing.T) {
w.WriteHeader(http.StatusNoContent)
})
- _, err := client.Repositories.RemoveCollaborator("o", "r", "u")
+ _, err := client.Repositories.RemoveCollaborator(context.Background(), "o", "r", "u")
if err != nil {
t.Errorf("Repositories.RemoveCollaborator returned error: %v", err)
}
}
func TestRepositoriesService_RemoveCollaborator_invalidUser(t *testing.T) {
- _, err := client.Repositories.RemoveCollaborator("%", "%", "%")
+ _, err := client.Repositories.RemoveCollaborator(context.Background(), "%", "%", "%")
testURLParseError(t, err)
}
diff --git a/github/repos_comments.go b/github/repos_comments.go
index d5917e112d5..4830ee2206d 100644
--- a/github/repos_comments.go
+++ b/github/repos_comments.go
@@ -6,6 +6,7 @@
package github
import (
+ "context"
"fmt"
"time"
)
@@ -35,7 +36,7 @@ func (r RepositoryComment) String() string {
// ListComments lists all the comments for the repository.
//
// GitHub API docs: https://developer.github.com/v3/repos/comments/#list-commit-comments-for-a-repository
-func (s *RepositoriesService) ListComments(owner, repo string, opt *ListOptions) ([]*RepositoryComment, *Response, error) {
+func (s *RepositoriesService) ListComments(ctx context.Context, owner, repo string, opt *ListOptions) ([]*RepositoryComment, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/comments", owner, repo)
u, err := addOptions(u, opt)
if err != nil {
@@ -51,7 +52,7 @@ func (s *RepositoriesService) ListComments(owner, repo string, opt *ListOptions)
req.Header.Set("Accept", mediaTypeReactionsPreview)
var comments []*RepositoryComment
- resp, err := s.client.Do(req, &comments)
+ resp, err := s.client.Do(ctx, req, &comments)
if err != nil {
return nil, resp, err
}
@@ -62,7 +63,7 @@ func (s *RepositoriesService) ListComments(owner, repo string, opt *ListOptions)
// ListCommitComments lists all the comments for a given commit SHA.
//
// GitHub API docs: https://developer.github.com/v3/repos/comments/#list-comments-for-a-single-commit
-func (s *RepositoriesService) ListCommitComments(owner, repo, sha string, opt *ListOptions) ([]*RepositoryComment, *Response, error) {
+func (s *RepositoriesService) ListCommitComments(ctx context.Context, owner, repo, sha string, opt *ListOptions) ([]*RepositoryComment, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/commits/%v/comments", owner, repo, sha)
u, err := addOptions(u, opt)
if err != nil {
@@ -78,7 +79,7 @@ func (s *RepositoriesService) ListCommitComments(owner, repo, sha string, opt *L
req.Header.Set("Accept", mediaTypeReactionsPreview)
var comments []*RepositoryComment
- resp, err := s.client.Do(req, &comments)
+ resp, err := s.client.Do(ctx, req, &comments)
if err != nil {
return nil, resp, err
}
@@ -90,7 +91,7 @@ func (s *RepositoriesService) ListCommitComments(owner, repo, sha string, opt *L
// Note: GitHub allows for comments to be created for non-existing files and positions.
//
// GitHub API docs: https://developer.github.com/v3/repos/comments/#create-a-commit-comment
-func (s *RepositoriesService) CreateComment(owner, repo, sha string, comment *RepositoryComment) (*RepositoryComment, *Response, error) {
+func (s *RepositoriesService) CreateComment(ctx context.Context, owner, repo, sha string, comment *RepositoryComment) (*RepositoryComment, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/commits/%v/comments", owner, repo, sha)
req, err := s.client.NewRequest("POST", u, comment)
if err != nil {
@@ -98,7 +99,7 @@ func (s *RepositoriesService) CreateComment(owner, repo, sha string, comment *Re
}
c := new(RepositoryComment)
- resp, err := s.client.Do(req, c)
+ resp, err := s.client.Do(ctx, req, c)
if err != nil {
return nil, resp, err
}
@@ -109,7 +110,7 @@ func (s *RepositoriesService) CreateComment(owner, repo, sha string, comment *Re
// GetComment gets a single comment from a repository.
//
// GitHub API docs: https://developer.github.com/v3/repos/comments/#get-a-single-commit-comment
-func (s *RepositoriesService) GetComment(owner, repo string, id int) (*RepositoryComment, *Response, error) {
+func (s *RepositoriesService) GetComment(ctx context.Context, owner, repo string, id int) (*RepositoryComment, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/comments/%v", owner, repo, id)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
@@ -120,7 +121,7 @@ func (s *RepositoriesService) GetComment(owner, repo string, id int) (*Repositor
req.Header.Set("Accept", mediaTypeReactionsPreview)
c := new(RepositoryComment)
- resp, err := s.client.Do(req, c)
+ resp, err := s.client.Do(ctx, req, c)
if err != nil {
return nil, resp, err
}
@@ -131,7 +132,7 @@ func (s *RepositoriesService) GetComment(owner, repo string, id int) (*Repositor
// UpdateComment updates the body of a single comment.
//
// GitHub API docs: https://developer.github.com/v3/repos/comments/#update-a-commit-comment
-func (s *RepositoriesService) UpdateComment(owner, repo string, id int, comment *RepositoryComment) (*RepositoryComment, *Response, error) {
+func (s *RepositoriesService) UpdateComment(ctx context.Context, owner, repo string, id int, comment *RepositoryComment) (*RepositoryComment, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/comments/%v", owner, repo, id)
req, err := s.client.NewRequest("PATCH", u, comment)
if err != nil {
@@ -139,7 +140,7 @@ func (s *RepositoriesService) UpdateComment(owner, repo string, id int, comment
}
c := new(RepositoryComment)
- resp, err := s.client.Do(req, c)
+ resp, err := s.client.Do(ctx, req, c)
if err != nil {
return nil, resp, err
}
@@ -150,11 +151,11 @@ func (s *RepositoriesService) UpdateComment(owner, repo string, id int, comment
// DeleteComment deletes a single comment from a repository.
//
// GitHub API docs: https://developer.github.com/v3/repos/comments/#delete-a-commit-comment
-func (s *RepositoriesService) DeleteComment(owner, repo string, id int) (*Response, error) {
+func (s *RepositoriesService) DeleteComment(ctx context.Context, owner, repo string, id int) (*Response, error) {
u := fmt.Sprintf("repos/%v/%v/comments/%v", owner, repo, id)
req, err := s.client.NewRequest("DELETE", u, nil)
if err != nil {
return nil, err
}
- return s.client.Do(req, nil)
+ return s.client.Do(ctx, req, nil)
}
diff --git a/github/repos_comments_test.go b/github/repos_comments_test.go
index 924a9a40e5f..249a37a3677 100644
--- a/github/repos_comments_test.go
+++ b/github/repos_comments_test.go
@@ -6,6 +6,7 @@
package github
import (
+ "context"
"encoding/json"
"fmt"
"net/http"
@@ -25,7 +26,7 @@ func TestRepositoriesService_ListComments(t *testing.T) {
})
opt := &ListOptions{Page: 2}
- comments, _, err := client.Repositories.ListComments("o", "r", opt)
+ comments, _, err := client.Repositories.ListComments(context.Background(), "o", "r", opt)
if err != nil {
t.Errorf("Repositories.ListComments returned error: %v", err)
}
@@ -37,7 +38,7 @@ func TestRepositoriesService_ListComments(t *testing.T) {
}
func TestRepositoriesService_ListComments_invalidOwner(t *testing.T) {
- _, _, err := client.Repositories.ListComments("%", "%", nil)
+ _, _, err := client.Repositories.ListComments(context.Background(), "%", "%", nil)
testURLParseError(t, err)
}
@@ -53,7 +54,7 @@ func TestRepositoriesService_ListCommitComments(t *testing.T) {
})
opt := &ListOptions{Page: 2}
- comments, _, err := client.Repositories.ListCommitComments("o", "r", "s", opt)
+ comments, _, err := client.Repositories.ListCommitComments(context.Background(), "o", "r", "s", opt)
if err != nil {
t.Errorf("Repositories.ListCommitComments returned error: %v", err)
}
@@ -65,7 +66,7 @@ func TestRepositoriesService_ListCommitComments(t *testing.T) {
}
func TestRepositoriesService_ListCommitComments_invalidOwner(t *testing.T) {
- _, _, err := client.Repositories.ListCommitComments("%", "%", "%", nil)
+ _, _, err := client.Repositories.ListCommitComments(context.Background(), "%", "%", "%", nil)
testURLParseError(t, err)
}
@@ -87,7 +88,7 @@ func TestRepositoriesService_CreateComment(t *testing.T) {
fmt.Fprint(w, `{"id":1}`)
})
- comment, _, err := client.Repositories.CreateComment("o", "r", "s", input)
+ comment, _, err := client.Repositories.CreateComment(context.Background(), "o", "r", "s", input)
if err != nil {
t.Errorf("Repositories.CreateComment returned error: %v", err)
}
@@ -99,7 +100,7 @@ func TestRepositoriesService_CreateComment(t *testing.T) {
}
func TestRepositoriesService_CreateComment_invalidOwner(t *testing.T) {
- _, _, err := client.Repositories.CreateComment("%", "%", "%", nil)
+ _, _, err := client.Repositories.CreateComment(context.Background(), "%", "%", "%", nil)
testURLParseError(t, err)
}
@@ -113,7 +114,7 @@ func TestRepositoriesService_GetComment(t *testing.T) {
fmt.Fprint(w, `{"id":1}`)
})
- comment, _, err := client.Repositories.GetComment("o", "r", 1)
+ comment, _, err := client.Repositories.GetComment(context.Background(), "o", "r", 1)
if err != nil {
t.Errorf("Repositories.GetComment returned error: %v", err)
}
@@ -125,7 +126,7 @@ func TestRepositoriesService_GetComment(t *testing.T) {
}
func TestRepositoriesService_GetComment_invalidOwner(t *testing.T) {
- _, _, err := client.Repositories.GetComment("%", "%", 1)
+ _, _, err := client.Repositories.GetComment(context.Background(), "%", "%", 1)
testURLParseError(t, err)
}
@@ -147,7 +148,7 @@ func TestRepositoriesService_UpdateComment(t *testing.T) {
fmt.Fprint(w, `{"id":1}`)
})
- comment, _, err := client.Repositories.UpdateComment("o", "r", 1, input)
+ comment, _, err := client.Repositories.UpdateComment(context.Background(), "o", "r", 1, input)
if err != nil {
t.Errorf("Repositories.UpdateComment returned error: %v", err)
}
@@ -159,7 +160,7 @@ func TestRepositoriesService_UpdateComment(t *testing.T) {
}
func TestRepositoriesService_UpdateComment_invalidOwner(t *testing.T) {
- _, _, err := client.Repositories.UpdateComment("%", "%", 1, nil)
+ _, _, err := client.Repositories.UpdateComment(context.Background(), "%", "%", 1, nil)
testURLParseError(t, err)
}
@@ -171,13 +172,13 @@ func TestRepositoriesService_DeleteComment(t *testing.T) {
testMethod(t, r, "DELETE")
})
- _, err := client.Repositories.DeleteComment("o", "r", 1)
+ _, err := client.Repositories.DeleteComment(context.Background(), "o", "r", 1)
if err != nil {
t.Errorf("Repositories.DeleteComment returned error: %v", err)
}
}
func TestRepositoriesService_DeleteComment_invalidOwner(t *testing.T) {
- _, err := client.Repositories.DeleteComment("%", "%", 1)
+ _, err := client.Repositories.DeleteComment(context.Background(), "%", "%", 1)
testURLParseError(t, err)
}
diff --git a/github/repos_commits.go b/github/repos_commits.go
index 110e7b2f785..e516f1afd05 100644
--- a/github/repos_commits.go
+++ b/github/repos_commits.go
@@ -7,6 +7,7 @@ package github
import (
"bytes"
+ "context"
"fmt"
"time"
)
@@ -108,7 +109,7 @@ type CommitsListOptions struct {
// ListCommits lists the commits of a repository.
//
// GitHub API docs: https://developer.github.com/v3/repos/commits/#list
-func (s *RepositoriesService) ListCommits(owner, repo string, opt *CommitsListOptions) ([]*RepositoryCommit, *Response, error) {
+func (s *RepositoriesService) ListCommits(ctx context.Context, owner, repo string, opt *CommitsListOptions) ([]*RepositoryCommit, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/commits", owner, repo)
u, err := addOptions(u, opt)
if err != nil {
@@ -121,7 +122,7 @@ func (s *RepositoriesService) ListCommits(owner, repo string, opt *CommitsListOp
}
var commits []*RepositoryCommit
- resp, err := s.client.Do(req, &commits)
+ resp, err := s.client.Do(ctx, req, &commits)
if err != nil {
return nil, resp, err
}
@@ -134,7 +135,7 @@ func (s *RepositoriesService) ListCommits(owner, repo string, opt *CommitsListOp
//
// GitHub API docs: https://developer.github.com/v3/repos/commits/#get-a-single-commit
// See also: https://developer.github.com//v3/git/commits/#get-a-single-commit provides the same functionality
-func (s *RepositoriesService) GetCommit(owner, repo, sha string) (*RepositoryCommit, *Response, error) {
+func (s *RepositoriesService) GetCommit(ctx context.Context, owner, repo, sha string) (*RepositoryCommit, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/commits/%v", owner, repo, sha)
req, err := s.client.NewRequest("GET", u, nil)
@@ -146,7 +147,7 @@ func (s *RepositoriesService) GetCommit(owner, repo, sha string) (*RepositoryCom
req.Header.Set("Accept", mediaTypeGitSigningPreview)
commit := new(RepositoryCommit)
- resp, err := s.client.Do(req, commit)
+ resp, err := s.client.Do(ctx, req, commit)
if err != nil {
return nil, resp, err
}
@@ -158,7 +159,7 @@ func (s *RepositoriesService) GetCommit(owner, repo, sha string) (*RepositoryCom
// supplied and no new commits have occurred, a 304 Unmodified response is returned.
//
// GitHub API docs: https://developer.github.com/v3/repos/commits/#get-the-sha-1-of-a-commit-reference
-func (s *RepositoriesService) GetCommitSHA1(owner, repo, ref, lastSHA string) (string, *Response, error) {
+func (s *RepositoriesService) GetCommitSHA1(ctx context.Context, owner, repo, ref, lastSHA string) (string, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/commits/%v", owner, repo, ref)
req, err := s.client.NewRequest("GET", u, nil)
@@ -172,7 +173,7 @@ func (s *RepositoriesService) GetCommitSHA1(owner, repo, ref, lastSHA string) (s
req.Header.Set("Accept", mediaTypeV3SHA)
var buf bytes.Buffer
- resp, err := s.client.Do(req, &buf)
+ resp, err := s.client.Do(ctx, req, &buf)
if err != nil {
return "", resp, err
}
@@ -184,7 +185,7 @@ func (s *RepositoriesService) GetCommitSHA1(owner, repo, ref, lastSHA string) (s
// todo: support media formats - https://github.com/google/go-github/issues/6
//
// GitHub API docs: https://developer.github.com/v3/repos/commits/index.html#compare-two-commits
-func (s *RepositoriesService) CompareCommits(owner, repo string, base, head string) (*CommitsComparison, *Response, error) {
+func (s *RepositoriesService) CompareCommits(ctx context.Context, owner, repo string, base, head string) (*CommitsComparison, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/compare/%v...%v", owner, repo, base, head)
req, err := s.client.NewRequest("GET", u, nil)
@@ -193,7 +194,7 @@ func (s *RepositoriesService) CompareCommits(owner, repo string, base, head stri
}
comp := new(CommitsComparison)
- resp, err := s.client.Do(req, comp)
+ resp, err := s.client.Do(ctx, req, comp)
if err != nil {
return nil, resp, err
}
diff --git a/github/repos_commits_test.go b/github/repos_commits_test.go
index 83f8f29c88b..bd7c12333de 100644
--- a/github/repos_commits_test.go
+++ b/github/repos_commits_test.go
@@ -6,6 +6,7 @@
package github
import (
+ "context"
"fmt"
"net/http"
"reflect"
@@ -38,7 +39,7 @@ func TestRepositoriesService_ListCommits(t *testing.T) {
Since: time.Date(2013, time.August, 1, 0, 0, 0, 0, time.UTC),
Until: time.Date(2013, time.September, 3, 0, 0, 0, 0, time.UTC),
}
- commits, _, err := client.Repositories.ListCommits("o", "r", opt)
+ commits, _, err := client.Repositories.ListCommits(context.Background(), "o", "r", opt)
if err != nil {
t.Errorf("Repositories.ListCommits returned error: %v", err)
}
@@ -79,7 +80,7 @@ func TestRepositoriesService_GetCommit(t *testing.T) {
}`)
})
- commit, _, err := client.Repositories.GetCommit("o", "r", "s")
+ commit, _, err := client.Repositories.GetCommit(context.Background(), "o", "r", "s")
if err != nil {
t.Errorf("Repositories.GetCommit returned error: %v", err)
}
@@ -136,7 +137,7 @@ func TestRepositoriesService_GetCommitSHA1(t *testing.T) {
fmt.Fprintf(w, sha1)
})
- got, _, err := client.Repositories.GetCommitSHA1("o", "r", "master", "")
+ got, _, err := client.Repositories.GetCommitSHA1(context.Background(), "o", "r", "master", "")
if err != nil {
t.Errorf("Repositories.GetCommitSHA1 returned error: %v", err)
}
@@ -154,7 +155,7 @@ func TestRepositoriesService_GetCommitSHA1(t *testing.T) {
w.WriteHeader(http.StatusNotModified)
})
- got, _, err = client.Repositories.GetCommitSHA1("o", "r", "tag", sha1)
+ got, _, err = client.Repositories.GetCommitSHA1(context.Background(), "o", "r", "tag", sha1)
if err == nil {
t.Errorf("Expected HTTP 304 response")
}
@@ -201,7 +202,7 @@ func TestRepositoriesService_CompareCommits(t *testing.T) {
}`)
})
- got, _, err := client.Repositories.CompareCommits("o", "r", "b", "h")
+ got, _, err := client.Repositories.CompareCommits(context.Background(), "o", "r", "b", "h")
if err != nil {
t.Errorf("Repositories.CompareCommits returned error: %v", err)
}
diff --git a/github/repos_contents.go b/github/repos_contents.go
index 32b1573da1b..f7dd99c802e 100644
--- a/github/repos_contents.go
+++ b/github/repos_contents.go
@@ -9,6 +9,7 @@
package github
import (
+ "context"
"encoding/base64"
"encoding/json"
"fmt"
@@ -87,7 +88,7 @@ func (r *RepositoryContent) GetContent() (string, error) {
// GetReadme gets the Readme file for the repository.
//
// GitHub API docs: https://developer.github.com/v3/repos/contents/#get-the-readme
-func (s *RepositoriesService) GetReadme(owner, repo string, opt *RepositoryContentGetOptions) (*RepositoryContent, *Response, error) {
+func (s *RepositoriesService) GetReadme(ctx context.Context, owner, repo string, opt *RepositoryContentGetOptions) (*RepositoryContent, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/readme", owner, repo)
u, err := addOptions(u, opt)
if err != nil {
@@ -98,7 +99,7 @@ func (s *RepositoriesService) GetReadme(owner, repo string, opt *RepositoryConte
return nil, nil, err
}
readme := new(RepositoryContent)
- resp, err := s.client.Do(req, readme)
+ resp, err := s.client.Do(ctx, req, readme)
if err != nil {
return nil, resp, err
}
@@ -109,10 +110,10 @@ func (s *RepositoriesService) GetReadme(owner, repo string, opt *RepositoryConte
// specified file. This function will work with files of any size, as opposed
// to GetContents which is limited to 1 Mb files. It is the caller's
// responsibility to close the ReadCloser.
-func (s *RepositoriesService) DownloadContents(owner, repo, filepath string, opt *RepositoryContentGetOptions) (io.ReadCloser, error) {
+func (s *RepositoriesService) DownloadContents(ctx context.Context, owner, repo, filepath string, opt *RepositoryContentGetOptions) (io.ReadCloser, error) {
dir := path.Dir(filepath)
filename := path.Base(filepath)
- _, dirContents, _, err := s.GetContents(owner, repo, dir, opt)
+ _, dirContents, _, err := s.GetContents(ctx, owner, repo, dir, opt)
if err != nil {
return nil, err
}
@@ -139,7 +140,7 @@ func (s *RepositoriesService) DownloadContents(owner, repo, filepath string, opt
// value and the other will be nil.
//
// GitHub API docs: https://developer.github.com/v3/repos/contents/#get-contents
-func (s *RepositoriesService) GetContents(owner, repo, path string, opt *RepositoryContentGetOptions) (fileContent *RepositoryContent, directoryContent []*RepositoryContent, resp *Response, err error) {
+func (s *RepositoriesService) GetContents(ctx context.Context, owner, repo, path string, opt *RepositoryContentGetOptions) (fileContent *RepositoryContent, directoryContent []*RepositoryContent, resp *Response, err error) {
escapedPath := (&url.URL{Path: path}).String()
u := fmt.Sprintf("repos/%s/%s/contents/%s", owner, repo, escapedPath)
u, err = addOptions(u, opt)
@@ -151,7 +152,7 @@ func (s *RepositoriesService) GetContents(owner, repo, path string, opt *Reposit
return nil, nil, nil, err
}
var rawJSON json.RawMessage
- resp, err = s.client.Do(req, &rawJSON)
+ resp, err = s.client.Do(ctx, req, &rawJSON)
if err != nil {
return nil, nil, resp, err
}
@@ -170,14 +171,14 @@ func (s *RepositoriesService) GetContents(owner, repo, path string, opt *Reposit
// the commit and file metadata.
//
// GitHub API docs: https://developer.github.com/v3/repos/contents/#create-a-file
-func (s *RepositoriesService) CreateFile(owner, repo, path string, opt *RepositoryContentFileOptions) (*RepositoryContentResponse, *Response, error) {
+func (s *RepositoriesService) CreateFile(ctx context.Context, owner, repo, path string, opt *RepositoryContentFileOptions) (*RepositoryContentResponse, *Response, error) {
u := fmt.Sprintf("repos/%s/%s/contents/%s", owner, repo, path)
req, err := s.client.NewRequest("PUT", u, opt)
if err != nil {
return nil, nil, err
}
createResponse := new(RepositoryContentResponse)
- resp, err := s.client.Do(req, createResponse)
+ resp, err := s.client.Do(ctx, req, createResponse)
if err != nil {
return nil, resp, err
}
@@ -188,14 +189,14 @@ func (s *RepositoriesService) CreateFile(owner, repo, path string, opt *Reposito
// commit and file metadata. Requires the blob SHA of the file being updated.
//
// GitHub API docs: https://developer.github.com/v3/repos/contents/#update-a-file
-func (s *RepositoriesService) UpdateFile(owner, repo, path string, opt *RepositoryContentFileOptions) (*RepositoryContentResponse, *Response, error) {
+func (s *RepositoriesService) UpdateFile(ctx context.Context, owner, repo, path string, opt *RepositoryContentFileOptions) (*RepositoryContentResponse, *Response, error) {
u := fmt.Sprintf("repos/%s/%s/contents/%s", owner, repo, path)
req, err := s.client.NewRequest("PUT", u, opt)
if err != nil {
return nil, nil, err
}
updateResponse := new(RepositoryContentResponse)
- resp, err := s.client.Do(req, updateResponse)
+ resp, err := s.client.Do(ctx, req, updateResponse)
if err != nil {
return nil, resp, err
}
@@ -206,14 +207,14 @@ func (s *RepositoriesService) UpdateFile(owner, repo, path string, opt *Reposito
// Requires the blob SHA of the file to be deleted.
//
// GitHub API docs: https://developer.github.com/v3/repos/contents/#delete-a-file
-func (s *RepositoriesService) DeleteFile(owner, repo, path string, opt *RepositoryContentFileOptions) (*RepositoryContentResponse, *Response, error) {
+func (s *RepositoriesService) DeleteFile(ctx context.Context, owner, repo, path string, opt *RepositoryContentFileOptions) (*RepositoryContentResponse, *Response, error) {
u := fmt.Sprintf("repos/%s/%s/contents/%s", owner, repo, path)
req, err := s.client.NewRequest("DELETE", u, opt)
if err != nil {
return nil, nil, err
}
deleteResponse := new(RepositoryContentResponse)
- resp, err := s.client.Do(req, deleteResponse)
+ resp, err := s.client.Do(ctx, req, deleteResponse)
if err != nil {
return nil, resp, err
}
@@ -236,7 +237,7 @@ const (
// or github.Zipball constant.
//
// GitHub API docs: https://developer.github.com/v3/repos/contents/#get-archive-link
-func (s *RepositoriesService) GetArchiveLink(owner, repo string, archiveformat archiveFormat, opt *RepositoryContentGetOptions) (*url.URL, *Response, error) {
+func (s *RepositoriesService) GetArchiveLink(ctx context.Context, owner, repo string, archiveformat archiveFormat, opt *RepositoryContentGetOptions) (*url.URL, *Response, error) {
u := fmt.Sprintf("repos/%s/%s/%s", owner, repo, archiveformat)
if opt != nil && opt.Ref != "" {
u += fmt.Sprintf("/%s", opt.Ref)
@@ -248,9 +249,9 @@ func (s *RepositoriesService) GetArchiveLink(owner, repo string, archiveformat a
var resp *http.Response
// Use http.DefaultTransport if no custom Transport is configured
if s.client.client.Transport == nil {
- resp, err = http.DefaultTransport.RoundTrip(req)
+ resp, err = http.DefaultTransport.RoundTrip(req.WithContext(ctx))
} else {
- resp, err = s.client.client.Transport.RoundTrip(req)
+ resp, err = s.client.client.Transport.RoundTrip(req.WithContext(ctx))
}
if err != nil {
return nil, nil, err
diff --git a/github/repos_contents_test.go b/github/repos_contents_test.go
index b86d7e16bef..498dfc81001 100644
--- a/github/repos_contents_test.go
+++ b/github/repos_contents_test.go
@@ -6,6 +6,7 @@
package github
import (
+ "context"
"fmt"
"io/ioutil"
"net/http"
@@ -79,7 +80,7 @@ func TestRepositoriesService_GetReadme(t *testing.T) {
"path": "README.md"
}`)
})
- readme, _, err := client.Repositories.GetReadme("o", "r", &RepositoryContentGetOptions{})
+ readme, _, err := client.Repositories.GetReadme(context.Background(), "o", "r", &RepositoryContentGetOptions{})
if err != nil {
t.Errorf("Repositories.GetReadme returned error: %v", err)
}
@@ -105,7 +106,7 @@ func TestRepositoriesService_DownloadContents_Success(t *testing.T) {
fmt.Fprint(w, "foo")
})
- r, err := client.Repositories.DownloadContents("o", "r", "d/f", nil)
+ r, err := client.Repositories.DownloadContents(context.Background(), "o", "r", "d/f", nil)
if err != nil {
t.Errorf("Repositories.DownloadContents returned error: %v", err)
}
@@ -132,7 +133,7 @@ func TestRepositoriesService_DownloadContents_NoDownloadURL(t *testing.T) {
}]`)
})
- _, err := client.Repositories.DownloadContents("o", "r", "d/f", nil)
+ _, err := client.Repositories.DownloadContents(context.Background(), "o", "r", "d/f", nil)
if err == nil {
t.Errorf("Repositories.DownloadContents did not return expected error")
}
@@ -146,7 +147,7 @@ func TestRepositoriesService_DownloadContents_NoFile(t *testing.T) {
fmt.Fprint(w, `[]`)
})
- _, err := client.Repositories.DownloadContents("o", "r", "d/f", nil)
+ _, err := client.Repositories.DownloadContents(context.Background(), "o", "r", "d/f", nil)
if err == nil {
t.Errorf("Repositories.DownloadContents did not return expected error")
}
@@ -165,7 +166,7 @@ func TestRepositoriesService_GetContents_File(t *testing.T) {
"path": "LICENSE"
}`)
})
- fileContents, _, _, err := client.Repositories.GetContents("o", "r", "p", &RepositoryContentGetOptions{})
+ fileContents, _, _, err := client.Repositories.GetContents(context.Background(), "o", "r", "p", &RepositoryContentGetOptions{})
if err != nil {
t.Errorf("Repositories.GetContents returned error: %v", err)
}
@@ -182,7 +183,7 @@ func TestRepositoriesService_GetContents_FilenameNeedsEscape(t *testing.T) {
testMethod(t, r, "GET")
fmt.Fprint(w, `{}`)
})
- _, _, _, err := client.Repositories.GetContents("o", "r", "p#?%/ä¸.go", &RepositoryContentGetOptions{})
+ _, _, _, err := client.Repositories.GetContents(context.Background(), "o", "r", "p#?%/ä¸.go", &RepositoryContentGetOptions{})
if err != nil {
t.Fatalf("Repositories.GetContents returned error: %v", err)
}
@@ -195,7 +196,7 @@ func TestRepositoriesService_GetContents_DirectoryWithSpaces(t *testing.T) {
testMethod(t, r, "GET")
fmt.Fprint(w, `{}`)
})
- _, _, _, err := client.Repositories.GetContents("o", "r", "some directory/file.go", &RepositoryContentGetOptions{})
+ _, _, _, err := client.Repositories.GetContents(context.Background(), "o", "r", "some directory/file.go", &RepositoryContentGetOptions{})
if err != nil {
t.Fatalf("Repositories.GetContents returned error: %v", err)
}
@@ -208,7 +209,7 @@ func TestRepositoriesService_GetContents_DirectoryWithPlusChars(t *testing.T) {
testMethod(t, r, "GET")
fmt.Fprint(w, `{}`)
})
- _, _, _, err := client.Repositories.GetContents("o", "r", "some directory+name/file.go", &RepositoryContentGetOptions{})
+ _, _, _, err := client.Repositories.GetContents(context.Background(), "o", "r", "some directory+name/file.go", &RepositoryContentGetOptions{})
if err != nil {
t.Fatalf("Repositories.GetContents returned error: %v", err)
}
@@ -231,7 +232,7 @@ func TestRepositoriesService_GetContents_Directory(t *testing.T) {
"path": "LICENSE"
}]`)
})
- _, directoryContents, _, err := client.Repositories.GetContents("o", "r", "p", &RepositoryContentGetOptions{})
+ _, directoryContents, _, err := client.Repositories.GetContents(context.Background(), "o", "r", "p", &RepositoryContentGetOptions{})
if err != nil {
t.Errorf("Repositories.GetContents returned error: %v", err)
}
@@ -264,7 +265,7 @@ func TestRepositoriesService_CreateFile(t *testing.T) {
Content: content,
Committer: &CommitAuthor{Name: String("n"), Email: String("e")},
}
- createResponse, _, err := client.Repositories.CreateFile("o", "r", "p", repositoryContentsOptions)
+ createResponse, _, err := client.Repositories.CreateFile(context.Background(), "o", "r", "p", repositoryContentsOptions)
if err != nil {
t.Errorf("Repositories.CreateFile returned error: %v", err)
}
@@ -304,7 +305,7 @@ func TestRepositoriesService_UpdateFile(t *testing.T) {
SHA: &sha,
Committer: &CommitAuthor{Name: String("n"), Email: String("e")},
}
- updateResponse, _, err := client.Repositories.UpdateFile("o", "r", "p", repositoryContentsOptions)
+ updateResponse, _, err := client.Repositories.UpdateFile(context.Background(), "o", "r", "p", repositoryContentsOptions)
if err != nil {
t.Errorf("Repositories.UpdateFile returned error: %v", err)
}
@@ -340,7 +341,7 @@ func TestRepositoriesService_DeleteFile(t *testing.T) {
SHA: &sha,
Committer: &CommitAuthor{Name: String("n"), Email: String("e")},
}
- deleteResponse, _, err := client.Repositories.DeleteFile("o", "r", "p", repositoryContentsOptions)
+ deleteResponse, _, err := client.Repositories.DeleteFile(context.Background(), "o", "r", "p", repositoryContentsOptions)
if err != nil {
t.Errorf("Repositories.DeleteFile returned error: %v", err)
}
@@ -363,7 +364,7 @@ func TestRepositoriesService_GetArchiveLink(t *testing.T) {
testMethod(t, r, "GET")
http.Redirect(w, r, "http://github.com/a", http.StatusFound)
})
- url, resp, err := client.Repositories.GetArchiveLink("o", "r", Tarball, &RepositoryContentGetOptions{})
+ url, resp, err := client.Repositories.GetArchiveLink(context.Background(), "o", "r", Tarball, &RepositoryContentGetOptions{})
if err != nil {
t.Errorf("Repositories.GetArchiveLink returned error: %v", err)
}
diff --git a/github/repos_deployments.go b/github/repos_deployments.go
index ad931afc208..9054ca9472e 100644
--- a/github/repos_deployments.go
+++ b/github/repos_deployments.go
@@ -6,6 +6,7 @@
package github
import (
+ "context"
"encoding/json"
"fmt"
)
@@ -61,7 +62,7 @@ type DeploymentsListOptions struct {
// ListDeployments lists the deployments of a repository.
//
// GitHub API docs: https://developer.github.com/v3/repos/deployments/#list-deployments
-func (s *RepositoriesService) ListDeployments(owner, repo string, opt *DeploymentsListOptions) ([]*Deployment, *Response, error) {
+func (s *RepositoriesService) ListDeployments(ctx context.Context, owner, repo string, opt *DeploymentsListOptions) ([]*Deployment, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/deployments", owner, repo)
u, err := addOptions(u, opt)
if err != nil {
@@ -74,7 +75,7 @@ func (s *RepositoriesService) ListDeployments(owner, repo string, opt *Deploymen
}
var deployments []*Deployment
- resp, err := s.client.Do(req, &deployments)
+ resp, err := s.client.Do(ctx, req, &deployments)
if err != nil {
return nil, resp, err
}
@@ -85,7 +86,7 @@ func (s *RepositoriesService) ListDeployments(owner, repo string, opt *Deploymen
// GetDeployment returns a single deployment of a repository.
//
// GitHub API docs: https://developer.github.com/v3/repos/deployments/#get-a-single-deployment
-func (s *RepositoriesService) GetDeployment(owner, repo string, deploymentID int) (*Deployment, *Response, error) {
+func (s *RepositoriesService) GetDeployment(ctx context.Context, owner, repo string, deploymentID int) (*Deployment, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/deployments/%v", owner, repo, deploymentID)
req, err := s.client.NewRequest("GET", u, nil)
@@ -94,7 +95,7 @@ func (s *RepositoriesService) GetDeployment(owner, repo string, deploymentID int
}
deployment := new(Deployment)
- resp, err := s.client.Do(req, deployment)
+ resp, err := s.client.Do(ctx, req, deployment)
if err != nil {
return nil, resp, err
}
@@ -105,7 +106,7 @@ func (s *RepositoriesService) GetDeployment(owner, repo string, deploymentID int
// CreateDeployment creates a new deployment for a repository.
//
// GitHub API docs: https://developer.github.com/v3/repos/deployments/#create-a-deployment
-func (s *RepositoriesService) CreateDeployment(owner, repo string, request *DeploymentRequest) (*Deployment, *Response, error) {
+func (s *RepositoriesService) CreateDeployment(ctx context.Context, owner, repo string, request *DeploymentRequest) (*Deployment, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/deployments", owner, repo)
req, err := s.client.NewRequest("POST", u, request)
@@ -117,7 +118,7 @@ func (s *RepositoriesService) CreateDeployment(owner, repo string, request *Depl
req.Header.Set("Accept", mediaTypeDeploymentStatusPreview)
d := new(Deployment)
- resp, err := s.client.Do(req, d)
+ resp, err := s.client.Do(ctx, req, d)
if err != nil {
return nil, resp, err
}
@@ -153,7 +154,7 @@ type DeploymentStatusRequest struct {
// ListDeploymentStatuses lists the statuses of a given deployment of a repository.
//
// GitHub API docs: https://developer.github.com/v3/repos/deployments/#list-deployment-statuses
-func (s *RepositoriesService) ListDeploymentStatuses(owner, repo string, deployment int, opt *ListOptions) ([]*DeploymentStatus, *Response, error) {
+func (s *RepositoriesService) ListDeploymentStatuses(ctx context.Context, owner, repo string, deployment int, opt *ListOptions) ([]*DeploymentStatus, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/deployments/%v/statuses", owner, repo, deployment)
u, err := addOptions(u, opt)
if err != nil {
@@ -166,7 +167,7 @@ func (s *RepositoriesService) ListDeploymentStatuses(owner, repo string, deploym
}
var statuses []*DeploymentStatus
- resp, err := s.client.Do(req, &statuses)
+ resp, err := s.client.Do(ctx, req, &statuses)
if err != nil {
return nil, resp, err
}
@@ -177,7 +178,7 @@ func (s *RepositoriesService) ListDeploymentStatuses(owner, repo string, deploym
// GetDeploymentStatus returns a single deployment status of a repository.
//
// GitHub API docs: https://developer.github.com/v3/repos/deployments/#get-a-single-deployment-status
-func (s *RepositoriesService) GetDeploymentStatus(owner, repo string, deploymentID, deploymentStatusID int) (*DeploymentStatus, *Response, error) {
+func (s *RepositoriesService) GetDeploymentStatus(ctx context.Context, owner, repo string, deploymentID, deploymentStatusID int) (*DeploymentStatus, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/deployments/%v/statuses/%v", owner, repo, deploymentID, deploymentStatusID)
req, err := s.client.NewRequest("GET", u, nil)
@@ -189,7 +190,7 @@ func (s *RepositoriesService) GetDeploymentStatus(owner, repo string, deployment
req.Header.Set("Accept", mediaTypeDeploymentStatusPreview)
d := new(DeploymentStatus)
- resp, err := s.client.Do(req, d)
+ resp, err := s.client.Do(ctx, req, d)
if err != nil {
return nil, resp, err
}
@@ -200,7 +201,7 @@ func (s *RepositoriesService) GetDeploymentStatus(owner, repo string, deployment
// CreateDeploymentStatus creates a new status for a deployment.
//
// GitHub API docs: https://developer.github.com/v3/repos/deployments/#create-a-deployment-status
-func (s *RepositoriesService) CreateDeploymentStatus(owner, repo string, deployment int, request *DeploymentStatusRequest) (*DeploymentStatus, *Response, error) {
+func (s *RepositoriesService) CreateDeploymentStatus(ctx context.Context, owner, repo string, deployment int, request *DeploymentStatusRequest) (*DeploymentStatus, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/deployments/%v/statuses", owner, repo, deployment)
req, err := s.client.NewRequest("POST", u, request)
@@ -212,7 +213,7 @@ func (s *RepositoriesService) CreateDeploymentStatus(owner, repo string, deploym
req.Header.Set("Accept", mediaTypeDeploymentStatusPreview)
d := new(DeploymentStatus)
- resp, err := s.client.Do(req, d)
+ resp, err := s.client.Do(ctx, req, d)
if err != nil {
return nil, resp, err
}
diff --git a/github/repos_deployments_test.go b/github/repos_deployments_test.go
index 8593667e870..9fa44b2ba4c 100644
--- a/github/repos_deployments_test.go
+++ b/github/repos_deployments_test.go
@@ -6,6 +6,7 @@
package github
import (
+ "context"
"encoding/json"
"fmt"
"net/http"
@@ -24,7 +25,7 @@ func TestRepositoriesService_ListDeployments(t *testing.T) {
})
opt := &DeploymentsListOptions{Environment: "test"}
- deployments, _, err := client.Repositories.ListDeployments("o", "r", opt)
+ deployments, _, err := client.Repositories.ListDeployments(context.Background(), "o", "r", opt)
if err != nil {
t.Errorf("Repositories.ListDeployments returned error: %v", err)
}
@@ -44,7 +45,7 @@ func TestRepositoriesService_GetDeployment(t *testing.T) {
fmt.Fprint(w, `{"id":3}`)
})
- deployment, _, err := client.Repositories.GetDeployment("o", "r", 3)
+ deployment, _, err := client.Repositories.GetDeployment(context.Background(), "o", "r", 3)
if err != nil {
t.Errorf("Repositories.GetDeployment returned error: %v", err)
}
@@ -75,7 +76,7 @@ func TestRepositoriesService_CreateDeployment(t *testing.T) {
fmt.Fprint(w, `{"ref": "1111", "task": "deploy"}`)
})
- deployment, _, err := client.Repositories.CreateDeployment("o", "r", input)
+ deployment, _, err := client.Repositories.CreateDeployment(context.Background(), "o", "r", input)
if err != nil {
t.Errorf("Repositories.CreateDeployment returned error: %v", err)
}
@@ -97,7 +98,7 @@ func TestRepositoriesService_ListDeploymentStatuses(t *testing.T) {
})
opt := &ListOptions{Page: 2}
- statutses, _, err := client.Repositories.ListDeploymentStatuses("o", "r", 1, opt)
+ statutses, _, err := client.Repositories.ListDeploymentStatuses(context.Background(), "o", "r", 1, opt)
if err != nil {
t.Errorf("Repositories.ListDeploymentStatuses returned error: %v", err)
}
@@ -118,7 +119,7 @@ func TestRepositoriesService_GetDeploymentStatus(t *testing.T) {
fmt.Fprint(w, `{"id":4}`)
})
- deploymentStatus, _, err := client.Repositories.GetDeploymentStatus("o", "r", 3, 4)
+ deploymentStatus, _, err := client.Repositories.GetDeploymentStatus(context.Background(), "o", "r", 3, 4)
if err != nil {
t.Errorf("Repositories.GetDeploymentStatus returned error: %v", err)
}
@@ -148,7 +149,7 @@ func TestRepositoriesService_CreateDeploymentStatus(t *testing.T) {
fmt.Fprint(w, `{"state": "inactive", "description": "deploy"}`)
})
- deploymentStatus, _, err := client.Repositories.CreateDeploymentStatus("o", "r", 1, input)
+ deploymentStatus, _, err := client.Repositories.CreateDeploymentStatus(context.Background(), "o", "r", 1, input)
if err != nil {
t.Errorf("Repositories.CreateDeploymentStatus returned error: %v", err)
}
diff --git a/github/repos_forks.go b/github/repos_forks.go
index fe98a6c2f2d..6b5e4eabba2 100644
--- a/github/repos_forks.go
+++ b/github/repos_forks.go
@@ -5,7 +5,10 @@
package github
-import "fmt"
+import (
+ "context"
+ "fmt"
+)
// RepositoryListForksOptions specifies the optional parameters to the
// RepositoriesService.ListForks method.
@@ -20,7 +23,7 @@ type RepositoryListForksOptions struct {
// ListForks lists the forks of the specified repository.
//
// GitHub API docs: https://developer.github.com/v3/repos/forks/#list-forks
-func (s *RepositoriesService) ListForks(owner, repo string, opt *RepositoryListForksOptions) ([]*Repository, *Response, error) {
+func (s *RepositoriesService) ListForks(ctx context.Context, owner, repo string, opt *RepositoryListForksOptions) ([]*Repository, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/forks", owner, repo)
u, err := addOptions(u, opt)
if err != nil {
@@ -33,7 +36,7 @@ func (s *RepositoriesService) ListForks(owner, repo string, opt *RepositoryListF
}
var repos []*Repository
- resp, err := s.client.Do(req, &repos)
+ resp, err := s.client.Do(ctx, req, &repos)
if err != nil {
return nil, resp, err
}
@@ -57,7 +60,7 @@ type RepositoryCreateForkOptions struct {
// in a successful request.
//
// GitHub API docs: https://developer.github.com/v3/repos/forks/#create-a-fork
-func (s *RepositoriesService) CreateFork(owner, repo string, opt *RepositoryCreateForkOptions) (*Repository, *Response, error) {
+func (s *RepositoriesService) CreateFork(ctx context.Context, owner, repo string, opt *RepositoryCreateForkOptions) (*Repository, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/forks", owner, repo)
u, err := addOptions(u, opt)
if err != nil {
@@ -70,7 +73,7 @@ func (s *RepositoriesService) CreateFork(owner, repo string, opt *RepositoryCrea
}
fork := new(Repository)
- resp, err := s.client.Do(req, fork)
+ resp, err := s.client.Do(ctx, req, fork)
if err != nil {
return nil, resp, err
}
diff --git a/github/repos_forks_test.go b/github/repos_forks_test.go
index 3d2baa54e94..40916ea4ea7 100644
--- a/github/repos_forks_test.go
+++ b/github/repos_forks_test.go
@@ -6,6 +6,7 @@
package github
import (
+ "context"
"fmt"
"net/http"
"reflect"
@@ -29,7 +30,7 @@ func TestRepositoriesService_ListForks(t *testing.T) {
Sort: "newest",
ListOptions: ListOptions{Page: 3},
}
- repos, _, err := client.Repositories.ListForks("o", "r", opt)
+ repos, _, err := client.Repositories.ListForks(context.Background(), "o", "r", opt)
if err != nil {
t.Errorf("Repositories.ListForks returned error: %v", err)
}
@@ -41,7 +42,7 @@ func TestRepositoriesService_ListForks(t *testing.T) {
}
func TestRepositoriesService_ListForks_invalidOwner(t *testing.T) {
- _, _, err := client.Repositories.ListForks("%", "r", nil)
+ _, _, err := client.Repositories.ListForks(context.Background(), "%", "r", nil)
testURLParseError(t, err)
}
@@ -56,7 +57,7 @@ func TestRepositoriesService_CreateFork(t *testing.T) {
})
opt := &RepositoryCreateForkOptions{Organization: "o"}
- repo, _, err := client.Repositories.CreateFork("o", "r", opt)
+ repo, _, err := client.Repositories.CreateFork(context.Background(), "o", "r", opt)
if err != nil {
t.Errorf("Repositories.CreateFork returned error: %v", err)
}
@@ -68,6 +69,6 @@ func TestRepositoriesService_CreateFork(t *testing.T) {
}
func TestRepositoriesService_CreateFork_invalidOwner(t *testing.T) {
- _, _, err := client.Repositories.CreateFork("%", "r", nil)
+ _, _, err := client.Repositories.CreateFork(context.Background(), "%", "r", nil)
testURLParseError(t, err)
}
diff --git a/github/repos_hooks.go b/github/repos_hooks.go
index 818286b7998..67ce96ac342 100644
--- a/github/repos_hooks.go
+++ b/github/repos_hooks.go
@@ -6,6 +6,7 @@
package github
import (
+ "context"
"fmt"
"time"
)
@@ -86,7 +87,7 @@ func (h Hook) String() string {
// Name and Config are required fields.
//
// GitHub API docs: https://developer.github.com/v3/repos/hooks/#create-a-hook
-func (s *RepositoriesService) CreateHook(owner, repo string, hook *Hook) (*Hook, *Response, error) {
+func (s *RepositoriesService) CreateHook(ctx context.Context, owner, repo string, hook *Hook) (*Hook, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/hooks", owner, repo)
req, err := s.client.NewRequest("POST", u, hook)
if err != nil {
@@ -94,7 +95,7 @@ func (s *RepositoriesService) CreateHook(owner, repo string, hook *Hook) (*Hook,
}
h := new(Hook)
- resp, err := s.client.Do(req, h)
+ resp, err := s.client.Do(ctx, req, h)
if err != nil {
return nil, resp, err
}
@@ -105,7 +106,7 @@ func (s *RepositoriesService) CreateHook(owner, repo string, hook *Hook) (*Hook,
// ListHooks lists all Hooks for the specified repository.
//
// GitHub API docs: https://developer.github.com/v3/repos/hooks/#list
-func (s *RepositoriesService) ListHooks(owner, repo string, opt *ListOptions) ([]*Hook, *Response, error) {
+func (s *RepositoriesService) ListHooks(ctx context.Context, owner, repo string, opt *ListOptions) ([]*Hook, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/hooks", owner, repo)
u, err := addOptions(u, opt)
if err != nil {
@@ -118,7 +119,7 @@ func (s *RepositoriesService) ListHooks(owner, repo string, opt *ListOptions) ([
}
var hooks []*Hook
- resp, err := s.client.Do(req, &hooks)
+ resp, err := s.client.Do(ctx, req, &hooks)
if err != nil {
return nil, resp, err
}
@@ -129,63 +130,63 @@ func (s *RepositoriesService) ListHooks(owner, repo string, opt *ListOptions) ([
// GetHook returns a single specified Hook.
//
// GitHub API docs: https://developer.github.com/v3/repos/hooks/#get-single-hook
-func (s *RepositoriesService) GetHook(owner, repo string, id int) (*Hook, *Response, error) {
+func (s *RepositoriesService) GetHook(ctx context.Context, owner, repo string, id int) (*Hook, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/hooks/%d", owner, repo, id)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}
hook := new(Hook)
- resp, err := s.client.Do(req, hook)
+ resp, err := s.client.Do(ctx, req, hook)
return hook, resp, err
}
// EditHook updates a specified Hook.
//
// GitHub API docs: https://developer.github.com/v3/repos/hooks/#edit-a-hook
-func (s *RepositoriesService) EditHook(owner, repo string, id int, hook *Hook) (*Hook, *Response, error) {
+func (s *RepositoriesService) EditHook(ctx context.Context, owner, repo string, id int, hook *Hook) (*Hook, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/hooks/%d", owner, repo, id)
req, err := s.client.NewRequest("PATCH", u, hook)
if err != nil {
return nil, nil, err
}
h := new(Hook)
- resp, err := s.client.Do(req, h)
+ resp, err := s.client.Do(ctx, req, h)
return h, resp, err
}
// DeleteHook deletes a specified Hook.
//
// GitHub API docs: https://developer.github.com/v3/repos/hooks/#delete-a-hook
-func (s *RepositoriesService) DeleteHook(owner, repo string, id int) (*Response, error) {
+func (s *RepositoriesService) DeleteHook(ctx context.Context, owner, repo string, id int) (*Response, error) {
u := fmt.Sprintf("repos/%v/%v/hooks/%d", owner, repo, id)
req, err := s.client.NewRequest("DELETE", u, nil)
if err != nil {
return nil, err
}
- return s.client.Do(req, nil)
+ return s.client.Do(ctx, req, nil)
}
// PingHook triggers a 'ping' event to be sent to the Hook.
//
// GitHub API docs: https://developer.github.com/v3/repos/hooks/#ping-a-hook
-func (s *RepositoriesService) PingHook(owner, repo string, id int) (*Response, error) {
+func (s *RepositoriesService) PingHook(ctx context.Context, owner, repo string, id int) (*Response, error) {
u := fmt.Sprintf("repos/%v/%v/hooks/%d/pings", owner, repo, id)
req, err := s.client.NewRequest("POST", u, nil)
if err != nil {
return nil, err
}
- return s.client.Do(req, nil)
+ return s.client.Do(ctx, req, nil)
}
// TestHook triggers a test Hook by github.
//
// GitHub API docs: https://developer.github.com/v3/repos/hooks/#test-a-push-hook
-func (s *RepositoriesService) TestHook(owner, repo string, id int) (*Response, error) {
+func (s *RepositoriesService) TestHook(ctx context.Context, owner, repo string, id int) (*Response, error) {
u := fmt.Sprintf("repos/%v/%v/hooks/%d/tests", owner, repo, id)
req, err := s.client.NewRequest("POST", u, nil)
if err != nil {
return nil, err
}
- return s.client.Do(req, nil)
+ return s.client.Do(ctx, req, nil)
}
diff --git a/github/repos_hooks_test.go b/github/repos_hooks_test.go
index fcfc9a7f6f5..364f4583f08 100644
--- a/github/repos_hooks_test.go
+++ b/github/repos_hooks_test.go
@@ -6,6 +6,7 @@
package github
import (
+ "context"
"encoding/json"
"fmt"
"net/http"
@@ -31,7 +32,7 @@ func TestRepositoriesService_CreateHook(t *testing.T) {
fmt.Fprint(w, `{"id":1}`)
})
- hook, _, err := client.Repositories.CreateHook("o", "r", input)
+ hook, _, err := client.Repositories.CreateHook(context.Background(), "o", "r", input)
if err != nil {
t.Errorf("Repositories.CreateHook returned error: %v", err)
}
@@ -43,7 +44,7 @@ func TestRepositoriesService_CreateHook(t *testing.T) {
}
func TestRepositoriesService_CreateHook_invalidOwner(t *testing.T) {
- _, _, err := client.Repositories.CreateHook("%", "%", nil)
+ _, _, err := client.Repositories.CreateHook(context.Background(), "%", "%", nil)
testURLParseError(t, err)
}
@@ -59,7 +60,7 @@ func TestRepositoriesService_ListHooks(t *testing.T) {
opt := &ListOptions{Page: 2}
- hooks, _, err := client.Repositories.ListHooks("o", "r", opt)
+ hooks, _, err := client.Repositories.ListHooks(context.Background(), "o", "r", opt)
if err != nil {
t.Errorf("Repositories.ListHooks returned error: %v", err)
}
@@ -71,7 +72,7 @@ func TestRepositoriesService_ListHooks(t *testing.T) {
}
func TestRepositoriesService_ListHooks_invalidOwner(t *testing.T) {
- _, _, err := client.Repositories.ListHooks("%", "%", nil)
+ _, _, err := client.Repositories.ListHooks(context.Background(), "%", "%", nil)
testURLParseError(t, err)
}
@@ -84,7 +85,7 @@ func TestRepositoriesService_GetHook(t *testing.T) {
fmt.Fprint(w, `{"id":1}`)
})
- hook, _, err := client.Repositories.GetHook("o", "r", 1)
+ hook, _, err := client.Repositories.GetHook(context.Background(), "o", "r", 1)
if err != nil {
t.Errorf("Repositories.GetHook returned error: %v", err)
}
@@ -96,7 +97,7 @@ func TestRepositoriesService_GetHook(t *testing.T) {
}
func TestRepositoriesService_GetHook_invalidOwner(t *testing.T) {
- _, _, err := client.Repositories.GetHook("%", "%", 1)
+ _, _, err := client.Repositories.GetHook(context.Background(), "%", "%", 1)
testURLParseError(t, err)
}
@@ -118,7 +119,7 @@ func TestRepositoriesService_EditHook(t *testing.T) {
fmt.Fprint(w, `{"id":1}`)
})
- hook, _, err := client.Repositories.EditHook("o", "r", 1, input)
+ hook, _, err := client.Repositories.EditHook(context.Background(), "o", "r", 1, input)
if err != nil {
t.Errorf("Repositories.EditHook returned error: %v", err)
}
@@ -130,7 +131,7 @@ func TestRepositoriesService_EditHook(t *testing.T) {
}
func TestRepositoriesService_EditHook_invalidOwner(t *testing.T) {
- _, _, err := client.Repositories.EditHook("%", "%", 1, nil)
+ _, _, err := client.Repositories.EditHook(context.Background(), "%", "%", 1, nil)
testURLParseError(t, err)
}
@@ -142,14 +143,14 @@ func TestRepositoriesService_DeleteHook(t *testing.T) {
testMethod(t, r, "DELETE")
})
- _, err := client.Repositories.DeleteHook("o", "r", 1)
+ _, err := client.Repositories.DeleteHook(context.Background(), "o", "r", 1)
if err != nil {
t.Errorf("Repositories.DeleteHook returned error: %v", err)
}
}
func TestRepositoriesService_DeleteHook_invalidOwner(t *testing.T) {
- _, err := client.Repositories.DeleteHook("%", "%", 1)
+ _, err := client.Repositories.DeleteHook(context.Background(), "%", "%", 1)
testURLParseError(t, err)
}
@@ -161,7 +162,7 @@ func TestRepositoriesService_PingHook(t *testing.T) {
testMethod(t, r, "POST")
})
- _, err := client.Repositories.PingHook("o", "r", 1)
+ _, err := client.Repositories.PingHook(context.Background(), "o", "r", 1)
if err != nil {
t.Errorf("Repositories.PingHook returned error: %v", err)
}
@@ -175,13 +176,13 @@ func TestRepositoriesService_TestHook(t *testing.T) {
testMethod(t, r, "POST")
})
- _, err := client.Repositories.TestHook("o", "r", 1)
+ _, err := client.Repositories.TestHook(context.Background(), "o", "r", 1)
if err != nil {
t.Errorf("Repositories.TestHook returned error: %v", err)
}
}
func TestRepositoriesService_TestHook_invalidOwner(t *testing.T) {
- _, err := client.Repositories.TestHook("%", "%", 1)
+ _, err := client.Repositories.TestHook(context.Background(), "%", "%", 1)
testURLParseError(t, err)
}
diff --git a/github/repos_invitations.go b/github/repos_invitations.go
index e80b946314a..58c26dfa335 100644
--- a/github/repos_invitations.go
+++ b/github/repos_invitations.go
@@ -5,7 +5,10 @@
package github
-import "fmt"
+import (
+ "context"
+ "fmt"
+)
// RepositoryInvitation represents an invitation to collaborate on a repo.
type RepositoryInvitation struct {
@@ -25,7 +28,7 @@ type RepositoryInvitation struct {
// ListInvitations lists all currently-open repository invitations.
//
// GitHub API docs: https://developer.github.com/v3/repos/invitations/#list-invitations-for-a-repository
-func (s *RepositoriesService) ListInvitations(repoID int, opt *ListOptions) ([]*RepositoryInvitation, *Response, error) {
+func (s *RepositoriesService) ListInvitations(ctx context.Context, repoID int, opt *ListOptions) ([]*RepositoryInvitation, *Response, error) {
u := fmt.Sprintf("repositories/%v/invitations", repoID)
u, err := addOptions(u, opt)
if err != nil {
@@ -41,7 +44,7 @@ func (s *RepositoriesService) ListInvitations(repoID int, opt *ListOptions) ([]*
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
}
@@ -52,7 +55,7 @@ func (s *RepositoriesService) ListInvitations(repoID int, opt *ListOptions) ([]*
// DeleteInvitation deletes a repository invitation.
//
// GitHub API docs: https://developer.github.com/v3/repos/invitations/#delete-a-repository-invitation
-func (s *RepositoriesService) DeleteInvitation(repoID, invitationID int) (*Response, error) {
+func (s *RepositoriesService) DeleteInvitation(ctx context.Context, repoID, invitationID int) (*Response, error) {
u := fmt.Sprintf("repositories/%v/invitations/%v", repoID, invitationID)
req, err := s.client.NewRequest("DELETE", u, nil)
if err != nil {
@@ -62,7 +65,7 @@ func (s *RepositoriesService) DeleteInvitation(repoID, invitationID int) (*Respo
// 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)
}
// UpdateInvitation updates the permissions associated with a repository
@@ -72,7 +75,7 @@ func (s *RepositoriesService) DeleteInvitation(repoID, invitationID int) (*Respo
// on the repository. Possible values are: "read", "write", "admin".
//
// GitHub API docs: https://developer.github.com/v3/repos/invitations/#update-a-repository-invitation
-func (s *RepositoriesService) UpdateInvitation(repoID, invitationID int, permissions string) (*RepositoryInvitation, *Response, error) {
+func (s *RepositoriesService) UpdateInvitation(ctx context.Context, repoID, invitationID int, permissions string) (*RepositoryInvitation, *Response, error) {
opts := &struct {
Permissions string `json:"permissions"`
}{Permissions: permissions}
@@ -86,6 +89,6 @@ func (s *RepositoriesService) UpdateInvitation(repoID, invitationID int, permiss
req.Header.Set("Accept", mediaTypeRepositoryInvitationsPreview)
invite := &RepositoryInvitation{}
- resp, err := s.client.Do(req, invite)
+ resp, err := s.client.Do(ctx, req, invite)
return invite, resp, err
}
diff --git a/github/repos_invitations_test.go b/github/repos_invitations_test.go
index c5688cb6635..c5327353a63 100644
--- a/github/repos_invitations_test.go
+++ b/github/repos_invitations_test.go
@@ -6,6 +6,7 @@
package github
import (
+ "context"
"fmt"
"net/http"
"reflect"
@@ -24,7 +25,7 @@ func TestRepositoriesService_ListInvitations(t *testing.T) {
})
opt := &ListOptions{Page: 2}
- got, _, err := client.Repositories.ListInvitations(1, opt)
+ got, _, err := client.Repositories.ListInvitations(context.Background(), 1, opt)
if err != nil {
t.Errorf("Repositories.ListInvitations returned error: %v", err)
}
@@ -45,7 +46,7 @@ func TestRepositoriesService_DeleteInvitation(t *testing.T) {
w.WriteHeader(http.StatusNoContent)
})
- _, err := client.Repositories.DeleteInvitation(1, 2)
+ _, err := client.Repositories.DeleteInvitation(context.Background(), 1, 2)
if err != nil {
t.Errorf("Repositories.DeleteInvitation returned error: %v", err)
}
@@ -61,7 +62,7 @@ func TestRepositoriesService_UpdateInvitation(t *testing.T) {
fmt.Fprintf(w, `{"id":1}`)
})
- got, _, err := client.Repositories.UpdateInvitation(1, 2, "write")
+ got, _, err := client.Repositories.UpdateInvitation(context.Background(), 1, 2, "write")
if err != nil {
t.Errorf("Repositories.UpdateInvitation returned error: %v", err)
}
diff --git a/github/repos_keys.go b/github/repos_keys.go
index 1ac35da1794..f5a865813a5 100644
--- a/github/repos_keys.go
+++ b/github/repos_keys.go
@@ -5,14 +5,17 @@
package github
-import "fmt"
+import (
+ "context"
+ "fmt"
+)
// The Key type is defined in users_keys.go
// ListKeys lists the deploy keys for a repository.
//
// GitHub API docs: https://developer.github.com/v3/repos/keys/#list
-func (s *RepositoriesService) ListKeys(owner string, repo string, opt *ListOptions) ([]*Key, *Response, error) {
+func (s *RepositoriesService) ListKeys(ctx context.Context, owner string, repo string, opt *ListOptions) ([]*Key, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/keys", owner, repo)
u, err := addOptions(u, opt)
if err != nil {
@@ -25,7 +28,7 @@ func (s *RepositoriesService) ListKeys(owner string, repo string, opt *ListOptio
}
var keys []*Key
- resp, err := s.client.Do(req, &keys)
+ resp, err := s.client.Do(ctx, req, &keys)
if err != nil {
return nil, resp, err
}
@@ -36,7 +39,7 @@ func (s *RepositoriesService) ListKeys(owner string, repo string, opt *ListOptio
// GetKey fetches a single deploy key.
//
// GitHub API docs: https://developer.github.com/v3/repos/keys/#get
-func (s *RepositoriesService) GetKey(owner string, repo string, id int) (*Key, *Response, error) {
+func (s *RepositoriesService) GetKey(ctx context.Context, owner string, repo string, id int) (*Key, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/keys/%v", owner, repo, id)
req, err := s.client.NewRequest("GET", u, nil)
@@ -45,7 +48,7 @@ func (s *RepositoriesService) GetKey(owner string, repo string, id int) (*Key, *
}
key := new(Key)
- resp, err := s.client.Do(req, key)
+ resp, err := s.client.Do(ctx, req, key)
if err != nil {
return nil, resp, err
}
@@ -56,7 +59,7 @@ func (s *RepositoriesService) GetKey(owner string, repo string, id int) (*Key, *
// CreateKey adds a deploy key for a repository.
//
// GitHub API docs: https://developer.github.com/v3/repos/keys/#create
-func (s *RepositoriesService) CreateKey(owner string, repo string, key *Key) (*Key, *Response, error) {
+func (s *RepositoriesService) CreateKey(ctx context.Context, owner string, repo string, key *Key) (*Key, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/keys", owner, repo)
req, err := s.client.NewRequest("POST", u, key)
@@ -65,7 +68,7 @@ func (s *RepositoriesService) CreateKey(owner string, repo string, key *Key) (*K
}
k := new(Key)
- resp, err := s.client.Do(req, k)
+ resp, err := s.client.Do(ctx, req, k)
if err != nil {
return nil, resp, err
}
@@ -76,7 +79,7 @@ func (s *RepositoriesService) CreateKey(owner string, repo string, key *Key) (*K
// EditKey edits a deploy key.
//
// GitHub API docs: https://developer.github.com/v3/repos/keys/#edit
-func (s *RepositoriesService) EditKey(owner string, repo string, id int, key *Key) (*Key, *Response, error) {
+func (s *RepositoriesService) EditKey(ctx context.Context, owner string, repo string, id int, key *Key) (*Key, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/keys/%v", owner, repo, id)
req, err := s.client.NewRequest("PATCH", u, key)
@@ -85,7 +88,7 @@ func (s *RepositoriesService) EditKey(owner string, repo string, id int, key *Ke
}
k := new(Key)
- resp, err := s.client.Do(req, k)
+ resp, err := s.client.Do(ctx, req, k)
if err != nil {
return nil, resp, err
}
@@ -96,7 +99,7 @@ func (s *RepositoriesService) EditKey(owner string, repo string, id int, key *Ke
// DeleteKey deletes a deploy key.
//
// GitHub API docs: https://developer.github.com/v3/repos/keys/#delete
-func (s *RepositoriesService) DeleteKey(owner string, repo string, id int) (*Response, error) {
+func (s *RepositoriesService) DeleteKey(ctx context.Context, owner string, repo string, id int) (*Response, error) {
u := fmt.Sprintf("repos/%v/%v/keys/%v", owner, repo, id)
req, err := s.client.NewRequest("DELETE", u, nil)
@@ -104,5 +107,5 @@ func (s *RepositoriesService) DeleteKey(owner string, repo string, id int) (*Res
return nil, err
}
- return s.client.Do(req, nil)
+ return s.client.Do(ctx, req, nil)
}
diff --git a/github/repos_keys_test.go b/github/repos_keys_test.go
index 3bea308f0b7..2ef04fdcb62 100644
--- a/github/repos_keys_test.go
+++ b/github/repos_keys_test.go
@@ -6,6 +6,7 @@
package github
import (
+ "context"
"encoding/json"
"fmt"
"net/http"
@@ -24,7 +25,7 @@ func TestRepositoriesService_ListKeys(t *testing.T) {
})
opt := &ListOptions{Page: 2}
- keys, _, err := client.Repositories.ListKeys("o", "r", opt)
+ keys, _, err := client.Repositories.ListKeys(context.Background(), "o", "r", opt)
if err != nil {
t.Errorf("Repositories.ListKeys returned error: %v", err)
}
@@ -36,7 +37,7 @@ func TestRepositoriesService_ListKeys(t *testing.T) {
}
func TestRepositoriesService_ListKeys_invalidOwner(t *testing.T) {
- _, _, err := client.Repositories.ListKeys("%", "%", nil)
+ _, _, err := client.Repositories.ListKeys(context.Background(), "%", "%", nil)
testURLParseError(t, err)
}
@@ -49,7 +50,7 @@ func TestRepositoriesService_GetKey(t *testing.T) {
fmt.Fprint(w, `{"id":1}`)
})
- key, _, err := client.Repositories.GetKey("o", "r", 1)
+ key, _, err := client.Repositories.GetKey(context.Background(), "o", "r", 1)
if err != nil {
t.Errorf("Repositories.GetKey returned error: %v", err)
}
@@ -61,7 +62,7 @@ func TestRepositoriesService_GetKey(t *testing.T) {
}
func TestRepositoriesService_GetKey_invalidOwner(t *testing.T) {
- _, _, err := client.Repositories.GetKey("%", "%", 1)
+ _, _, err := client.Repositories.GetKey(context.Background(), "%", "%", 1)
testURLParseError(t, err)
}
@@ -83,7 +84,7 @@ func TestRepositoriesService_CreateKey(t *testing.T) {
fmt.Fprint(w, `{"id":1}`)
})
- key, _, err := client.Repositories.CreateKey("o", "r", input)
+ key, _, err := client.Repositories.CreateKey(context.Background(), "o", "r", input)
if err != nil {
t.Errorf("Repositories.GetKey returned error: %v", err)
}
@@ -95,7 +96,7 @@ func TestRepositoriesService_CreateKey(t *testing.T) {
}
func TestRepositoriesService_CreateKey_invalidOwner(t *testing.T) {
- _, _, err := client.Repositories.CreateKey("%", "%", nil)
+ _, _, err := client.Repositories.CreateKey(context.Background(), "%", "%", nil)
testURLParseError(t, err)
}
@@ -117,7 +118,7 @@ func TestRepositoriesService_EditKey(t *testing.T) {
fmt.Fprint(w, `{"id":1}`)
})
- key, _, err := client.Repositories.EditKey("o", "r", 1, input)
+ key, _, err := client.Repositories.EditKey(context.Background(), "o", "r", 1, input)
if err != nil {
t.Errorf("Repositories.EditKey returned error: %v", err)
}
@@ -129,7 +130,7 @@ func TestRepositoriesService_EditKey(t *testing.T) {
}
func TestRepositoriesService_EditKey_invalidOwner(t *testing.T) {
- _, _, err := client.Repositories.EditKey("%", "%", 1, nil)
+ _, _, err := client.Repositories.EditKey(context.Background(), "%", "%", 1, nil)
testURLParseError(t, err)
}
@@ -141,13 +142,13 @@ func TestRepositoriesService_DeleteKey(t *testing.T) {
testMethod(t, r, "DELETE")
})
- _, err := client.Repositories.DeleteKey("o", "r", 1)
+ _, err := client.Repositories.DeleteKey(context.Background(), "o", "r", 1)
if err != nil {
t.Errorf("Repositories.DeleteKey returned error: %v", err)
}
}
func TestRepositoriesService_DeleteKey_invalidOwner(t *testing.T) {
- _, err := client.Repositories.DeleteKey("%", "%", 1)
+ _, err := client.Repositories.DeleteKey(context.Background(), "%", "%", 1)
testURLParseError(t, err)
}
diff --git a/github/repos_merging.go b/github/repos_merging.go
index f9aefb49b51..04383c1ae32 100644
--- a/github/repos_merging.go
+++ b/github/repos_merging.go
@@ -6,6 +6,7 @@
package github
import (
+ "context"
"fmt"
)
@@ -20,7 +21,7 @@ type RepositoryMergeRequest struct {
// Merge a branch in the specified repository.
//
// GitHub API docs: https://developer.github.com/v3/repos/merging/#perform-a-merge
-func (s *RepositoriesService) Merge(owner, repo string, request *RepositoryMergeRequest) (*RepositoryCommit, *Response, error) {
+func (s *RepositoriesService) Merge(ctx context.Context, owner, repo string, request *RepositoryMergeRequest) (*RepositoryCommit, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/merges", owner, repo)
req, err := s.client.NewRequest("POST", u, request)
if err != nil {
@@ -28,7 +29,7 @@ func (s *RepositoriesService) Merge(owner, repo string, request *RepositoryMerge
}
commit := new(RepositoryCommit)
- resp, err := s.client.Do(req, commit)
+ resp, err := s.client.Do(ctx, req, commit)
if err != nil {
return nil, resp, err
}
diff --git a/github/repos_merging_test.go b/github/repos_merging_test.go
index 166c5e5204f..e2e264fd660 100644
--- a/github/repos_merging_test.go
+++ b/github/repos_merging_test.go
@@ -6,6 +6,7 @@
package github
import (
+ "context"
"encoding/json"
"fmt"
"net/http"
@@ -35,7 +36,7 @@ func TestRepositoriesService_Merge(t *testing.T) {
fmt.Fprint(w, `{"sha":"s"}`)
})
- commit, _, err := client.Repositories.Merge("o", "r", input)
+ commit, _, err := client.Repositories.Merge(context.Background(), "o", "r", input)
if err != nil {
t.Errorf("Repositories.Merge returned error: %v", err)
}
diff --git a/github/repos_pages.go b/github/repos_pages.go
index e4bb6d8811a..3d19b43db57 100644
--- a/github/repos_pages.go
+++ b/github/repos_pages.go
@@ -5,7 +5,10 @@
package github
-import "fmt"
+import (
+ "context"
+ "fmt"
+)
// Pages represents a GitHub Pages site configuration.
type Pages struct {
@@ -36,7 +39,7 @@ type PagesBuild struct {
// GetPagesInfo fetches information about a GitHub Pages site.
//
// GitHub API docs: https://developer.github.com/v3/repos/pages/#get-information-about-a-pages-site
-func (s *RepositoriesService) GetPagesInfo(owner, repo string) (*Pages, *Response, error) {
+func (s *RepositoriesService) GetPagesInfo(ctx context.Context, owner, repo string) (*Pages, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/pages", owner, repo)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
@@ -47,7 +50,7 @@ func (s *RepositoriesService) GetPagesInfo(owner, repo string) (*Pages, *Respons
req.Header.Set("Accept", mediaTypePagesPreview)
site := new(Pages)
- resp, err := s.client.Do(req, site)
+ resp, err := s.client.Do(ctx, req, site)
if err != nil {
return nil, resp, err
}
@@ -58,7 +61,7 @@ func (s *RepositoriesService) GetPagesInfo(owner, repo string) (*Pages, *Respons
// ListPagesBuilds lists the builds for a GitHub Pages site.
//
// GitHub API docs: https://developer.github.com/v3/repos/pages/#list-pages-builds
-func (s *RepositoriesService) ListPagesBuilds(owner, repo string) ([]*PagesBuild, *Response, error) {
+func (s *RepositoriesService) ListPagesBuilds(ctx context.Context, owner, repo string) ([]*PagesBuild, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/pages/builds", owner, repo)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
@@ -66,7 +69,7 @@ func (s *RepositoriesService) ListPagesBuilds(owner, repo string) ([]*PagesBuild
}
var pages []*PagesBuild
- resp, err := s.client.Do(req, &pages)
+ resp, err := s.client.Do(ctx, req, &pages)
if err != nil {
return nil, resp, err
}
@@ -77,7 +80,7 @@ func (s *RepositoriesService) ListPagesBuilds(owner, repo string) ([]*PagesBuild
// GetLatestPagesBuild fetches the latest build information for a GitHub pages site.
//
// GitHub API docs: https://developer.github.com/v3/repos/pages/#list-latest-pages-build
-func (s *RepositoriesService) GetLatestPagesBuild(owner, repo string) (*PagesBuild, *Response, error) {
+func (s *RepositoriesService) GetLatestPagesBuild(ctx context.Context, owner, repo string) (*PagesBuild, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/pages/builds/latest", owner, repo)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
@@ -85,7 +88,7 @@ func (s *RepositoriesService) GetLatestPagesBuild(owner, repo string) (*PagesBui
}
build := new(PagesBuild)
- resp, err := s.client.Do(req, build)
+ resp, err := s.client.Do(ctx, req, build)
if err != nil {
return nil, resp, err
}
@@ -96,7 +99,7 @@ func (s *RepositoriesService) GetLatestPagesBuild(owner, repo string) (*PagesBui
// GetPageBuild fetches the specific build information for a GitHub pages site.
//
// GitHub API docs: https://developer.github.com/v3/repos/pages/#list-a-specific-pages-build
-func (s *RepositoriesService) GetPageBuild(owner, repo string, id int) (*PagesBuild, *Response, error) {
+func (s *RepositoriesService) GetPageBuild(ctx context.Context, owner, repo string, id int) (*PagesBuild, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/pages/builds/%v", owner, repo, id)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
@@ -104,7 +107,7 @@ func (s *RepositoriesService) GetPageBuild(owner, repo string, id int) (*PagesBu
}
build := new(PagesBuild)
- resp, err := s.client.Do(req, build)
+ resp, err := s.client.Do(ctx, req, build)
if err != nil {
return nil, resp, err
}
@@ -115,7 +118,7 @@ func (s *RepositoriesService) GetPageBuild(owner, repo string, id int) (*PagesBu
// RequestPageBuild requests a build of a GitHub Pages site without needing to push new commit.
//
// GitHub API docs: https://developer.github.com/v3/repos/pages/#request-a-page-build
-func (s *RepositoriesService) RequestPageBuild(owner, repo string) (*PagesBuild, *Response, error) {
+func (s *RepositoriesService) RequestPageBuild(ctx context.Context, owner, repo string) (*PagesBuild, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/pages/builds", owner, repo)
req, err := s.client.NewRequest("POST", u, nil)
if err != nil {
@@ -126,7 +129,7 @@ func (s *RepositoriesService) RequestPageBuild(owner, repo string) (*PagesBuild,
req.Header.Set("Accept", mediaTypePagesPreview)
build := new(PagesBuild)
- resp, err := s.client.Do(req, build)
+ resp, err := s.client.Do(ctx, req, build)
if err != nil {
return nil, resp, err
}
diff --git a/github/repos_pages_test.go b/github/repos_pages_test.go
index e2d908ed637..ce7bea43adb 100644
--- a/github/repos_pages_test.go
+++ b/github/repos_pages_test.go
@@ -6,6 +6,7 @@
package github
import (
+ "context"
"fmt"
"net/http"
"reflect"
@@ -22,7 +23,7 @@ func TestRepositoriesService_GetPagesInfo(t *testing.T) {
fmt.Fprint(w, `{"url":"u","status":"s","cname":"c","custom_404":false,"html_url":"h"}`)
})
- page, _, err := client.Repositories.GetPagesInfo("o", "r")
+ page, _, err := client.Repositories.GetPagesInfo(context.Background(), "o", "r")
if err != nil {
t.Errorf("Repositories.GetPagesInfo returned error: %v", err)
}
@@ -42,7 +43,7 @@ func TestRepositoriesService_ListPagesBuilds(t *testing.T) {
fmt.Fprint(w, `[{"url":"u","status":"s","commit":"c"}]`)
})
- pages, _, err := client.Repositories.ListPagesBuilds("o", "r")
+ pages, _, err := client.Repositories.ListPagesBuilds(context.Background(), "o", "r")
if err != nil {
t.Errorf("Repositories.ListPagesBuilds returned error: %v", err)
}
@@ -62,7 +63,7 @@ func TestRepositoriesService_GetLatestPagesBuild(t *testing.T) {
fmt.Fprint(w, `{"url":"u","status":"s","commit":"c"}`)
})
- build, _, err := client.Repositories.GetLatestPagesBuild("o", "r")
+ build, _, err := client.Repositories.GetLatestPagesBuild(context.Background(), "o", "r")
if err != nil {
t.Errorf("Repositories.GetLatestPagesBuild returned error: %v", err)
}
@@ -82,7 +83,7 @@ func TestRepositoriesService_GetPageBuild(t *testing.T) {
fmt.Fprint(w, `{"url":"u","status":"s","commit":"c"}`)
})
- build, _, err := client.Repositories.GetPageBuild("o", "r", 1)
+ build, _, err := client.Repositories.GetPageBuild(context.Background(), "o", "r", 1)
if err != nil {
t.Errorf("Repositories.GetPageBuild returned error: %v", err)
}
@@ -103,7 +104,7 @@ func TestRepositoriesService_RequestPageBuild(t *testing.T) {
fmt.Fprint(w, `{"url":"u","status":"s"}`)
})
- build, _, err := client.Repositories.RequestPageBuild("o", "r")
+ build, _, err := client.Repositories.RequestPageBuild(context.Background(), "o", "r")
if err != nil {
t.Errorf("Repositories.RequestPageBuild returned error: %v", err)
}
diff --git a/github/repos_projects.go b/github/repos_projects.go
index dc9227c389c..9e1a4dbb2d5 100644
--- a/github/repos_projects.go
+++ b/github/repos_projects.go
@@ -5,12 +5,15 @@
package github
-import "fmt"
+import (
+ "context"
+ "fmt"
+)
// ListProjects lists the projects for a repo.
//
// GitHub API docs: https://developer.github.com/v3/projects/#list-repository-projects
-func (s *RepositoriesService) ListProjects(owner, repo string, opt *ListOptions) ([]*Project, *Response, error) {
+func (s *RepositoriesService) ListProjects(ctx context.Context, owner, repo string, opt *ListOptions) ([]*Project, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/projects", owner, repo)
u, err := addOptions(u, opt)
if err != nil {
@@ -26,7 +29,7 @@ func (s *RepositoriesService) ListProjects(owner, repo string, opt *ListOptions)
req.Header.Set("Accept", mediaTypeProjectsPreview)
projects := []*Project{}
- resp, err := s.client.Do(req, &projects)
+ resp, err := s.client.Do(ctx, req, &projects)
if err != nil {
return nil, resp, err
}
@@ -37,7 +40,7 @@ func (s *RepositoriesService) ListProjects(owner, repo string, opt *ListOptions)
// CreateProject creates a GitHub Project for the specified repository.
//
// GitHub API docs: https://developer.github.com/v3/projects/#create-a-repository-project
-func (s *RepositoriesService) CreateProject(owner, repo string, opt *ProjectOptions) (*Project, *Response, error) {
+func (s *RepositoriesService) CreateProject(ctx context.Context, owner, repo string, opt *ProjectOptions) (*Project, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/projects", owner, repo)
req, err := s.client.NewRequest("POST", u, opt)
if err != nil {
@@ -48,7 +51,7 @@ func (s *RepositoriesService) CreateProject(owner, repo string, opt *ProjectOpti
req.Header.Set("Accept", mediaTypeProjectsPreview)
project := &Project{}
- resp, err := s.client.Do(req, project)
+ resp, err := s.client.Do(ctx, req, project)
if err != nil {
return nil, resp, err
}
diff --git a/github/repos_projects_test.go b/github/repos_projects_test.go
index d8a35f60cb5..7bc323bed0d 100644
--- a/github/repos_projects_test.go
+++ b/github/repos_projects_test.go
@@ -6,6 +6,7 @@
package github
import (
+ "context"
"encoding/json"
"fmt"
"net/http"
@@ -25,7 +26,7 @@ func TestRepositoriesService_ListProjects(t *testing.T) {
})
opt := &ListOptions{Page: 2}
- projects, _, err := client.Repositories.ListProjects("o", "r", opt)
+ projects, _, err := client.Repositories.ListProjects(context.Background(), "o", "r", opt)
if err != nil {
t.Errorf("Repositories.ListProjects returned error: %v", err)
}
@@ -55,7 +56,7 @@ func TestRepositoriesService_CreateProject(t *testing.T) {
fmt.Fprint(w, `{"id":1}`)
})
- project, _, err := client.Repositories.CreateProject("o", "r", input)
+ project, _, err := client.Repositories.CreateProject(context.Background(), "o", "r", input)
if err != nil {
t.Errorf("Repositories.CreateProject returned error: %v", err)
}
diff --git a/github/repos_releases.go b/github/repos_releases.go
index 10abc880485..f26366a36a7 100644
--- a/github/repos_releases.go
+++ b/github/repos_releases.go
@@ -6,6 +6,7 @@
package github
import (
+ "context"
"errors"
"fmt"
"io"
@@ -64,7 +65,7 @@ func (r ReleaseAsset) String() string {
// ListReleases lists the releases for a repository.
//
// GitHub API docs: https://developer.github.com/v3/repos/releases/#list-releases-for-a-repository
-func (s *RepositoriesService) ListReleases(owner, repo string, opt *ListOptions) ([]*RepositoryRelease, *Response, error) {
+func (s *RepositoriesService) ListReleases(ctx context.Context, owner, repo string, opt *ListOptions) ([]*RepositoryRelease, *Response, error) {
u := fmt.Sprintf("repos/%s/%s/releases", owner, repo)
u, err := addOptions(u, opt)
if err != nil {
@@ -77,7 +78,7 @@ func (s *RepositoriesService) ListReleases(owner, repo string, opt *ListOptions)
}
var releases []*RepositoryRelease
- resp, err := s.client.Do(req, &releases)
+ resp, err := s.client.Do(ctx, req, &releases)
if err != nil {
return nil, resp, err
}
@@ -87,35 +88,35 @@ func (s *RepositoriesService) ListReleases(owner, repo string, opt *ListOptions)
// GetRelease fetches a single release.
//
// GitHub API docs: https://developer.github.com/v3/repos/releases/#get-a-single-release
-func (s *RepositoriesService) GetRelease(owner, repo string, id int) (*RepositoryRelease, *Response, error) {
+func (s *RepositoriesService) GetRelease(ctx context.Context, owner, repo string, id int) (*RepositoryRelease, *Response, error) {
u := fmt.Sprintf("repos/%s/%s/releases/%d", owner, repo, id)
- return s.getSingleRelease(u)
+ return s.getSingleRelease(ctx, u)
}
// GetLatestRelease fetches the latest published release for the repository.
//
// GitHub API docs: https://developer.github.com/v3/repos/releases/#get-the-latest-release
-func (s *RepositoriesService) GetLatestRelease(owner, repo string) (*RepositoryRelease, *Response, error) {
+func (s *RepositoriesService) GetLatestRelease(ctx context.Context, owner, repo string) (*RepositoryRelease, *Response, error) {
u := fmt.Sprintf("repos/%s/%s/releases/latest", owner, repo)
- return s.getSingleRelease(u)
+ return s.getSingleRelease(ctx, u)
}
// GetReleaseByTag fetches a release with the specified tag.
//
// GitHub API docs: https://developer.github.com/v3/repos/releases/#get-a-release-by-tag-name
-func (s *RepositoriesService) GetReleaseByTag(owner, repo, tag string) (*RepositoryRelease, *Response, error) {
+func (s *RepositoriesService) GetReleaseByTag(ctx context.Context, owner, repo, tag string) (*RepositoryRelease, *Response, error) {
u := fmt.Sprintf("repos/%s/%s/releases/tags/%s", owner, repo, tag)
- return s.getSingleRelease(u)
+ return s.getSingleRelease(ctx, u)
}
-func (s *RepositoriesService) getSingleRelease(url string) (*RepositoryRelease, *Response, error) {
+func (s *RepositoriesService) getSingleRelease(ctx context.Context, url string) (*RepositoryRelease, *Response, error) {
req, err := s.client.NewRequest("GET", url, nil)
if err != nil {
return nil, nil, err
}
release := new(RepositoryRelease)
- resp, err := s.client.Do(req, release)
+ resp, err := s.client.Do(ctx, req, release)
if err != nil {
return nil, resp, err
}
@@ -125,7 +126,7 @@ func (s *RepositoriesService) getSingleRelease(url string) (*RepositoryRelease,
// CreateRelease adds a new release for a repository.
//
// GitHub API docs : https://developer.github.com/v3/repos/releases/#create-a-release
-func (s *RepositoriesService) CreateRelease(owner, repo string, release *RepositoryRelease) (*RepositoryRelease, *Response, error) {
+func (s *RepositoriesService) CreateRelease(ctx context.Context, owner, repo string, release *RepositoryRelease) (*RepositoryRelease, *Response, error) {
u := fmt.Sprintf("repos/%s/%s/releases", owner, repo)
req, err := s.client.NewRequest("POST", u, release)
@@ -134,7 +135,7 @@ func (s *RepositoriesService) CreateRelease(owner, repo string, release *Reposit
}
r := new(RepositoryRelease)
- resp, err := s.client.Do(req, r)
+ resp, err := s.client.Do(ctx, req, r)
if err != nil {
return nil, resp, err
}
@@ -144,7 +145,7 @@ func (s *RepositoriesService) CreateRelease(owner, repo string, release *Reposit
// EditRelease edits a repository release.
//
// GitHub API docs : https://developer.github.com/v3/repos/releases/#edit-a-release
-func (s *RepositoriesService) EditRelease(owner, repo string, id int, release *RepositoryRelease) (*RepositoryRelease, *Response, error) {
+func (s *RepositoriesService) EditRelease(ctx context.Context, owner, repo string, id int, release *RepositoryRelease) (*RepositoryRelease, *Response, error) {
u := fmt.Sprintf("repos/%s/%s/releases/%d", owner, repo, id)
req, err := s.client.NewRequest("PATCH", u, release)
@@ -153,7 +154,7 @@ func (s *RepositoriesService) EditRelease(owner, repo string, id int, release *R
}
r := new(RepositoryRelease)
- resp, err := s.client.Do(req, r)
+ resp, err := s.client.Do(ctx, req, r)
if err != nil {
return nil, resp, err
}
@@ -163,20 +164,20 @@ func (s *RepositoriesService) EditRelease(owner, repo string, id int, release *R
// DeleteRelease delete a single release from a repository.
//
// GitHub API docs : https://developer.github.com/v3/repos/releases/#delete-a-release
-func (s *RepositoriesService) DeleteRelease(owner, repo string, id int) (*Response, error) {
+func (s *RepositoriesService) DeleteRelease(ctx context.Context, owner, repo string, id int) (*Response, error) {
u := fmt.Sprintf("repos/%s/%s/releases/%d", owner, repo, id)
req, err := s.client.NewRequest("DELETE", u, nil)
if err != nil {
return nil, err
}
- return s.client.Do(req, nil)
+ return s.client.Do(ctx, req, nil)
}
// ListReleaseAssets lists the release's assets.
//
// GitHub API docs : https://developer.github.com/v3/repos/releases/#list-assets-for-a-release
-func (s *RepositoriesService) ListReleaseAssets(owner, repo string, id int, opt *ListOptions) ([]*ReleaseAsset, *Response, error) {
+func (s *RepositoriesService) ListReleaseAssets(ctx context.Context, owner, repo string, id int, opt *ListOptions) ([]*ReleaseAsset, *Response, error) {
u := fmt.Sprintf("repos/%s/%s/releases/%d/assets", owner, repo, id)
u, err := addOptions(u, opt)
if err != nil {
@@ -189,7 +190,7 @@ func (s *RepositoriesService) ListReleaseAssets(owner, repo string, id int, opt
}
var assets []*ReleaseAsset
- resp, err := s.client.Do(req, &assets)
+ resp, err := s.client.Do(ctx, req, &assets)
if err != nil {
return nil, resp, err
}
@@ -199,7 +200,7 @@ func (s *RepositoriesService) ListReleaseAssets(owner, repo string, id int, opt
// GetReleaseAsset fetches a single release asset.
//
// GitHub API docs : https://developer.github.com/v3/repos/releases/#get-a-single-release-asset
-func (s *RepositoriesService) GetReleaseAsset(owner, repo string, id int) (*ReleaseAsset, *Response, error) {
+func (s *RepositoriesService) GetReleaseAsset(ctx context.Context, owner, repo string, id int) (*ReleaseAsset, *Response, error) {
u := fmt.Sprintf("repos/%s/%s/releases/assets/%d", owner, repo, id)
req, err := s.client.NewRequest("GET", u, nil)
@@ -208,7 +209,7 @@ func (s *RepositoriesService) GetReleaseAsset(owner, repo string, id int) (*Rele
}
asset := new(ReleaseAsset)
- resp, err := s.client.Do(req, asset)
+ resp, err := s.client.Do(ctx, req, asset)
if err != nil {
return nil, resp, err
}
@@ -223,7 +224,7 @@ func (s *RepositoriesService) GetReleaseAsset(owner, repo string, id int) (*Rele
// of the io.ReadCloser. Exactly one of rc and redirectURL will be zero.
//
// GitHub API docs : https://developer.github.com/v3/repos/releases/#get-a-single-release-asset
-func (s *RepositoriesService) DownloadReleaseAsset(owner, repo string, id int) (rc io.ReadCloser, redirectURL string, err error) {
+func (s *RepositoriesService) DownloadReleaseAsset(ctx context.Context, owner, repo string, id int) (rc io.ReadCloser, redirectURL string, err error) {
u := fmt.Sprintf("repos/%s/%s/releases/assets/%d", owner, repo, id)
req, err := s.client.NewRequest("GET", u, nil)
@@ -243,7 +244,7 @@ func (s *RepositoriesService) DownloadReleaseAsset(owner, repo string, id int) (
}
defer func() { s.client.client.CheckRedirect = saveRedirect }()
- resp, err := s.client.client.Do(req)
+ resp, err := s.client.client.Do(req.WithContext(ctx))
if err != nil {
if !strings.Contains(err.Error(), "disable redirect") {
return nil, "", err
@@ -262,7 +263,7 @@ func (s *RepositoriesService) DownloadReleaseAsset(owner, repo string, id int) (
// EditReleaseAsset edits a repository release asset.
//
// GitHub API docs : https://developer.github.com/v3/repos/releases/#edit-a-release-asset
-func (s *RepositoriesService) EditReleaseAsset(owner, repo string, id int, release *ReleaseAsset) (*ReleaseAsset, *Response, error) {
+func (s *RepositoriesService) EditReleaseAsset(ctx context.Context, owner, repo string, id int, release *ReleaseAsset) (*ReleaseAsset, *Response, error) {
u := fmt.Sprintf("repos/%s/%s/releases/assets/%d", owner, repo, id)
req, err := s.client.NewRequest("PATCH", u, release)
@@ -271,7 +272,7 @@ func (s *RepositoriesService) EditReleaseAsset(owner, repo string, id int, relea
}
asset := new(ReleaseAsset)
- resp, err := s.client.Do(req, asset)
+ resp, err := s.client.Do(ctx, req, asset)
if err != nil {
return nil, resp, err
}
@@ -281,21 +282,21 @@ func (s *RepositoriesService) EditReleaseAsset(owner, repo string, id int, relea
// DeleteReleaseAsset delete a single release asset from a repository.
//
// GitHub API docs : https://developer.github.com/v3/repos/releases/#delete-a-release-asset
-func (s *RepositoriesService) DeleteReleaseAsset(owner, repo string, id int) (*Response, error) {
+func (s *RepositoriesService) DeleteReleaseAsset(ctx context.Context, owner, repo string, id int) (*Response, error) {
u := fmt.Sprintf("repos/%s/%s/releases/assets/%d", owner, repo, id)
req, err := s.client.NewRequest("DELETE", u, nil)
if err != nil {
return nil, err
}
- return s.client.Do(req, nil)
+ return s.client.Do(ctx, req, nil)
}
// UploadReleaseAsset creates an asset by uploading a file into a release repository.
// To upload assets that cannot be represented by an os.File, call NewUploadRequest directly.
//
// GitHub API docs : https://developer.github.com/v3/repos/releases/#upload-a-release-asset
-func (s *RepositoriesService) UploadReleaseAsset(owner, repo string, id int, opt *UploadOptions, file *os.File) (*ReleaseAsset, *Response, error) {
+func (s *RepositoriesService) UploadReleaseAsset(ctx context.Context, owner, repo string, id int, opt *UploadOptions, file *os.File) (*ReleaseAsset, *Response, error) {
u := fmt.Sprintf("repos/%s/%s/releases/%d/assets", owner, repo, id)
u, err := addOptions(u, opt)
if err != nil {
@@ -317,7 +318,7 @@ func (s *RepositoriesService) UploadReleaseAsset(owner, repo string, id int, opt
}
asset := new(ReleaseAsset)
- resp, err := s.client.Do(req, asset)
+ resp, err := s.client.Do(ctx, req, asset)
if err != nil {
return nil, resp, err
}
diff --git a/github/repos_releases_test.go b/github/repos_releases_test.go
index 99b6bef063f..9a2c4c8afff 100644
--- a/github/repos_releases_test.go
+++ b/github/repos_releases_test.go
@@ -7,6 +7,7 @@ package github
import (
"bytes"
+ "context"
"encoding/json"
"fmt"
"io/ioutil"
@@ -28,7 +29,7 @@ func TestRepositoriesService_ListReleases(t *testing.T) {
})
opt := &ListOptions{Page: 2}
- releases, _, err := client.Repositories.ListReleases("o", "r", opt)
+ releases, _, err := client.Repositories.ListReleases(context.Background(), "o", "r", opt)
if err != nil {
t.Errorf("Repositories.ListReleases returned error: %v", err)
}
@@ -47,7 +48,7 @@ func TestRepositoriesService_GetRelease(t *testing.T) {
fmt.Fprint(w, `{"id":1,"author":{"login":"l"}}`)
})
- release, resp, err := client.Repositories.GetRelease("o", "r", 1)
+ release, resp, err := client.Repositories.GetRelease(context.Background(), "o", "r", 1)
if err != nil {
t.Errorf("Repositories.GetRelease returned error: %v\n%v", err, resp.Body)
}
@@ -67,7 +68,7 @@ func TestRepositoriesService_GetLatestRelease(t *testing.T) {
fmt.Fprint(w, `{"id":3}`)
})
- release, resp, err := client.Repositories.GetLatestRelease("o", "r")
+ release, resp, err := client.Repositories.GetLatestRelease(context.Background(), "o", "r")
if err != nil {
t.Errorf("Repositories.GetLatestRelease returned error: %v\n%v", err, resp.Body)
}
@@ -87,7 +88,7 @@ func TestRepositoriesService_GetReleaseByTag(t *testing.T) {
fmt.Fprint(w, `{"id":13}`)
})
- release, resp, err := client.Repositories.GetReleaseByTag("o", "r", "foo")
+ release, resp, err := client.Repositories.GetReleaseByTag(context.Background(), "o", "r", "foo")
if err != nil {
t.Errorf("Repositories.GetReleaseByTag returned error: %v\n%v", err, resp.Body)
}
@@ -115,7 +116,7 @@ func TestRepositoriesService_CreateRelease(t *testing.T) {
fmt.Fprint(w, `{"id":1}`)
})
- release, _, err := client.Repositories.CreateRelease("o", "r", input)
+ release, _, err := client.Repositories.CreateRelease(context.Background(), "o", "r", input)
if err != nil {
t.Errorf("Repositories.CreateRelease returned error: %v", err)
}
@@ -143,7 +144,7 @@ func TestRepositoriesService_EditRelease(t *testing.T) {
fmt.Fprint(w, `{"id":1}`)
})
- release, _, err := client.Repositories.EditRelease("o", "r", 1, input)
+ release, _, err := client.Repositories.EditRelease(context.Background(), "o", "r", 1, input)
if err != nil {
t.Errorf("Repositories.EditRelease returned error: %v", err)
}
@@ -161,7 +162,7 @@ func TestRepositoriesService_DeleteRelease(t *testing.T) {
testMethod(t, r, "DELETE")
})
- _, err := client.Repositories.DeleteRelease("o", "r", 1)
+ _, err := client.Repositories.DeleteRelease(context.Background(), "o", "r", 1)
if err != nil {
t.Errorf("Repositories.DeleteRelease returned error: %v", err)
}
@@ -178,7 +179,7 @@ func TestRepositoriesService_ListReleaseAssets(t *testing.T) {
})
opt := &ListOptions{Page: 2}
- assets, _, err := client.Repositories.ListReleaseAssets("o", "r", 1, opt)
+ assets, _, err := client.Repositories.ListReleaseAssets(context.Background(), "o", "r", 1, opt)
if err != nil {
t.Errorf("Repositories.ListReleaseAssets returned error: %v", err)
}
@@ -197,7 +198,7 @@ func TestRepositoriesService_GetReleaseAsset(t *testing.T) {
fmt.Fprint(w, `{"id":1}`)
})
- asset, _, err := client.Repositories.GetReleaseAsset("o", "r", 1)
+ asset, _, err := client.Repositories.GetReleaseAsset(context.Background(), "o", "r", 1)
if err != nil {
t.Errorf("Repositories.GetReleaseAsset returned error: %v", err)
}
@@ -219,7 +220,7 @@ func TestRepositoriesService_DownloadReleaseAsset_Stream(t *testing.T) {
fmt.Fprint(w, "Hello World")
})
- reader, _, err := client.Repositories.DownloadReleaseAsset("o", "r", 1)
+ reader, _, err := client.Repositories.DownloadReleaseAsset(context.Background(), "o", "r", 1)
if err != nil {
t.Errorf("Repositories.DownloadReleaseAsset returned error: %v", err)
}
@@ -243,7 +244,7 @@ func TestRepositoriesService_DownloadReleaseAsset_Redirect(t *testing.T) {
http.Redirect(w, r, "/yo", http.StatusFound)
})
- _, got, err := client.Repositories.DownloadReleaseAsset("o", "r", 1)
+ _, got, err := client.Repositories.DownloadReleaseAsset(context.Background(), "o", "r", 1)
if err != nil {
t.Errorf("Repositories.DownloadReleaseAsset returned error: %v", err)
}
@@ -264,7 +265,7 @@ func TestRepositoriesService_DownloadReleaseAsset_APIError(t *testing.T) {
fmt.Fprint(w, `{"message":"Not Found","documentation_url":"https://developer.github.com/v3"}`)
})
- resp, loc, err := client.Repositories.DownloadReleaseAsset("o", "r", 1)
+ resp, loc, err := client.Repositories.DownloadReleaseAsset(context.Background(), "o", "r", 1)
if err == nil {
t.Error("Repositories.DownloadReleaseAsset did not return an error")
}
@@ -296,7 +297,7 @@ func TestRepositoriesService_EditReleaseAsset(t *testing.T) {
fmt.Fprint(w, `{"id":1}`)
})
- asset, _, err := client.Repositories.EditReleaseAsset("o", "r", 1, input)
+ asset, _, err := client.Repositories.EditReleaseAsset(context.Background(), "o", "r", 1, input)
if err != nil {
t.Errorf("Repositories.EditReleaseAsset returned error: %v", err)
}
@@ -314,7 +315,7 @@ func TestRepositoriesService_DeleteReleaseAsset(t *testing.T) {
testMethod(t, r, "DELETE")
})
- _, err := client.Repositories.DeleteReleaseAsset("o", "r", 1)
+ _, err := client.Repositories.DeleteReleaseAsset(context.Background(), "o", "r", 1)
if err != nil {
t.Errorf("Repositories.DeleteReleaseAsset returned error: %v", err)
}
@@ -341,7 +342,7 @@ func TestRepositoriesService_UploadReleaseAsset(t *testing.T) {
defer os.RemoveAll(dir)
opt := &UploadOptions{Name: "n"}
- asset, _, err := client.Repositories.UploadReleaseAsset("o", "r", 1, opt, file)
+ asset, _, err := client.Repositories.UploadReleaseAsset(context.Background(), "o", "r", 1, opt, file)
if err != nil {
t.Errorf("Repositories.UploadReleaseAssert returned error: %v", err)
}
diff --git a/github/repos_stats.go b/github/repos_stats.go
index 5ed1dec4127..f06aeee9a43 100644
--- a/github/repos_stats.go
+++ b/github/repos_stats.go
@@ -6,6 +6,7 @@
package github
import (
+ "context"
"fmt"
"time"
)
@@ -45,7 +46,7 @@ func (w WeeklyStats) String() string {
// delay of a second or so, should result in a successful request.
//
// GitHub API Docs: https://developer.github.com/v3/repos/statistics/#contributors
-func (s *RepositoriesService) ListContributorsStats(owner, repo string) ([]*ContributorStats, *Response, error) {
+func (s *RepositoriesService) ListContributorsStats(ctx context.Context, owner, repo string) ([]*ContributorStats, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/stats/contributors", owner, repo)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
@@ -53,7 +54,7 @@ func (s *RepositoriesService) ListContributorsStats(owner, repo string) ([]*Cont
}
var contributorStats []*ContributorStats
- resp, err := s.client.Do(req, &contributorStats)
+ resp, err := s.client.Do(ctx, req, &contributorStats)
if err != nil {
return nil, resp, err
}
@@ -84,7 +85,7 @@ func (w WeeklyCommitActivity) String() string {
// delay of a second or so, should result in a successful request.
//
// GitHub API Docs: https://developer.github.com/v3/repos/statistics/#commit-activity
-func (s *RepositoriesService) ListCommitActivity(owner, repo string) ([]*WeeklyCommitActivity, *Response, error) {
+func (s *RepositoriesService) ListCommitActivity(ctx context.Context, owner, repo string) ([]*WeeklyCommitActivity, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/stats/commit_activity", owner, repo)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
@@ -92,7 +93,7 @@ func (s *RepositoriesService) ListCommitActivity(owner, repo string) ([]*WeeklyC
}
var weeklyCommitActivity []*WeeklyCommitActivity
- resp, err := s.client.Do(req, &weeklyCommitActivity)
+ resp, err := s.client.Do(ctx, req, &weeklyCommitActivity)
if err != nil {
return nil, resp, err
}
@@ -111,7 +112,7 @@ func (s *RepositoriesService) ListCommitActivity(owner, repo string) ([]*WeeklyC
// delay of a second or so, should result in a successful request.
//
// GitHub API Docs: https://developer.github.com/v3/repos/statistics/#code-frequency
-func (s *RepositoriesService) ListCodeFrequency(owner, repo string) ([]*WeeklyStats, *Response, error) {
+func (s *RepositoriesService) ListCodeFrequency(ctx context.Context, owner, repo string) ([]*WeeklyStats, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/stats/code_frequency", owner, repo)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
@@ -119,7 +120,7 @@ func (s *RepositoriesService) ListCodeFrequency(owner, repo string) ([]*WeeklySt
}
var weeks [][]int
- resp, err := s.client.Do(req, &weeks)
+ resp, err := s.client.Do(ctx, req, &weeks)
// convert int slices into WeeklyStats
var stats []*WeeklyStats
@@ -164,7 +165,7 @@ func (r RepositoryParticipation) String() string {
// delay of a second or so, should result in a successful request.
//
// GitHub API Docs: https://developer.github.com/v3/repos/statistics/#participation
-func (s *RepositoriesService) ListParticipation(owner, repo string) (*RepositoryParticipation, *Response, error) {
+func (s *RepositoriesService) ListParticipation(ctx context.Context, owner, repo string) (*RepositoryParticipation, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/stats/participation", owner, repo)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
@@ -172,7 +173,7 @@ func (s *RepositoriesService) ListParticipation(owner, repo string) (*Repository
}
participation := new(RepositoryParticipation)
- resp, err := s.client.Do(req, participation)
+ resp, err := s.client.Do(ctx, req, participation)
if err != nil {
return nil, resp, err
}
@@ -197,7 +198,7 @@ type PunchCard struct {
// delay of a second or so, should result in a successful request.
//
// GitHub API Docs: https://developer.github.com/v3/repos/statistics/#punch-card
-func (s *RepositoriesService) ListPunchCard(owner, repo string) ([]*PunchCard, *Response, error) {
+func (s *RepositoriesService) ListPunchCard(ctx context.Context, owner, repo string) ([]*PunchCard, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/stats/punch_card", owner, repo)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
@@ -205,7 +206,7 @@ func (s *RepositoriesService) ListPunchCard(owner, repo string) ([]*PunchCard, *
}
var results [][]int
- resp, err := s.client.Do(req, &results)
+ resp, err := s.client.Do(ctx, req, &results)
// convert int slices into Punchcards
var cards []*PunchCard
diff --git a/github/repos_stats_test.go b/github/repos_stats_test.go
index 56acc56f553..1da94d01338 100644
--- a/github/repos_stats_test.go
+++ b/github/repos_stats_test.go
@@ -6,6 +6,7 @@
package github
import (
+ "context"
"fmt"
"net/http"
"reflect"
@@ -40,7 +41,7 @@ func TestRepositoriesService_ListContributorsStats(t *testing.T) {
`)
})
- stats, _, err := client.Repositories.ListContributorsStats("o", "r")
+ stats, _, err := client.Repositories.ListContributorsStats(context.Background(), "o", "r")
if err != nil {
t.Errorf("RepositoriesService.ListContributorsStats returned error: %v", err)
}
@@ -85,7 +86,7 @@ func TestRepositoriesService_ListCommitActivity(t *testing.T) {
`)
})
- activity, _, err := client.Repositories.ListCommitActivity("o", "r")
+ activity, _, err := client.Repositories.ListCommitActivity(context.Background(), "o", "r")
if err != nil {
t.Errorf("RepositoriesService.ListCommitActivity returned error: %v", err)
}
@@ -113,7 +114,7 @@ func TestRepositoriesService_ListCodeFrequency(t *testing.T) {
fmt.Fprint(w, `[[1302998400, 1124, -435]]`)
})
- code, _, err := client.Repositories.ListCodeFrequency("o", "r")
+ code, _, err := client.Repositories.ListCodeFrequency(context.Background(), "o", "r")
if err != nil {
t.Errorf("RepositoriesService.ListCodeFrequency returned error: %v", err)
}
@@ -154,7 +155,7 @@ func TestRepositoriesService_Participation(t *testing.T) {
`)
})
- participation, _, err := client.Repositories.ListParticipation("o", "r")
+ participation, _, err := client.Repositories.ListParticipation(context.Background(), "o", "r")
if err != nil {
t.Errorf("RepositoriesService.ListParticipation returned error: %v", err)
}
@@ -193,7 +194,7 @@ func TestRepositoriesService_ListPunchCard(t *testing.T) {
]`)
})
- card, _, err := client.Repositories.ListPunchCard("o", "r")
+ card, _, err := client.Repositories.ListPunchCard(context.Background(), "o", "r")
if err != nil {
t.Errorf("RepositoriesService.ListPunchCard returned error: %v", err)
}
diff --git a/github/repos_statuses.go b/github/repos_statuses.go
index 65c2e0aba41..6db501076ca 100644
--- a/github/repos_statuses.go
+++ b/github/repos_statuses.go
@@ -6,6 +6,7 @@
package github
import (
+ "context"
"fmt"
"time"
)
@@ -42,7 +43,7 @@ func (r RepoStatus) String() string {
// reference. ref can be a SHA, a branch name, or a tag name.
//
// GitHub API docs: https://developer.github.com/v3/repos/statuses/#list-statuses-for-a-specific-ref
-func (s *RepositoriesService) ListStatuses(owner, repo, ref string, opt *ListOptions) ([]*RepoStatus, *Response, error) {
+func (s *RepositoriesService) ListStatuses(ctx context.Context, owner, repo, ref string, opt *ListOptions) ([]*RepoStatus, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/commits/%v/statuses", owner, repo, ref)
u, err := addOptions(u, opt)
if err != nil {
@@ -55,7 +56,7 @@ func (s *RepositoriesService) ListStatuses(owner, repo, ref string, opt *ListOpt
}
var statuses []*RepoStatus
- resp, err := s.client.Do(req, &statuses)
+ resp, err := s.client.Do(ctx, req, &statuses)
if err != nil {
return nil, resp, err
}
@@ -67,7 +68,7 @@ func (s *RepositoriesService) ListStatuses(owner, repo, ref string, opt *ListOpt
// reference. Ref can be a SHA, a branch name, or a tag name.
//
// GitHub API docs: https://developer.github.com/v3/repos/statuses/#create-a-status
-func (s *RepositoriesService) CreateStatus(owner, repo, ref string, status *RepoStatus) (*RepoStatus, *Response, error) {
+func (s *RepositoriesService) CreateStatus(ctx context.Context, owner, repo, ref string, status *RepoStatus) (*RepoStatus, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/statuses/%v", owner, repo, ref)
req, err := s.client.NewRequest("POST", u, status)
if err != nil {
@@ -75,7 +76,7 @@ func (s *RepositoriesService) CreateStatus(owner, repo, ref string, status *Repo
}
repoStatus := new(RepoStatus)
- resp, err := s.client.Do(req, repoStatus)
+ resp, err := s.client.Do(ctx, req, repoStatus)
if err != nil {
return nil, resp, err
}
@@ -106,7 +107,7 @@ func (s CombinedStatus) String() string {
// reference. ref can be a SHA, a branch name, or a tag name.
//
// GitHub API docs: https://developer.github.com/v3/repos/statuses/#get-the-combined-status-for-a-specific-ref
-func (s *RepositoriesService) GetCombinedStatus(owner, repo, ref string, opt *ListOptions) (*CombinedStatus, *Response, error) {
+func (s *RepositoriesService) GetCombinedStatus(ctx context.Context, owner, repo, ref string, opt *ListOptions) (*CombinedStatus, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/commits/%v/status", owner, repo, ref)
u, err := addOptions(u, opt)
if err != nil {
@@ -119,7 +120,7 @@ func (s *RepositoriesService) GetCombinedStatus(owner, repo, ref string, opt *Li
}
status := new(CombinedStatus)
- resp, err := s.client.Do(req, status)
+ resp, err := s.client.Do(ctx, req, status)
if err != nil {
return nil, resp, err
}
diff --git a/github/repos_statuses_test.go b/github/repos_statuses_test.go
index c1cfc12e025..8e6c9378d27 100644
--- a/github/repos_statuses_test.go
+++ b/github/repos_statuses_test.go
@@ -6,6 +6,7 @@
package github
import (
+ "context"
"encoding/json"
"fmt"
"net/http"
@@ -24,7 +25,7 @@ func TestRepositoriesService_ListStatuses(t *testing.T) {
})
opt := &ListOptions{Page: 2}
- statuses, _, err := client.Repositories.ListStatuses("o", "r", "r", opt)
+ statuses, _, err := client.Repositories.ListStatuses(context.Background(), "o", "r", "r", opt)
if err != nil {
t.Errorf("Repositories.ListStatuses returned error: %v", err)
}
@@ -36,7 +37,7 @@ func TestRepositoriesService_ListStatuses(t *testing.T) {
}
func TestRepositoriesService_ListStatuses_invalidOwner(t *testing.T) {
- _, _, err := client.Repositories.ListStatuses("%", "r", "r", nil)
+ _, _, err := client.Repositories.ListStatuses(context.Background(), "%", "r", "r", nil)
testURLParseError(t, err)
}
@@ -57,7 +58,7 @@ func TestRepositoriesService_CreateStatus(t *testing.T) {
fmt.Fprint(w, `{"id":1}`)
})
- status, _, err := client.Repositories.CreateStatus("o", "r", "r", input)
+ status, _, err := client.Repositories.CreateStatus(context.Background(), "o", "r", "r", input)
if err != nil {
t.Errorf("Repositories.CreateStatus returned error: %v", err)
}
@@ -69,7 +70,7 @@ func TestRepositoriesService_CreateStatus(t *testing.T) {
}
func TestRepositoriesService_CreateStatus_invalidOwner(t *testing.T) {
- _, _, err := client.Repositories.CreateStatus("%", "r", "r", nil)
+ _, _, err := client.Repositories.CreateStatus(context.Background(), "%", "r", "r", nil)
testURLParseError(t, err)
}
@@ -84,7 +85,7 @@ func TestRepositoriesService_GetCombinedStatus(t *testing.T) {
})
opt := &ListOptions{Page: 2}
- status, _, err := client.Repositories.GetCombinedStatus("o", "r", "r", opt)
+ status, _, err := client.Repositories.GetCombinedStatus(context.Background(), "o", "r", "r", opt)
if err != nil {
t.Errorf("Repositories.GetCombinedStatus returned error: %v", err)
}
diff --git a/github/repos_test.go b/github/repos_test.go
index faa9ac679f6..3a98b4fe48e 100644
--- a/github/repos_test.go
+++ b/github/repos_test.go
@@ -6,6 +6,7 @@
package github
import (
+ "context"
"encoding/json"
"fmt"
"net/http"
@@ -24,7 +25,7 @@ func TestRepositoriesService_List_authenticatedUser(t *testing.T) {
fmt.Fprint(w, `[{"id":1},{"id":2}]`)
})
- repos, _, err := client.Repositories.List("", nil)
+ repos, _, err := client.Repositories.List(context.Background(), "", nil)
if err != nil {
t.Errorf("Repositories.List returned error: %v", err)
}
@@ -59,7 +60,7 @@ func TestRepositoriesService_List_specifiedUser(t *testing.T) {
Direction: "asc",
ListOptions: ListOptions{Page: 2},
}
- repos, _, err := client.Repositories.List("u", opt)
+ repos, _, err := client.Repositories.List(context.Background(), "u", opt)
if err != nil {
t.Errorf("Repositories.List returned error: %v", err)
}
@@ -86,7 +87,7 @@ func TestRepositoriesService_List_specifiedUser_type(t *testing.T) {
opt := &RepositoryListOptions{
Type: "owner",
}
- repos, _, err := client.Repositories.List("u", opt)
+ repos, _, err := client.Repositories.List(context.Background(), "u", opt)
if err != nil {
t.Errorf("Repositories.List returned error: %v", err)
}
@@ -98,7 +99,7 @@ func TestRepositoriesService_List_specifiedUser_type(t *testing.T) {
}
func TestRepositoriesService_List_invalidUser(t *testing.T) {
- _, _, err := client.Repositories.List("%", nil)
+ _, _, err := client.Repositories.List(context.Background(), "%", nil)
testURLParseError(t, err)
}
@@ -117,7 +118,7 @@ func TestRepositoriesService_ListByOrg(t *testing.T) {
})
opt := &RepositoryListByOrgOptions{"forks", ListOptions{Page: 2}}
- repos, _, err := client.Repositories.ListByOrg("o", opt)
+ repos, _, err := client.Repositories.ListByOrg(context.Background(), "o", opt)
if err != nil {
t.Errorf("Repositories.ListByOrg returned error: %v", err)
}
@@ -129,7 +130,7 @@ func TestRepositoriesService_ListByOrg(t *testing.T) {
}
func TestRepositoriesService_ListByOrg_invalidOrg(t *testing.T) {
- _, _, err := client.Repositories.ListByOrg("%", nil)
+ _, _, err := client.Repositories.ListByOrg(context.Background(), "%", nil)
testURLParseError(t, err)
}
@@ -148,7 +149,7 @@ func TestRepositoriesService_ListAll(t *testing.T) {
})
opt := &RepositoryListAllOptions{1, ListOptions{2, 3}}
- repos, _, err := client.Repositories.ListAll(opt)
+ repos, _, err := client.Repositories.ListAll(context.Background(), opt)
if err != nil {
t.Errorf("Repositories.ListAll returned error: %v", err)
}
@@ -177,7 +178,7 @@ func TestRepositoriesService_Create_user(t *testing.T) {
fmt.Fprint(w, `{"id":1}`)
})
- repo, _, err := client.Repositories.Create("", input)
+ repo, _, err := client.Repositories.Create(context.Background(), "", input)
if err != nil {
t.Errorf("Repositories.Create returned error: %v", err)
}
@@ -206,7 +207,7 @@ func TestRepositoriesService_Create_org(t *testing.T) {
fmt.Fprint(w, `{"id":1}`)
})
- repo, _, err := client.Repositories.Create("o", input)
+ repo, _, err := client.Repositories.Create(context.Background(), "o", input)
if err != nil {
t.Errorf("Repositories.Create returned error: %v", err)
}
@@ -218,7 +219,7 @@ func TestRepositoriesService_Create_org(t *testing.T) {
}
func TestRepositoriesService_Create_invalidOrg(t *testing.T) {
- _, _, err := client.Repositories.Create("%", nil)
+ _, _, err := client.Repositories.Create(context.Background(), "%", nil)
testURLParseError(t, err)
}
@@ -233,7 +234,7 @@ func TestRepositoriesService_Get(t *testing.T) {
fmt.Fprint(w, `{"id":1,"name":"n","description":"d","owner":{"login":"l"},"license":{"key":"mit"}}`)
})
- repo, _, err := client.Repositories.Get("o", "r")
+ repo, _, err := client.Repositories.Get(context.Background(), "o", "r")
if err != nil {
t.Errorf("Repositories.Get returned error: %v", err)
}
@@ -254,7 +255,7 @@ func TestRepositoriesService_GetByID(t *testing.T) {
fmt.Fprint(w, `{"id":1,"name":"n","description":"d","owner":{"login":"l"},"license":{"key":"mit"}}`)
})
- repo, _, err := client.Repositories.GetByID(1)
+ repo, _, err := client.Repositories.GetByID(context.Background(), 1)
if err != nil {
t.Errorf("Repositories.GetByID returned error: %v", err)
}
@@ -283,7 +284,7 @@ func TestRepositoriesService_Edit(t *testing.T) {
fmt.Fprint(w, `{"id":1}`)
})
- repo, _, err := client.Repositories.Edit("o", "r", input)
+ repo, _, err := client.Repositories.Edit(context.Background(), "o", "r", input)
if err != nil {
t.Errorf("Repositories.Edit returned error: %v", err)
}
@@ -302,19 +303,19 @@ func TestRepositoriesService_Delete(t *testing.T) {
testMethod(t, r, "DELETE")
})
- _, err := client.Repositories.Delete("o", "r")
+ _, err := client.Repositories.Delete(context.Background(), "o", "r")
if err != nil {
t.Errorf("Repositories.Delete returned error: %v", err)
}
}
func TestRepositoriesService_Get_invalidOwner(t *testing.T) {
- _, _, err := client.Repositories.Get("%", "r")
+ _, _, err := client.Repositories.Get(context.Background(), "%", "r")
testURLParseError(t, err)
}
func TestRepositoriesService_Edit_invalidOwner(t *testing.T) {
- _, _, err := client.Repositories.Edit("%", "r", nil)
+ _, _, err := client.Repositories.Edit(context.Background(), "%", "r", nil)
testURLParseError(t, err)
}
@@ -332,7 +333,7 @@ func TestRepositoriesService_ListContributors(t *testing.T) {
})
opts := &ListContributorsOptions{Anon: "true", ListOptions: ListOptions{Page: 2}}
- contributors, _, err := client.Repositories.ListContributors("o", "r", opts)
+ contributors, _, err := client.Repositories.ListContributors(context.Background(), "o", "r", opts)
if err != nil {
t.Errorf("Repositories.ListContributors returned error: %v", err)
}
@@ -352,7 +353,7 @@ func TestRepositoriesService_ListLanguages(t *testing.T) {
fmt.Fprint(w, `{"go":1}`)
})
- languages, _, err := client.Repositories.ListLanguages("o", "r")
+ languages, _, err := client.Repositories.ListLanguages(context.Background(), "o", "r")
if err != nil {
t.Errorf("Repositories.ListLanguages returned error: %v", err)
}
@@ -374,7 +375,7 @@ func TestRepositoriesService_ListTeams(t *testing.T) {
})
opt := &ListOptions{Page: 2}
- teams, _, err := client.Repositories.ListTeams("o", "r", opt)
+ teams, _, err := client.Repositories.ListTeams(context.Background(), "o", "r", opt)
if err != nil {
t.Errorf("Repositories.ListTeams returned error: %v", err)
}
@@ -396,7 +397,7 @@ func TestRepositoriesService_ListTags(t *testing.T) {
})
opt := &ListOptions{Page: 2}
- tags, _, err := client.Repositories.ListTags("o", "r", opt)
+ tags, _, err := client.Repositories.ListTags(context.Background(), "o", "r", opt)
if err != nil {
t.Errorf("Repositories.ListTags returned error: %v", err)
}
@@ -429,7 +430,7 @@ func TestRepositoriesService_ListBranches(t *testing.T) {
})
opt := &ListOptions{Page: 2}
- branches, _, err := client.Repositories.ListBranches("o", "r", opt)
+ branches, _, err := client.Repositories.ListBranches(context.Background(), "o", "r", opt)
if err != nil {
t.Errorf("Repositories.ListBranches returned error: %v", err)
}
@@ -450,7 +451,7 @@ func TestRepositoriesService_GetBranch(t *testing.T) {
fmt.Fprint(w, `{"name":"n", "commit":{"sha":"s","commit":{"message":"m"}}, "protected":true}`)
})
- branch, _, err := client.Repositories.GetBranch("o", "r", "b")
+ branch, _, err := client.Repositories.GetBranch(context.Background(), "o", "r", "b")
if err != nil {
t.Errorf("Repositories.GetBranch returned error: %v", err)
}
@@ -484,7 +485,7 @@ func TestRepositoriesService_GetBranchProtection(t *testing.T) {
fmt.Fprintf(w, `{"required_status_checks":{"include_admins":true,"strict":true,"contexts":["continuous-integration"]},"required_pull_request_reviews":{"include_admins":true},"restrictions":{"users":[{"id":1,"login":"u"}],"teams":[{"id":2,"slug":"t"}]}}`)
})
- protection, _, err := client.Repositories.GetBranchProtection("o", "r", "b")
+ protection, _, err := client.Repositories.GetBranchProtection(context.Background(), "o", "r", "b")
if err != nil {
t.Errorf("Repositories.GetBranchProtection returned error: %v", err)
}
@@ -543,7 +544,7 @@ func TestRepositoriesService_UpdateBranchProtection(t *testing.T) {
fmt.Fprintf(w, `{"required_status_checks":{"include_admins":true,"strict":true,"contexts":["continuous-integration"]},"required_pull_request_reviews":{"include_admins":true},"restrictions":{"users":[{"id":1,"login":"u"}],"teams":[{"id":2,"slug":"t"}]}}`)
})
- protection, _, err := client.Repositories.UpdateBranchProtection("o", "r", "b", input)
+ protection, _, err := client.Repositories.UpdateBranchProtection(context.Background(), "o", "r", "b", input)
if err != nil {
t.Errorf("Repositories.UpdateBranchProtection returned error: %v", err)
}
@@ -581,14 +582,14 @@ func TestRepositoriesService_RemoveBranchProtection(t *testing.T) {
w.WriteHeader(http.StatusNoContent)
})
- _, err := client.Repositories.RemoveBranchProtection("o", "r", "b")
+ _, err := client.Repositories.RemoveBranchProtection(context.Background(), "o", "r", "b")
if err != nil {
t.Errorf("Repositories.RemoveBranchProtection returned error: %v", err)
}
}
func TestRepositoriesService_ListLanguages_invalidOwner(t *testing.T) {
- _, _, err := client.Repositories.ListLanguages("%", "%")
+ _, _, err := client.Repositories.ListLanguages(context.Background(), "%", "%")
testURLParseError(t, err)
}
@@ -601,7 +602,7 @@ func TestRepositoriesService_License(t *testing.T) {
fmt.Fprint(w, `{"name": "LICENSE", "path": "LICENSE", "license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit","featured":true}}`)
})
- got, _, err := client.Repositories.License("o", "r")
+ got, _, err := client.Repositories.License(context.Background(), "o", "r")
if err != nil {
t.Errorf("Repositories.License returned error: %v", err)
}
diff --git a/github/repos_traffic.go b/github/repos_traffic.go
index 67341b953d5..fb1c97648a7 100644
--- a/github/repos_traffic.go
+++ b/github/repos_traffic.go
@@ -5,7 +5,10 @@
package github
-import "fmt"
+import (
+ "context"
+ "fmt"
+)
// TrafficReferrer represent information about traffic from a referrer .
type TrafficReferrer struct {
@@ -52,7 +55,7 @@ type TrafficBreakdownOptions struct {
// ListTrafficReferrers list the top 10 referrers over the last 14 days.
//
// GitHub API docs: https://developer.github.com/v3/repos/traffic/#list-referrers
-func (s *RepositoriesService) ListTrafficReferrers(owner, repo string) ([]*TrafficReferrer, *Response, error) {
+func (s *RepositoriesService) ListTrafficReferrers(ctx context.Context, owner, repo string) ([]*TrafficReferrer, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/traffic/popular/referrers", owner, repo)
req, err := s.client.NewRequest("GET", u, nil)
@@ -61,7 +64,7 @@ func (s *RepositoriesService) ListTrafficReferrers(owner, repo string) ([]*Traff
}
var trafficReferrers []*TrafficReferrer
- resp, err := s.client.Do(req, &trafficReferrers)
+ resp, err := s.client.Do(ctx, req, &trafficReferrers)
if err != nil {
return nil, resp, err
}
@@ -72,7 +75,7 @@ func (s *RepositoriesService) ListTrafficReferrers(owner, repo string) ([]*Traff
// ListTrafficPaths list the top 10 popular content over the last 14 days.
//
// GitHub API docs: https://developer.github.com/v3/repos/traffic/#list-paths
-func (s *RepositoriesService) ListTrafficPaths(owner, repo string) ([]*TrafficPath, *Response, error) {
+func (s *RepositoriesService) ListTrafficPaths(ctx context.Context, owner, repo string) ([]*TrafficPath, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/traffic/popular/paths", owner, repo)
req, err := s.client.NewRequest("GET", u, nil)
@@ -81,7 +84,7 @@ func (s *RepositoriesService) ListTrafficPaths(owner, repo string) ([]*TrafficPa
}
var paths []*TrafficPath
- resp, err := s.client.Do(req, &paths)
+ resp, err := s.client.Do(ctx, req, &paths)
if err != nil {
return nil, resp, err
}
@@ -92,7 +95,7 @@ func (s *RepositoriesService) ListTrafficPaths(owner, repo string) ([]*TrafficPa
// ListTrafficViews get total number of views for the last 14 days and breaks it down either per day or week.
//
// GitHub API docs: https://developer.github.com/v3/repos/traffic/#views
-func (s *RepositoriesService) ListTrafficViews(owner, repo string, opt *TrafficBreakdownOptions) (*TrafficViews, *Response, error) {
+func (s *RepositoriesService) ListTrafficViews(ctx context.Context, owner, repo string, opt *TrafficBreakdownOptions) (*TrafficViews, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/traffic/views", owner, repo)
u, err := addOptions(u, opt)
if err != nil {
@@ -105,7 +108,7 @@ func (s *RepositoriesService) ListTrafficViews(owner, repo string, opt *TrafficB
}
trafficViews := new(TrafficViews)
- resp, err := s.client.Do(req, &trafficViews)
+ resp, err := s.client.Do(ctx, req, &trafficViews)
if err != nil {
return nil, resp, err
}
@@ -116,7 +119,7 @@ func (s *RepositoriesService) ListTrafficViews(owner, repo string, opt *TrafficB
// ListTrafficClones get total number of clones for the last 14 days and breaks it down either per day or week for the last 14 days.
//
// GitHub API docs: https://developer.github.com/v3/repos/traffic/#views
-func (s *RepositoriesService) ListTrafficClones(owner, repo string, opt *TrafficBreakdownOptions) (*TrafficClones, *Response, error) {
+func (s *RepositoriesService) ListTrafficClones(ctx context.Context, owner, repo string, opt *TrafficBreakdownOptions) (*TrafficClones, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/traffic/clones", owner, repo)
u, err := addOptions(u, opt)
if err != nil {
@@ -129,7 +132,7 @@ func (s *RepositoriesService) ListTrafficClones(owner, repo string, opt *Traffic
}
trafficClones := new(TrafficClones)
- resp, err := s.client.Do(req, &trafficClones)
+ resp, err := s.client.Do(ctx, req, &trafficClones)
if err != nil {
return nil, resp, err
}
diff --git a/github/repos_traffic_test.go b/github/repos_traffic_test.go
index 027ecb2019b..c425f5cd5d1 100644
--- a/github/repos_traffic_test.go
+++ b/github/repos_traffic_test.go
@@ -6,6 +6,7 @@
package github
import (
+ "context"
"fmt"
"net/http"
"reflect"
@@ -25,7 +26,7 @@ func TestRepositoriesService_ListTrafficReferrers(t *testing.T) {
"uniques": 3
}]`)
})
- referrers, _, err := client.Repositories.ListTrafficReferrers("o", "r")
+ referrers, _, err := client.Repositories.ListTrafficReferrers(context.Background(), "o", "r")
if err != nil {
t.Errorf("Repositories.ListPaths returned error: %+v", err)
}
@@ -54,7 +55,7 @@ func TestRepositoriesService_ListTrafficPaths(t *testing.T) {
"uniques": 2225
}]`)
})
- paths, _, err := client.Repositories.ListTrafficPaths("o", "r")
+ paths, _, err := client.Repositories.ListTrafficPaths(context.Background(), "o", "r")
if err != nil {
t.Errorf("Repositories.ListPaths returned error: %+v", err)
}
@@ -86,7 +87,7 @@ func TestRepositoriesService_ListTrafficViews(t *testing.T) {
}]}`)
})
- views, _, err := client.Repositories.ListTrafficViews("o", "r", nil)
+ views, _, err := client.Repositories.ListTrafficViews(context.Background(), "o", "r", nil)
if err != nil {
t.Errorf("Repositories.ListPaths returned error: %+v", err)
}
@@ -122,7 +123,7 @@ func TestRepositoriesService_ListTrafficClones(t *testing.T) {
}]}`)
})
- clones, _, err := client.Repositories.ListTrafficClones("o", "r", nil)
+ clones, _, err := client.Repositories.ListTrafficClones(context.Background(), "o", "r", nil)
if err != nil {
t.Errorf("Repositories.ListPaths returned error: %+v", err)
}
diff --git a/github/search.go b/github/search.go
index e48f3ea83b7..84d2491715a 100644
--- a/github/search.go
+++ b/github/search.go
@@ -6,6 +6,7 @@
package github
import (
+ "context"
"fmt"
qs "github.com/google/go-querystring/query"
@@ -49,9 +50,9 @@ type RepositoriesSearchResult struct {
// Repositories searches repositories via various criteria.
//
// GitHub API docs: https://developer.github.com/v3/search/#search-repositories
-func (s *SearchService) Repositories(query string, opt *SearchOptions) (*RepositoriesSearchResult, *Response, error) {
+func (s *SearchService) Repositories(ctx context.Context, query string, opt *SearchOptions) (*RepositoriesSearchResult, *Response, error) {
result := new(RepositoriesSearchResult)
- resp, err := s.search("repositories", query, opt, result)
+ resp, err := s.search(ctx, "repositories", query, opt, result)
return result, resp, err
}
@@ -80,9 +81,9 @@ type CommitResult struct {
// Commits searches commits via various criteria.
//
// GitHub API Docs: https://developer.github.com/v3/search/#search-commits
-func (s *SearchService) Commits(query string, opt *SearchOptions) (*CommitsSearchResult, *Response, error) {
+func (s *SearchService) Commits(ctx context.Context, query string, opt *SearchOptions) (*CommitsSearchResult, *Response, error) {
result := new(CommitsSearchResult)
- resp, err := s.search("commits", query, opt, result)
+ resp, err := s.search(ctx, "commits", query, opt, result)
return result, resp, err
}
@@ -96,9 +97,9 @@ type IssuesSearchResult struct {
// Issues searches issues via various criteria.
//
// GitHub API docs: https://developer.github.com/v3/search/#search-issues
-func (s *SearchService) Issues(query string, opt *SearchOptions) (*IssuesSearchResult, *Response, error) {
+func (s *SearchService) Issues(ctx context.Context, query string, opt *SearchOptions) (*IssuesSearchResult, *Response, error) {
result := new(IssuesSearchResult)
- resp, err := s.search("issues", query, opt, result)
+ resp, err := s.search(ctx, "issues", query, opt, result)
return result, resp, err
}
@@ -112,9 +113,9 @@ type UsersSearchResult struct {
// Users searches users via various criteria.
//
// GitHub API docs: https://developer.github.com/v3/search/#search-users
-func (s *SearchService) Users(query string, opt *SearchOptions) (*UsersSearchResult, *Response, error) {
+func (s *SearchService) Users(ctx context.Context, query string, opt *SearchOptions) (*UsersSearchResult, *Response, error) {
result := new(UsersSearchResult)
- resp, err := s.search("users", query, opt, result)
+ resp, err := s.search(ctx, "users", query, opt, result)
return result, resp, err
}
@@ -161,15 +162,15 @@ func (c CodeResult) String() string {
// Code searches code via various criteria.
//
// GitHub API docs: https://developer.github.com/v3/search/#search-code
-func (s *SearchService) Code(query string, opt *SearchOptions) (*CodeSearchResult, *Response, error) {
+func (s *SearchService) Code(ctx context.Context, query string, opt *SearchOptions) (*CodeSearchResult, *Response, error) {
result := new(CodeSearchResult)
- resp, err := s.search("code", query, opt, result)
+ resp, err := s.search(ctx, "code", query, opt, result)
return result, resp, err
}
// Helper function that executes search queries against different
// GitHub search types (repositories, commits, code, issues, users)
-func (s *SearchService) search(searchType string, query string, opt *SearchOptions, result interface{}) (*Response, error) {
+func (s *SearchService) search(ctx context.Context, searchType string, query string, opt *SearchOptions, result interface{}) (*Response, error) {
params, err := qs.Values(opt)
if err != nil {
return nil, err
@@ -193,5 +194,5 @@ func (s *SearchService) search(searchType string, query string, opt *SearchOptio
req.Header.Set("Accept", "application/vnd.github.v3.text-match+json")
}
- return s.client.Do(req, result)
+ return s.client.Do(ctx, req, result)
}
diff --git a/github/search_test.go b/github/search_test.go
index 0427a8bb485..3126bc8de35 100644
--- a/github/search_test.go
+++ b/github/search_test.go
@@ -6,6 +6,7 @@
package github
import (
+ "context"
"fmt"
"net/http"
"reflect"
@@ -31,7 +32,7 @@ func TestSearchService_Repositories(t *testing.T) {
})
opts := &SearchOptions{Sort: "forks", Order: "desc", ListOptions: ListOptions{Page: 2, PerPage: 2}}
- result, _, err := client.Search.Repositories("blah", opts)
+ result, _, err := client.Search.Repositories(context.Background(), "blah", opts)
if err != nil {
t.Errorf("Search.Repositories returned error: %v", err)
}
@@ -62,7 +63,7 @@ func TestSearchService_Commits(t *testing.T) {
})
opts := &SearchOptions{Sort: "author-date", Order: "desc"}
- result, _, err := client.Search.Commits("blah", opts)
+ result, _, err := client.Search.Commits(context.Background(), "blah", opts)
if err != nil {
t.Errorf("Search.Commits returned error: %v", err)
}
@@ -95,7 +96,7 @@ func TestSearchService_Issues(t *testing.T) {
})
opts := &SearchOptions{Sort: "forks", Order: "desc", ListOptions: ListOptions{Page: 2, PerPage: 2}}
- result, _, err := client.Search.Issues("blah", opts)
+ result, _, err := client.Search.Issues(context.Background(), "blah", opts)
if err != nil {
t.Errorf("Search.Issues returned error: %v", err)
}
@@ -128,7 +129,7 @@ func TestSearchService_Users(t *testing.T) {
})
opts := &SearchOptions{Sort: "forks", Order: "desc", ListOptions: ListOptions{Page: 2, PerPage: 2}}
- result, _, err := client.Search.Users("blah", opts)
+ result, _, err := client.Search.Users(context.Background(), "blah", opts)
if err != nil {
t.Errorf("Search.Issues returned error: %v", err)
}
@@ -161,7 +162,7 @@ func TestSearchService_Code(t *testing.T) {
})
opts := &SearchOptions{Sort: "forks", Order: "desc", ListOptions: ListOptions{Page: 2, PerPage: 2}}
- result, _, err := client.Search.Code("blah", opts)
+ result, _, err := client.Search.Code(context.Background(), "blah", opts)
if err != nil {
t.Errorf("Search.Code returned error: %v", err)
}
@@ -213,7 +214,7 @@ func TestSearchService_CodeTextMatch(t *testing.T) {
})
opts := &SearchOptions{Sort: "forks", Order: "desc", ListOptions: ListOptions{Page: 2, PerPage: 2}, TextMatch: true}
- result, _, err := client.Search.Code("blah", opts)
+ result, _, err := client.Search.Code(context.Background(), "blah", opts)
if err != nil {
t.Errorf("Search.Code returned error: %v", err)
}
diff --git a/github/users.go b/github/users.go
index 7639cb2ff02..d74439c7b04 100644
--- a/github/users.go
+++ b/github/users.go
@@ -5,7 +5,10 @@
package github
-import "fmt"
+import (
+ "context"
+ "fmt"
+)
// UsersService handles communication with the user related
// methods of the GitHub API.
@@ -72,7 +75,7 @@ func (u User) String() string {
// user.
//
// GitHub API docs: https://developer.github.com/v3/users/#get-a-single-user
-func (s *UsersService) Get(user string) (*User, *Response, error) {
+func (s *UsersService) Get(ctx context.Context, user string) (*User, *Response, error) {
var u string
if user != "" {
u = fmt.Sprintf("users/%v", user)
@@ -85,7 +88,7 @@ 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
}
@@ -96,7 +99,7 @@ func (s *UsersService) Get(user string) (*User, *Response, error) {
// 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 int) (*User, *Response, error) {
u := fmt.Sprintf("user/%d", id)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
@@ -104,7 +107,7 @@ 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
}
@@ -115,7 +118,7 @@ func (s *UsersService) GetByID(id int) (*User, *Response, error) {
// Edit the authenticated user.
//
// GitHub API docs: https://developer.github.com/v3/users/#update-the-authenticated-user
-func (s *UsersService) Edit(user *User) (*User, *Response, error) {
+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 {
@@ -123,7 +126,7 @@ 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
}
@@ -145,7 +148,7 @@ type UserListOptions struct {
// To paginate through all users, populate 'Since' with the ID of the last user.
//
// GitHub API docs: https://developer.github.com/v3/users/#get-all-users
-func (s *UsersService) ListAll(opt *UserListOptions) ([]*User, *Response, error) {
+func (s *UsersService) ListAll(ctx context.Context, opt *UserListOptions) ([]*User, *Response, error) {
u, err := addOptions("users", opt)
if err != nil {
return nil, nil, err
@@ -157,7 +160,7 @@ func (s *UsersService) ListAll(opt *UserListOptions) ([]*User, *Response, error)
}
var users []*User
- resp, err := s.client.Do(req, &users)
+ resp, err := s.client.Do(ctx, req, &users)
if err != nil {
return nil, resp, err
}
@@ -169,7 +172,7 @@ func (s *UsersService) ListAll(opt *UserListOptions) ([]*User, *Response, error)
// authenticated user.
//
// GitHub API docs: https://developer.github.com/v3/repos/invitations/#list-a-users-repository-invitations
-func (s *UsersService) ListInvitations() ([]*RepositoryInvitation, *Response, error) {
+func (s *UsersService) ListInvitations(ctx context.Context) ([]*RepositoryInvitation, *Response, error) {
req, err := s.client.NewRequest("GET", "user/repository_invitations", nil)
if err != nil {
return nil, nil, err
@@ -179,7 +182,7 @@ 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
}
@@ -191,7 +194,7 @@ func (s *UsersService) ListInvitations() ([]*RepositoryInvitation, *Response, er
// 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 int) (*Response, error) {
u := fmt.Sprintf("user/repository_invitations/%v", invitationID)
req, err := s.client.NewRequest("PATCH", u, nil)
if err != nil {
@@ -201,14 +204,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 int) (*Response, error) {
u := fmt.Sprintf("user/repository_invitations/%v", invitationID)
req, err := s.client.NewRequest("DELETE", u, nil)
if err != nil {
@@ -218,5 +221,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)
}
diff --git a/github/users_administration.go b/github/users_administration.go
index dc1dcb89499..e042398d8c5 100644
--- a/github/users_administration.go
+++ b/github/users_administration.go
@@ -5,12 +5,15 @@
package github
-import "fmt"
+import (
+ "context"
+ "fmt"
+)
// PromoteSiteAdmin promotes a user to a site administrator of a GitHub Enterprise instance.
//
// GitHub API docs: https://developer.github.com/v3/users/administration/#promote-an-ordinary-user-to-a-site-administrator
-func (s *UsersService) PromoteSiteAdmin(user string) (*Response, error) {
+func (s *UsersService) PromoteSiteAdmin(ctx context.Context, user string) (*Response, error) {
u := fmt.Sprintf("users/%v/site_admin", user)
req, err := s.client.NewRequest("PUT", u, nil)
@@ -18,13 +21,13 @@ func (s *UsersService) PromoteSiteAdmin(user string) (*Response, error) {
return nil, err
}
- return s.client.Do(req, nil)
+ return s.client.Do(ctx, req, nil)
}
// DemoteSiteAdmin demotes a user from site administrator of a GitHub Enterprise instance.
//
// GitHub API docs: https://developer.github.com/v3/users/administration/#demote-a-site-administrator-to-an-ordinary-user
-func (s *UsersService) DemoteSiteAdmin(user string) (*Response, error) {
+func (s *UsersService) DemoteSiteAdmin(ctx context.Context, user string) (*Response, error) {
u := fmt.Sprintf("users/%v/site_admin", user)
req, err := s.client.NewRequest("DELETE", u, nil)
@@ -32,13 +35,13 @@ func (s *UsersService) DemoteSiteAdmin(user string) (*Response, error) {
return nil, err
}
- return s.client.Do(req, nil)
+ return s.client.Do(ctx, req, nil)
}
// Suspend a user on a GitHub Enterprise instance.
//
// GitHub API docs: https://developer.github.com/v3/users/administration/#suspend-a-user
-func (s *UsersService) Suspend(user string) (*Response, error) {
+func (s *UsersService) Suspend(ctx context.Context, user string) (*Response, error) {
u := fmt.Sprintf("users/%v/suspended", user)
req, err := s.client.NewRequest("PUT", u, nil)
@@ -46,13 +49,13 @@ func (s *UsersService) Suspend(user string) (*Response, error) {
return nil, err
}
- return s.client.Do(req, nil)
+ return s.client.Do(ctx, req, nil)
}
// Unsuspend a user on a GitHub Enterprise instance.
//
// GitHub API docs: https://developer.github.com/v3/users/administration/#unsuspend-a-user
-func (s *UsersService) Unsuspend(user string) (*Response, error) {
+func (s *UsersService) Unsuspend(ctx context.Context, user string) (*Response, error) {
u := fmt.Sprintf("users/%v/suspended", user)
req, err := s.client.NewRequest("DELETE", u, nil)
@@ -60,5 +63,5 @@ func (s *UsersService) Unsuspend(user string) (*Response, error) {
return nil, err
}
- return s.client.Do(req, nil)
+ return s.client.Do(ctx, req, nil)
}
diff --git a/github/users_administration_test.go b/github/users_administration_test.go
index d415f4d4aa5..8f02b88cea7 100644
--- a/github/users_administration_test.go
+++ b/github/users_administration_test.go
@@ -6,6 +6,7 @@
package github
import (
+ "context"
"net/http"
"testing"
)
@@ -19,7 +20,7 @@ func TestUsersService_PromoteSiteAdmin(t *testing.T) {
w.WriteHeader(http.StatusNoContent)
})
- _, err := client.Users.PromoteSiteAdmin("u")
+ _, err := client.Users.PromoteSiteAdmin(context.Background(), "u")
if err != nil {
t.Errorf("Users.PromoteSiteAdmin returned error: %v", err)
}
@@ -34,7 +35,7 @@ func TestUsersService_DemoteSiteAdmin(t *testing.T) {
w.WriteHeader(http.StatusNoContent)
})
- _, err := client.Users.DemoteSiteAdmin("u")
+ _, err := client.Users.DemoteSiteAdmin(context.Background(), "u")
if err != nil {
t.Errorf("Users.DemoteSiteAdmin returned error: %v", err)
}
@@ -49,7 +50,7 @@ func TestUsersService_Suspend(t *testing.T) {
w.WriteHeader(http.StatusNoContent)
})
- _, err := client.Users.Suspend("u")
+ _, err := client.Users.Suspend(context.Background(), "u")
if err != nil {
t.Errorf("Users.Suspend returned error: %v", err)
}
@@ -64,7 +65,7 @@ func TestUsersService_Unsuspend(t *testing.T) {
w.WriteHeader(http.StatusNoContent)
})
- _, err := client.Users.Unsuspend("u")
+ _, err := client.Users.Unsuspend(context.Background(), "u")
if err != nil {
t.Errorf("Users.Unsuspend returned error: %v", err)
}
diff --git a/github/users_emails.go b/github/users_emails.go
index f236b427b5f..0bbd4627e3b 100644
--- a/github/users_emails.go
+++ b/github/users_emails.go
@@ -5,6 +5,8 @@
package github
+import "context"
+
// UserEmail represents user's email address
type UserEmail struct {
Email *string `json:"email,omitempty"`
@@ -15,7 +17,7 @@ type UserEmail struct {
// ListEmails lists all email addresses for the authenticated user.
//
// GitHub API docs: https://developer.github.com/v3/users/emails/#list-email-addresses-for-a-user
-func (s *UsersService) ListEmails(opt *ListOptions) ([]*UserEmail, *Response, error) {
+func (s *UsersService) ListEmails(ctx context.Context, opt *ListOptions) ([]*UserEmail, *Response, error) {
u := "user/emails"
u, err := addOptions(u, opt)
if err != nil {
@@ -28,7 +30,7 @@ func (s *UsersService) ListEmails(opt *ListOptions) ([]*UserEmail, *Response, er
}
var emails []*UserEmail
- resp, err := s.client.Do(req, &emails)
+ resp, err := s.client.Do(ctx, req, &emails)
if err != nil {
return nil, resp, err
}
@@ -39,7 +41,7 @@ func (s *UsersService) ListEmails(opt *ListOptions) ([]*UserEmail, *Response, er
// AddEmails adds email addresses of the authenticated user.
//
// GitHub API docs: https://developer.github.com/v3/users/emails/#add-email-addresses
-func (s *UsersService) AddEmails(emails []string) ([]*UserEmail, *Response, error) {
+func (s *UsersService) AddEmails(ctx context.Context, emails []string) ([]*UserEmail, *Response, error) {
u := "user/emails"
req, err := s.client.NewRequest("POST", u, emails)
if err != nil {
@@ -47,7 +49,7 @@ func (s *UsersService) AddEmails(emails []string) ([]*UserEmail, *Response, erro
}
var e []*UserEmail
- resp, err := s.client.Do(req, &e)
+ resp, err := s.client.Do(ctx, req, &e)
if err != nil {
return nil, resp, err
}
@@ -58,12 +60,12 @@ func (s *UsersService) AddEmails(emails []string) ([]*UserEmail, *Response, erro
// DeleteEmails deletes email addresses from authenticated user.
//
// GitHub API docs: https://developer.github.com/v3/users/emails/#delete-email-addresses
-func (s *UsersService) DeleteEmails(emails []string) (*Response, error) {
+func (s *UsersService) DeleteEmails(ctx context.Context, emails []string) (*Response, error) {
u := "user/emails"
req, err := s.client.NewRequest("DELETE", u, emails)
if err != nil {
return nil, err
}
- return s.client.Do(req, nil)
+ return s.client.Do(ctx, req, nil)
}
diff --git a/github/users_emails_test.go b/github/users_emails_test.go
index f030331d16d..3f8176a0078 100644
--- a/github/users_emails_test.go
+++ b/github/users_emails_test.go
@@ -6,6 +6,7 @@
package github
import (
+ "context"
"encoding/json"
"fmt"
"net/http"
@@ -28,7 +29,7 @@ func TestUsersService_ListEmails(t *testing.T) {
})
opt := &ListOptions{Page: 2}
- emails, _, err := client.Users.ListEmails(opt)
+ emails, _, err := client.Users.ListEmails(context.Background(), opt)
if err != nil {
t.Errorf("Users.ListEmails returned error: %v", err)
}
@@ -57,7 +58,7 @@ func TestUsersService_AddEmails(t *testing.T) {
fmt.Fprint(w, `[{"email":"old@example.com"}, {"email":"new@example.com"}]`)
})
- emails, _, err := client.Users.AddEmails(input)
+ emails, _, err := client.Users.AddEmails(context.Background(), input)
if err != nil {
t.Errorf("Users.AddEmails returned error: %v", err)
}
@@ -87,7 +88,7 @@ func TestUsersService_DeleteEmails(t *testing.T) {
}
})
- _, err := client.Users.DeleteEmails(input)
+ _, err := client.Users.DeleteEmails(context.Background(), input)
if err != nil {
t.Errorf("Users.DeleteEmails returned error: %v", err)
}
diff --git a/github/users_followers.go b/github/users_followers.go
index 9e81b60081c..c2224096a62 100644
--- a/github/users_followers.go
+++ b/github/users_followers.go
@@ -5,13 +5,16 @@
package github
-import "fmt"
+import (
+ "context"
+ "fmt"
+)
// ListFollowers lists the followers for a user. Passing the empty string will
// fetch followers for the authenticated user.
//
// GitHub API docs: https://developer.github.com/v3/users/followers/#list-followers-of-a-user
-func (s *UsersService) ListFollowers(user string, opt *ListOptions) ([]*User, *Response, error) {
+func (s *UsersService) ListFollowers(ctx context.Context, user string, opt *ListOptions) ([]*User, *Response, error) {
var u string
if user != "" {
u = fmt.Sprintf("users/%v/followers", user)
@@ -29,7 +32,7 @@ func (s *UsersService) ListFollowers(user string, opt *ListOptions) ([]*User, *R
}
var users []*User
- resp, err := s.client.Do(req, &users)
+ resp, err := s.client.Do(ctx, req, &users)
if err != nil {
return nil, resp, err
}
@@ -41,7 +44,7 @@ func (s *UsersService) ListFollowers(user string, opt *ListOptions) ([]*User, *R
// string will list people the authenticated user is following.
//
// GitHub API docs: https://developer.github.com/v3/users/followers/#list-users-followed-by-another-user
-func (s *UsersService) ListFollowing(user string, opt *ListOptions) ([]*User, *Response, error) {
+func (s *UsersService) ListFollowing(ctx context.Context, user string, opt *ListOptions) ([]*User, *Response, error) {
var u string
if user != "" {
u = fmt.Sprintf("users/%v/following", user)
@@ -59,7 +62,7 @@ func (s *UsersService) ListFollowing(user string, opt *ListOptions) ([]*User, *R
}
var users []*User
- resp, err := s.client.Do(req, &users)
+ resp, err := s.client.Do(ctx, req, &users)
if err != nil {
return nil, resp, err
}
@@ -71,7 +74,7 @@ func (s *UsersService) ListFollowing(user string, opt *ListOptions) ([]*User, *R
// string for "user" will check if the authenticated user is following "target".
//
// GitHub API docs: https://developer.github.com/v3/users/followers/#check-if-you-are-following-a-user
-func (s *UsersService) IsFollowing(user, target string) (bool, *Response, error) {
+func (s *UsersService) IsFollowing(ctx context.Context, user, target string) (bool, *Response, error) {
var u string
if user != "" {
u = fmt.Sprintf("users/%v/following/%v", user, target)
@@ -84,7 +87,7 @@ func (s *UsersService) IsFollowing(user, target string) (bool, *Response, error)
return false, nil, err
}
- resp, err := s.client.Do(req, nil)
+ resp, err := s.client.Do(ctx, req, nil)
following, err := parseBoolResponse(err)
return following, resp, err
}
@@ -92,25 +95,25 @@ func (s *UsersService) IsFollowing(user, target string) (bool, *Response, error)
// Follow will cause the authenticated user to follow the specified user.
//
// GitHub API docs: https://developer.github.com/v3/users/followers/#follow-a-user
-func (s *UsersService) Follow(user string) (*Response, error) {
+func (s *UsersService) Follow(ctx context.Context, user string) (*Response, error) {
u := fmt.Sprintf("user/following/%v", user)
req, err := s.client.NewRequest("PUT", u, nil)
if err != nil {
return nil, err
}
- return s.client.Do(req, nil)
+ return s.client.Do(ctx, req, nil)
}
// Unfollow will cause the authenticated user to unfollow the specified user.
//
// GitHub API docs: https://developer.github.com/v3/users/followers/#unfollow-a-user
-func (s *UsersService) Unfollow(user string) (*Response, error) {
+func (s *UsersService) Unfollow(ctx context.Context, user string) (*Response, error) {
u := fmt.Sprintf("user/following/%v", user)
req, err := s.client.NewRequest("DELETE", u, nil)
if err != nil {
return nil, err
}
- return s.client.Do(req, nil)
+ return s.client.Do(ctx, req, nil)
}
diff --git a/github/users_followers_test.go b/github/users_followers_test.go
index 044772161fe..688af2c4450 100644
--- a/github/users_followers_test.go
+++ b/github/users_followers_test.go
@@ -6,6 +6,7 @@
package github
import (
+ "context"
"fmt"
"net/http"
"reflect"
@@ -23,7 +24,7 @@ func TestUsersService_ListFollowers_authenticatedUser(t *testing.T) {
})
opt := &ListOptions{Page: 2}
- users, _, err := client.Users.ListFollowers("", opt)
+ users, _, err := client.Users.ListFollowers(context.Background(), "", opt)
if err != nil {
t.Errorf("Users.ListFollowers returned error: %v", err)
}
@@ -43,7 +44,7 @@ func TestUsersService_ListFollowers_specifiedUser(t *testing.T) {
fmt.Fprint(w, `[{"id":1}]`)
})
- users, _, err := client.Users.ListFollowers("u", nil)
+ users, _, err := client.Users.ListFollowers(context.Background(), "u", nil)
if err != nil {
t.Errorf("Users.ListFollowers returned error: %v", err)
}
@@ -55,7 +56,7 @@ func TestUsersService_ListFollowers_specifiedUser(t *testing.T) {
}
func TestUsersService_ListFollowers_invalidUser(t *testing.T) {
- _, _, err := client.Users.ListFollowers("%", nil)
+ _, _, err := client.Users.ListFollowers(context.Background(), "%", nil)
testURLParseError(t, err)
}
@@ -70,7 +71,7 @@ func TestUsersService_ListFollowing_authenticatedUser(t *testing.T) {
})
opts := &ListOptions{Page: 2}
- users, _, err := client.Users.ListFollowing("", opts)
+ users, _, err := client.Users.ListFollowing(context.Background(), "", opts)
if err != nil {
t.Errorf("Users.ListFollowing returned error: %v", err)
}
@@ -90,7 +91,7 @@ func TestUsersService_ListFollowing_specifiedUser(t *testing.T) {
fmt.Fprint(w, `[{"id":1}]`)
})
- users, _, err := client.Users.ListFollowing("u", nil)
+ users, _, err := client.Users.ListFollowing(context.Background(), "u", nil)
if err != nil {
t.Errorf("Users.ListFollowing returned error: %v", err)
}
@@ -102,7 +103,7 @@ func TestUsersService_ListFollowing_specifiedUser(t *testing.T) {
}
func TestUsersService_ListFollowing_invalidUser(t *testing.T) {
- _, _, err := client.Users.ListFollowing("%", nil)
+ _, _, err := client.Users.ListFollowing(context.Background(), "%", nil)
testURLParseError(t, err)
}
@@ -115,7 +116,7 @@ func TestUsersService_IsFollowing_authenticatedUser(t *testing.T) {
w.WriteHeader(http.StatusNoContent)
})
- following, _, err := client.Users.IsFollowing("", "t")
+ following, _, err := client.Users.IsFollowing(context.Background(), "", "t")
if err != nil {
t.Errorf("Users.IsFollowing returned error: %v", err)
}
@@ -133,7 +134,7 @@ func TestUsersService_IsFollowing_specifiedUser(t *testing.T) {
w.WriteHeader(http.StatusNoContent)
})
- following, _, err := client.Users.IsFollowing("u", "t")
+ following, _, err := client.Users.IsFollowing(context.Background(), "u", "t")
if err != nil {
t.Errorf("Users.IsFollowing returned error: %v", err)
}
@@ -151,7 +152,7 @@ func TestUsersService_IsFollowing_false(t *testing.T) {
w.WriteHeader(http.StatusNotFound)
})
- following, _, err := client.Users.IsFollowing("u", "t")
+ following, _, err := client.Users.IsFollowing(context.Background(), "u", "t")
if err != nil {
t.Errorf("Users.IsFollowing returned error: %v", err)
}
@@ -169,7 +170,7 @@ func TestUsersService_IsFollowing_error(t *testing.T) {
http.Error(w, "BadRequest", http.StatusBadRequest)
})
- following, _, err := client.Users.IsFollowing("u", "t")
+ following, _, err := client.Users.IsFollowing(context.Background(), "u", "t")
if err == nil {
t.Errorf("Expected HTTP 400 response")
}
@@ -179,7 +180,7 @@ func TestUsersService_IsFollowing_error(t *testing.T) {
}
func TestUsersService_IsFollowing_invalidUser(t *testing.T) {
- _, _, err := client.Users.IsFollowing("%", "%")
+ _, _, err := client.Users.IsFollowing(context.Background(), "%", "%")
testURLParseError(t, err)
}
@@ -191,14 +192,14 @@ func TestUsersService_Follow(t *testing.T) {
testMethod(t, r, "PUT")
})
- _, err := client.Users.Follow("u")
+ _, err := client.Users.Follow(context.Background(), "u")
if err != nil {
t.Errorf("Users.Follow returned error: %v", err)
}
}
func TestUsersService_Follow_invalidUser(t *testing.T) {
- _, err := client.Users.Follow("%")
+ _, err := client.Users.Follow(context.Background(), "%")
testURLParseError(t, err)
}
@@ -210,13 +211,13 @@ func TestUsersService_Unfollow(t *testing.T) {
testMethod(t, r, "DELETE")
})
- _, err := client.Users.Unfollow("u")
+ _, err := client.Users.Unfollow(context.Background(), "u")
if err != nil {
t.Errorf("Users.Follow returned error: %v", err)
}
}
func TestUsersService_Unfollow_invalidUser(t *testing.T) {
- _, err := client.Users.Unfollow("%")
+ _, err := client.Users.Unfollow(context.Background(), "%")
testURLParseError(t, err)
}
diff --git a/github/users_gpg_keys.go b/github/users_gpg_keys.go
index 1576365f5bc..35cce020923 100644
--- a/github/users_gpg_keys.go
+++ b/github/users_gpg_keys.go
@@ -6,6 +6,7 @@
package github
import (
+ "context"
"fmt"
"time"
)
@@ -43,7 +44,7 @@ type GPGEmail struct {
// via Basic Auth or via OAuth with at least read:gpg_key scope.
//
// GitHub API docs: https://developer.github.com/v3/users/gpg_keys/#list-your-gpg-keys
-func (s *UsersService) ListGPGKeys() ([]*GPGKey, *Response, error) {
+func (s *UsersService) ListGPGKeys(ctx context.Context) ([]*GPGKey, *Response, error) {
req, err := s.client.NewRequest("GET", "user/gpg_keys", nil)
if err != nil {
return nil, nil, err
@@ -53,7 +54,7 @@ func (s *UsersService) ListGPGKeys() ([]*GPGKey, *Response, error) {
req.Header.Set("Accept", mediaTypeGitSigningPreview)
var keys []*GPGKey
- resp, err := s.client.Do(req, &keys)
+ resp, err := s.client.Do(ctx, req, &keys)
if err != nil {
return nil, resp, err
}
@@ -65,7 +66,7 @@ func (s *UsersService) ListGPGKeys() ([]*GPGKey, *Response, error) {
// via Basic Auth or via OAuth with at least read:gpg_key scope.
//
// GitHub API docs: https://developer.github.com/v3/users/gpg_keys/#get-a-single-gpg-key
-func (s *UsersService) GetGPGKey(id int) (*GPGKey, *Response, error) {
+func (s *UsersService) GetGPGKey(ctx context.Context, id int) (*GPGKey, *Response, error) {
u := fmt.Sprintf("user/gpg_keys/%v", id)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
@@ -76,7 +77,7 @@ func (s *UsersService) GetGPGKey(id int) (*GPGKey, *Response, error) {
req.Header.Set("Accept", mediaTypeGitSigningPreview)
key := &GPGKey{}
- resp, err := s.client.Do(req, key)
+ resp, err := s.client.Do(ctx, req, key)
if err != nil {
return nil, resp, err
}
@@ -88,7 +89,7 @@ func (s *UsersService) GetGPGKey(id int) (*GPGKey, *Response, error) {
// or OAuth with at least write:gpg_key scope.
//
// GitHub API docs: https://developer.github.com/v3/users/gpg_keys/#create-a-gpg-key
-func (s *UsersService) CreateGPGKey(armoredPublicKey string) (*GPGKey, *Response, error) {
+func (s *UsersService) CreateGPGKey(ctx context.Context, armoredPublicKey string) (*GPGKey, *Response, error) {
gpgKey := &struct {
ArmoredPublicKey string `json:"armored_public_key"`
}{ArmoredPublicKey: armoredPublicKey}
@@ -101,7 +102,7 @@ func (s *UsersService) CreateGPGKey(armoredPublicKey string) (*GPGKey, *Response
req.Header.Set("Accept", mediaTypeGitSigningPreview)
key := &GPGKey{}
- resp, err := s.client.Do(req, key)
+ resp, err := s.client.Do(ctx, req, key)
if err != nil {
return nil, resp, err
}
@@ -113,7 +114,7 @@ func (s *UsersService) CreateGPGKey(armoredPublicKey string) (*GPGKey, *Response
// via OAuth with at least admin:gpg_key scope.
//
// GitHub API docs: https://developer.github.com/v3/users/gpg_keys/#delete-a-gpg-key
-func (s *UsersService) DeleteGPGKey(id int) (*Response, error) {
+func (s *UsersService) DeleteGPGKey(ctx context.Context, id int) (*Response, error) {
u := fmt.Sprintf("user/gpg_keys/%v", id)
req, err := s.client.NewRequest("DELETE", u, nil)
if err != nil {
@@ -123,5 +124,5 @@ func (s *UsersService) DeleteGPGKey(id int) (*Response, error) {
// TODO: remove custom Accept header when this API fully launches.
req.Header.Set("Accept", mediaTypeGitSigningPreview)
- return s.client.Do(req, nil)
+ return s.client.Do(ctx, req, nil)
}
diff --git a/github/users_gpg_keys_test.go b/github/users_gpg_keys_test.go
index 05ef23f1358..12bd7ef7af5 100644
--- a/github/users_gpg_keys_test.go
+++ b/github/users_gpg_keys_test.go
@@ -6,6 +6,7 @@
package github
import (
+ "context"
"encoding/json"
"fmt"
"net/http"
@@ -23,7 +24,7 @@ func TestUsersService_ListGPGKeys(t *testing.T) {
fmt.Fprint(w, `[{"id":1,"primary_key_id":2}]`)
})
- keys, _, err := client.Users.ListGPGKeys()
+ keys, _, err := client.Users.ListGPGKeys(context.Background())
if err != nil {
t.Errorf("Users.ListGPGKeys returned error: %v", err)
}
@@ -44,7 +45,7 @@ func TestUsersService_GetGPGKey(t *testing.T) {
fmt.Fprint(w, `{"id":1}`)
})
- key, _, err := client.Users.GetGPGKey(1)
+ key, _, err := client.Users.GetGPGKey(context.Background(), 1)
if err != nil {
t.Errorf("Users.GetGPGKey returned error: %v", err)
}
@@ -83,7 +84,7 @@ mQINBFcEd9kBEACo54TDbGhKlXKWMvJgecEUKPPcv7XdnpKdGb3LRw5MvFwT0V0f
fmt.Fprint(w, `{"id":1}`)
})
- gpgKey, _, err := client.Users.CreateGPGKey(input)
+ gpgKey, _, err := client.Users.CreateGPGKey(context.Background(), input)
if err != nil {
t.Errorf("Users.GetGPGKey returned error: %v", err)
}
@@ -103,7 +104,7 @@ func TestUsersService_DeleteGPGKey(t *testing.T) {
testHeader(t, r, "Accept", mediaTypeGitSigningPreview)
})
- _, err := client.Users.DeleteGPGKey(1)
+ _, err := client.Users.DeleteGPGKey(context.Background(), 1)
if err != nil {
t.Errorf("Users.DeleteGPGKey returned error: %v", err)
}
diff --git a/github/users_keys.go b/github/users_keys.go
index ebc333fbd7a..97ed4b86112 100644
--- a/github/users_keys.go
+++ b/github/users_keys.go
@@ -5,7 +5,10 @@
package github
-import "fmt"
+import (
+ "context"
+ "fmt"
+)
// Key represents a public SSH key used to authenticate a user or deploy script.
type Key struct {
@@ -24,7 +27,7 @@ func (k Key) String() string {
// string will fetch keys for the authenticated user.
//
// GitHub API docs: https://developer.github.com/v3/users/keys/#list-public-keys-for-a-user
-func (s *UsersService) ListKeys(user string, opt *ListOptions) ([]*Key, *Response, error) {
+func (s *UsersService) ListKeys(ctx context.Context, user string, opt *ListOptions) ([]*Key, *Response, error) {
var u string
if user != "" {
u = fmt.Sprintf("users/%v/keys", user)
@@ -42,7 +45,7 @@ func (s *UsersService) ListKeys(user string, opt *ListOptions) ([]*Key, *Respons
}
var keys []*Key
- resp, err := s.client.Do(req, &keys)
+ resp, err := s.client.Do(ctx, req, &keys)
if err != nil {
return nil, resp, err
}
@@ -53,7 +56,7 @@ func (s *UsersService) ListKeys(user string, opt *ListOptions) ([]*Key, *Respons
// GetKey fetches a single public key.
//
// GitHub API docs: https://developer.github.com/v3/users/keys/#get-a-single-public-key
-func (s *UsersService) GetKey(id int) (*Key, *Response, error) {
+func (s *UsersService) GetKey(ctx context.Context, id int) (*Key, *Response, error) {
u := fmt.Sprintf("user/keys/%v", id)
req, err := s.client.NewRequest("GET", u, nil)
@@ -62,7 +65,7 @@ func (s *UsersService) GetKey(id int) (*Key, *Response, error) {
}
key := new(Key)
- resp, err := s.client.Do(req, key)
+ resp, err := s.client.Do(ctx, req, key)
if err != nil {
return nil, resp, err
}
@@ -73,7 +76,7 @@ func (s *UsersService) GetKey(id int) (*Key, *Response, error) {
// CreateKey adds a public key for the authenticated user.
//
// GitHub API docs: https://developer.github.com/v3/users/keys/#create-a-public-key
-func (s *UsersService) CreateKey(key *Key) (*Key, *Response, error) {
+func (s *UsersService) CreateKey(ctx context.Context, key *Key) (*Key, *Response, error) {
u := "user/keys"
req, err := s.client.NewRequest("POST", u, key)
@@ -82,7 +85,7 @@ func (s *UsersService) CreateKey(key *Key) (*Key, *Response, error) {
}
k := new(Key)
- resp, err := s.client.Do(req, k)
+ resp, err := s.client.Do(ctx, req, k)
if err != nil {
return nil, resp, err
}
@@ -93,7 +96,7 @@ func (s *UsersService) CreateKey(key *Key) (*Key, *Response, error) {
// DeleteKey deletes a public key.
//
// GitHub API docs: https://developer.github.com/v3/users/keys/#delete-a-public-key
-func (s *UsersService) DeleteKey(id int) (*Response, error) {
+func (s *UsersService) DeleteKey(ctx context.Context, id int) (*Response, error) {
u := fmt.Sprintf("user/keys/%v", id)
req, err := s.client.NewRequest("DELETE", u, nil)
@@ -101,5 +104,5 @@ func (s *UsersService) DeleteKey(id int) (*Response, error) {
return nil, err
}
- return s.client.Do(req, nil)
+ return s.client.Do(ctx, req, nil)
}
diff --git a/github/users_keys_test.go b/github/users_keys_test.go
index 25d4f0ca4c7..8554c50cd92 100644
--- a/github/users_keys_test.go
+++ b/github/users_keys_test.go
@@ -6,6 +6,7 @@
package github
import (
+ "context"
"encoding/json"
"fmt"
"net/http"
@@ -24,7 +25,7 @@ func TestUsersService_ListKeys_authenticatedUser(t *testing.T) {
})
opt := &ListOptions{Page: 2}
- keys, _, err := client.Users.ListKeys("", opt)
+ keys, _, err := client.Users.ListKeys(context.Background(), "", opt)
if err != nil {
t.Errorf("Users.ListKeys returned error: %v", err)
}
@@ -44,7 +45,7 @@ func TestUsersService_ListKeys_specifiedUser(t *testing.T) {
fmt.Fprint(w, `[{"id":1}]`)
})
- keys, _, err := client.Users.ListKeys("u", nil)
+ keys, _, err := client.Users.ListKeys(context.Background(), "u", nil)
if err != nil {
t.Errorf("Users.ListKeys returned error: %v", err)
}
@@ -56,7 +57,7 @@ func TestUsersService_ListKeys_specifiedUser(t *testing.T) {
}
func TestUsersService_ListKeys_invalidUser(t *testing.T) {
- _, _, err := client.Users.ListKeys("%", nil)
+ _, _, err := client.Users.ListKeys(context.Background(), "%", nil)
testURLParseError(t, err)
}
@@ -69,7 +70,7 @@ func TestUsersService_GetKey(t *testing.T) {
fmt.Fprint(w, `{"id":1}`)
})
- key, _, err := client.Users.GetKey(1)
+ key, _, err := client.Users.GetKey(context.Background(), 1)
if err != nil {
t.Errorf("Users.GetKey returned error: %v", err)
}
@@ -98,7 +99,7 @@ func TestUsersService_CreateKey(t *testing.T) {
fmt.Fprint(w, `{"id":1}`)
})
- key, _, err := client.Users.CreateKey(input)
+ key, _, err := client.Users.CreateKey(context.Background(), input)
if err != nil {
t.Errorf("Users.GetKey returned error: %v", err)
}
@@ -117,7 +118,7 @@ func TestUsersService_DeleteKey(t *testing.T) {
testMethod(t, r, "DELETE")
})
- _, err := client.Users.DeleteKey(1)
+ _, err := client.Users.DeleteKey(context.Background(), 1)
if err != nil {
t.Errorf("Users.DeleteKey returned error: %v", err)
}
diff --git a/github/users_test.go b/github/users_test.go
index db72afa8a9b..dfa39af66fb 100644
--- a/github/users_test.go
+++ b/github/users_test.go
@@ -6,6 +6,7 @@
package github
import (
+ "context"
"encoding/json"
"fmt"
"net/http"
@@ -64,7 +65,7 @@ func TestUsersService_Get_authenticatedUser(t *testing.T) {
fmt.Fprint(w, `{"id":1}`)
})
- user, _, err := client.Users.Get("")
+ user, _, err := client.Users.Get(context.Background(), "")
if err != nil {
t.Errorf("Users.Get returned error: %v", err)
}
@@ -84,7 +85,7 @@ func TestUsersService_Get_specifiedUser(t *testing.T) {
fmt.Fprint(w, `{"id":1}`)
})
- user, _, err := client.Users.Get("u")
+ user, _, err := client.Users.Get(context.Background(), "u")
if err != nil {
t.Errorf("Users.Get returned error: %v", err)
}
@@ -96,7 +97,7 @@ func TestUsersService_Get_specifiedUser(t *testing.T) {
}
func TestUsersService_Get_invalidUser(t *testing.T) {
- _, _, err := client.Users.Get("%")
+ _, _, err := client.Users.Get(context.Background(), "%")
testURLParseError(t, err)
}
@@ -109,7 +110,7 @@ func TestUsersService_GetByID(t *testing.T) {
fmt.Fprint(w, `{"id":1}`)
})
- user, _, err := client.Users.GetByID(1)
+ user, _, err := client.Users.GetByID(context.Background(), 1)
if err != nil {
t.Errorf("Users.GetByID returned error: %v", err)
}
@@ -138,7 +139,7 @@ func TestUsersService_Edit(t *testing.T) {
fmt.Fprint(w, `{"id":1}`)
})
- user, _, err := client.Users.Edit(input)
+ user, _, err := client.Users.Edit(context.Background(), input)
if err != nil {
t.Errorf("Users.Edit returned error: %v", err)
}
@@ -160,7 +161,7 @@ func TestUsersService_ListAll(t *testing.T) {
})
opt := &UserListOptions{1, ListOptions{Page: 2}}
- users, _, err := client.Users.ListAll(opt)
+ users, _, err := client.Users.ListAll(context.Background(), opt)
if err != nil {
t.Errorf("Users.Get returned error: %v", err)
}
@@ -181,7 +182,7 @@ func TestUsersService_ListInvitations(t *testing.T) {
fmt.Fprintf(w, `[{"id":1}, {"id":2}]`)
})
- got, _, err := client.Users.ListInvitations()
+ got, _, err := client.Users.ListInvitations(context.Background())
if err != nil {
t.Errorf("Users.ListInvitations returned error: %v", err)
}
@@ -202,7 +203,7 @@ func TestUsersService_AcceptInvitation(t *testing.T) {
w.WriteHeader(http.StatusNoContent)
})
- if _, err := client.Users.AcceptInvitation(1); err != nil {
+ if _, err := client.Users.AcceptInvitation(context.Background(), 1); err != nil {
t.Errorf("Users.AcceptInvitation returned error: %v", err)
}
}
@@ -217,7 +218,7 @@ func TestUsersService_DeclineInvitation(t *testing.T) {
w.WriteHeader(http.StatusNoContent)
})
- if _, err := client.Users.DeclineInvitation(1); err != nil {
+ if _, err := client.Users.DeclineInvitation(context.Background(), 1); err != nil {
t.Errorf("Users.DeclineInvitation returned error: %v", err)
}
}
diff --git a/tests/fields/fields.go b/tests/fields/fields.go
index 9f13691306b..bd1463eb253 100644
--- a/tests/fields/fields.go
+++ b/tests/fields/fields.go
@@ -17,6 +17,7 @@
package main
import (
+ "context"
"encoding/json"
"flag"
"fmt"
@@ -46,7 +47,7 @@ func main() {
print("!!! No OAuth token. Some tests won't run. !!!\n\n")
client = github.NewClient(nil)
} else {
- tc := oauth2.NewClient(oauth2.NoContext, oauth2.StaticTokenSource(
+ tc := oauth2.NewClient(context.Background(), oauth2.StaticTokenSource(
&oauth2.Token{AccessToken: token},
))
client = github.NewClient(tc)
@@ -84,7 +85,7 @@ func testType(urlStr string, typ interface{}) error {
// start with a json.RawMessage so we can decode multiple ways below
raw := new(json.RawMessage)
- _, err = client.Do(req, raw)
+ _, err = client.Do(context.Background(), req, raw)
if err != nil {
return err
}