Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 0 additions & 50 deletions github/billing.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,6 @@ import (
// GitHub API docs: https://docs.github.com/rest/billing
type BillingService service

// ActionBilling represents a GitHub Action billing.
type ActionBilling struct {
TotalMinutesUsed float64 `json:"total_minutes_used"`
TotalPaidMinutesUsed float64 `json:"total_paid_minutes_used"`
IncludedMinutes float64 `json:"included_minutes"`
MinutesUsedBreakdown MinutesUsedBreakdown `json:"minutes_used_breakdown"`
}

// MinutesUsedBreakdown counts the actions minutes used by machine type (e.g. UBUNTU, WINDOWS, MACOS).
type MinutesUsedBreakdown = map[string]int

Expand Down Expand Up @@ -103,27 +95,6 @@ type UsageReport struct {
UsageItems []*UsageItem `json:"usageItems,omitempty"`
}

// GetActionsBillingOrg returns the summary of the free and paid GitHub Actions minutes used for an Org.
//
// GitHub API docs: https://docs.github.com/rest/billing/billing#get-github-actions-billing-for-an-organization
//
//meta:operation GET /orgs/{org}/settings/billing/actions
func (s *BillingService) GetActionsBillingOrg(ctx context.Context, org string) (*ActionBilling, *Response, error) {
u := fmt.Sprintf("orgs/%v/settings/billing/actions", org)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}

actionsOrgBilling := new(ActionBilling)
resp, err := s.client.Do(ctx, req, actionsOrgBilling)
if err != nil {
return nil, resp, err
}

return actionsOrgBilling, resp, nil
}

// GetPackagesBillingOrg returns the free and paid storage used for GitHub Packages in gigabytes for an Org.
//
// GitHub API docs: https://docs.github.com/rest/billing/billing#get-github-packages-billing-for-an-organization
Expand Down Expand Up @@ -193,27 +164,6 @@ func (s *BillingService) GetAdvancedSecurityActiveCommittersOrg(ctx context.Cont
return activeOrgCommitters, resp, nil
}

// GetActionsBillingUser returns the summary of the free and paid GitHub Actions minutes used for a user.
//
// GitHub API docs: https://docs.github.com/rest/billing/billing#get-github-actions-billing-for-a-user
//
//meta:operation GET /users/{username}/settings/billing/actions
func (s *BillingService) GetActionsBillingUser(ctx context.Context, user string) (*ActionBilling, *Response, error) {
u := fmt.Sprintf("users/%v/settings/billing/actions", user)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}

actionsUserBilling := new(ActionBilling)
resp, err := s.client.Do(ctx, req, actionsUserBilling)
if err != nil {
return nil, resp, err
}

return actionsUserBilling, resp, nil
}

// GetPackagesBillingUser returns the free and paid storage used for GitHub Packages in gigabytes for a user.
//
// GitHub API docs: https://docs.github.com/rest/billing/billing#get-github-packages-billing-for-a-user
Expand Down
153 changes: 0 additions & 153 deletions github/billing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,68 +14,6 @@ import (
"github.com/google/go-cmp/cmp"
)

