Repository: google/go-github (go)

Issue:
Add NewTokenClient constructor
I often write one-off tools using this module and I keep needing to come back to the docs to copy/paste this snippet.

``` go
return github.NewClient(
	oauth2.NewClient(
		ctx, oauth2.StaticTokenSource(
			&oauth2.Token{
				AccessToken: token,
			},
		),
	),
)
```

It would be nice if there was a helper to do this.

``` go
client := github.NewTokenClient(ctx, token)
```

Pull request:
Add NewTokenClient
Fixes #2636 

Patch:
diff --git a/github/billing.go b/github/billing.go
index 2f5861ce..2900a016 100644
--- a/github/billing.go
+++ b/github/billing.go
@@ -18,9 +18,9 @@ type BillingService service
 
 // ActionBilling represents a GitHub Action billing.
 type ActionBilling struct {
-	TotalMinutesUsed     int                  `json:"total_minutes_used"`
+	TotalMinutesUsed     float64              `json:"total_minutes_used"`
 	TotalPaidMinutesUsed float64              `json:"total_paid_minutes_used"`
-	IncludedMinutes      int                  `json:"included_minutes"`
+	IncludedMinutes      float64              `json:"included_minutes"`
 	MinutesUsedBreakdown MinutesUsedBreakdown `json:"minutes_used_breakdown"`
 }
 
@@ -29,16 +29,16 @@ type MinutesUsedBreakdown = map[string]int
 
 // PackageBilling represents a GitHub Package billing.
 type PackageBilling struct {
-	TotalGigabytesBandwidthUsed     int `json:"total_gigabytes_bandwidth_used"`
-	TotalPaidGigabytesBandwidthUsed int `json:"total_paid_gigabytes_bandwidth_used"`
-	IncludedGigabytesBandwidth      int `json:"included_gigabytes_bandwidth"`
+	TotalGigabytesBandwidthUsed     int     `json:"total_gigabytes_bandwidth_used"`
+	TotalPaidGigabytesBandwidthUsed int     `json:"total_paid_gigabytes_bandwidth_used"`
+	IncludedGigabytesBandwidth      float64 `json:"included_gigabytes_bandwidth"`
 }
 
 // StorageBilling represents a GitHub Storage billing.
 type StorageBilling struct {
 	DaysLeftInBillingCycle       int     `json:"days_left_in_billing_cycle"`
 	EstimatedPaidStorageForMonth float64 `json:"estimated_paid_storage_for_month"`
-	EstimatedStorageForMonth     int     `json:"estimated_storage_for_month"`
+	EstimatedStorageForMonth     float64 `json:"estimated_storage_for_month"`
 }
 
 // ActiveCommitters represents the total active committers across all repositories in an Organization.
diff --git a/github/github.go b/github/github.go
index e97e31f2..7d915dfa 100644
--- a/github/github.go
+++ b/github/github.go
@@ -24,6 +24,7 @@ import (
 	"time"
 
 	"github.com/google/go-querystring/query"
+	"golang.org/x/oauth2"
 )
 
 const (
@@ -346,6 +347,11 @@ func NewClient(httpClient *http.Client) *Client {
 	return c
 }
 
+// NewTokenClient returns a new GitHub API client authenticated with the provided token.
+func NewTokenClient(ctx context.Context, token string) *Client {
+	return NewClient(oauth2.NewClient(ctx, oauth2.StaticTokenSource(&oauth2.Token{AccessToken: token})))
+}
+
 // NewEnterpriseClient returns a new GitHub API client with provided
 // base URL and upload URL (often is your GitHub Enterprise hostname).
 // If the base URL does not have the suffix "/api/v3/", it will be added automatically.


Test patch:
diff --git a/github/billing_test.go b/github/billing_test.go
index 6a85cd22..52b338b8 100644
--- a/github/billing_test.go
+++ b/github/billing_test.go
@@ -21,9 +21,9 @@ func TestBillingService_GetActionsBillingOrg(t *testing.T) {
 	mux.HandleFunc("/orgs/o/settings/billing/actions", func(w http.ResponseWriter, r *http.Request) {
 		testMethod(t, r, "GET")
 		fmt.Fprint(w, `{
-				"total_minutes_used": 305,
+				"total_minutes_used": 305.0,
 				"total_paid_minutes_used": 0.0,
-				"included_minutes": 3000,
+				"included_minutes": 3000.0,
 				"minutes_used_breakdown": {
 					"UBUNTU": 205,
 					"MACOS": 10,
@@ -39,9 +39,9 @@ func TestBillingService_GetActionsBillingOrg(t *testing.T) {
 	}
 
 	want := &ActionBilling{
-		TotalMinutesUsed:     305,
-		TotalPaidMinutesUsed: 0,
-		IncludedMinutes:      3000,
+		TotalMinutesUsed:     305.0,
+		TotalPaidMinutesUsed: 0.0,
+		IncludedMinutes:      3000.0,
 		MinutesUsedBreakdown: MinutesUsedBreakdown{
 			"UBUNTU":  205,
 			"MACOS":   10,
diff --git a/github/github_test.go b/github/github_test.go
index 53809399..50ecd543 100644
--- a/github/github_test.go
+++ b/github/github_test.go
@@ -22,6 +22,7 @@ import (
 	"time"
 
 	"github.com/google/go-cmp/cmp"
+	"golang.org/x/oauth2"
 )
 
 const (
@@ -266,6 +267,19 @@ func TestClient(t *testing.T) {
 	}
 }
 
+func TestNewTokenClient(t *testing.T) {
+	token := "gh_test_token"
+	ctx := context.Background()
+	c := NewTokenClient(ctx, token)
+	tr, ok := c.Client().Transport.(*oauth2.Transport)
+	if !ok {
+		t.Error("Client transport is not oauth2.Transport")
+	}
+	if tok, err := tr.Source.Token(); err != nil || tok.AccessToken != token {
+		t.Errorf("Client not using correct token")
+	}
+}
+
 func TestNewEnterpriseClient(t *testing.T) {
 	baseURL := "https://custom-url/api/v3/"
 	uploadURL := "https://custom-upload-url/api/uploads/"