func TestBillingService_GetActionsBillingOrg(t *testing.T) {
t.Parallel()
client, mux, _ := setup(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.0,
"total_paid_minutes_used": 0.0,
"included_minutes": 3000.0,
"minutes_used_breakdown": {
"UBUNTU": 205,
"MACOS": 10,
"WINDOWS": 90
}
}`)
})

ctx := context.Background()
hook, _, err := client.Billing.GetActionsBillingOrg(ctx, "o")
if err != nil {
t.Errorf("Billing.GetActionsBillingOrg returned error: %v", err)
}

want := &ActionBilling{
TotalMinutesUsed: 305.0,
TotalPaidMinutesUsed: 0.0,
IncludedMinutes: 3000.0,
MinutesUsedBreakdown: MinutesUsedBreakdown{
"UBUNTU": 205,
"MACOS": 10,
"WINDOWS": 90,
},
}
if !cmp.Equal(hook, want) {
t.Errorf("Billing.GetActionsBillingOrg returned %+v, want %+v", hook, want)
}

const methodName = "GetActionsBillingOrg"
testBadOptions(t, methodName, func() (err error) {
_, _, err = client.Billing.GetActionsBillingOrg(ctx, "\n")
return err
})

testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
got, resp, err := client.Billing.GetActionsBillingOrg(ctx, "o")
if got != nil {
t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
}
return resp, err
})
}

func TestBillingService_GetActionsBillingOrg_invalidOrg(t *testing.T) {
t.Parallel()
client, _, _ := setup(t)

ctx := context.Background()
_, _, err := client.Billing.GetActionsBillingOrg(ctx, "%")
testURLParseError(t, err)
}

func TestBillingService_GetPackagesBillingOrg(t *testing.T) {
t.Parallel()
client, mux, _ := setup(t)
Expand Down Expand Up @@ -180,68 +118,6 @@ func TestBillingService_GetStorageBillingOrg_invalidOrg(t *testing.T) {
testURLParseError(t, err)
}

func TestBillingService_GetActionsBillingUser(t *testing.T) {
t.Parallel()
client, mux, _ := setup(t)

mux.HandleFunc("/users/u/settings/billing/actions", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
fmt.Fprint(w, `{
"total_minutes_used": 10,
"total_paid_minutes_used": 0,
"included_minutes": 3000,
"minutes_used_breakdown": {
"UBUNTU": 205,
"MACOS": 10,
"WINDOWS": 90
}
}`)
})

ctx := context.Background()
hook, _, err := client.Billing.GetActionsBillingUser(ctx, "u")
if err != nil {
t.Errorf("Billing.GetActionsBillingUser returned error: %v", err)
}

want := &ActionBilling{
TotalMinutesUsed: 10,
TotalPaidMinutesUsed: 0,
IncludedMinutes: 3000,
MinutesUsedBreakdown: MinutesUsedBreakdown{
"UBUNTU": 205,
"MACOS": 10,
"WINDOWS": 90,
},
}
if !cmp.Equal(hook, want) {
t.Errorf("Billing.GetActionsBillingUser returned %+v, want %+v", hook, want)
}

const methodName = "GetActionsBillingUser"
testBadOptions(t, methodName, func() (err error) {
_, _, err = client.Billing.GetActionsBillingOrg(ctx, "\n")
return err
})

testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
got, resp, err := client.Billing.GetActionsBillingUser(ctx, "o")
if got != nil {
t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
}
return resp, err
})
}

func TestBillingService_GetActionsBillingUser_invalidUser(t *testing.T) {
t.Parallel()
client, _, _ := setup(t)

ctx := context.Background()
_, _, err := client.Billing.GetActionsBillingUser(ctx, "%")
testURLParseError(t, err)
}

func TestBillingService_GetPackagesBillingUser(t *testing.T) {
t.Parallel()
client, mux, _ := setup(t)
Expand Down Expand Up @@ -365,35 +241,6 @@ func TestMinutesUsedBreakdown_Marshal(t *testing.T) {
testJSONMarshal(t, u, want)
}

func TestActionBilling_Marshal(t *testing.T) {
t.Parallel()
testJSONMarshal(t, &MinutesUsedBreakdown{}, "{}")

u := &ActionBilling{
TotalMinutesUsed: 1,
TotalPaidMinutesUsed: 1,
IncludedMinutes: 1,
MinutesUsedBreakdown: MinutesUsedBreakdown{
"UBUNTU": 1,
"MACOS": 1,
"WINDOWS": 1,
},
}

want := `{
"total_minutes_used": 1,
"total_paid_minutes_used": 1,
"included_minutes": 1,
"minutes_used_breakdown": {
"UBUNTU": 1,
"MACOS": 1,
"WINDOWS": 1
}
}`

testJSONMarshal(t, u, want)
}

func TestPackageBilling_Marshal(t *testing.T) {
t.Parallel()
testJSONMarshal(t, &PackageBilling{}, "{}")
Expand Down