Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change actions billing structs to maps #2597

Merged
merged 2 commits into from Dec 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 5 additions & 8 deletions github/actions_workflow_runs.go
Expand Up @@ -65,16 +65,13 @@ type ListWorkflowRunsOptions struct {

// WorkflowRunUsage represents a usage of a specific workflow run.
type WorkflowRunUsage struct {
Billable *WorkflowRunEnvironment `json:"billable,omitempty"`
RunDurationMS *int64 `json:"run_duration_ms,omitempty"`
Billable *WorkflowRunBillMap `json:"billable,omitempty"`
RunDurationMS *int64 `json:"run_duration_ms,omitempty"`
}

// WorkflowRunEnvironment represents different runner environments available for a workflow run.
type WorkflowRunEnvironment struct {
Ubuntu *WorkflowRunBill `json:"UBUNTU,omitempty"`
MacOS *WorkflowRunBill `json:"MACOS,omitempty"`
Windows *WorkflowRunBill `json:"WINDOWS,omitempty"`
}
// WorkflowRunBillMap represents different runner environments available for a workflow run.
// Its key is the name of its environment, e.g. "UBUNTU", "MACOS", "WINDOWS", etc.
type WorkflowRunBillMap map[string]*WorkflowRunBill
gmlewis marked this conversation as resolved.
Show resolved Hide resolved

// WorkflowRunBill specifies billable time for a specific environment in a workflow run.
type WorkflowRunBill struct {
Expand Down
31 changes: 15 additions & 16 deletions github/actions_workflow_runs_test.go
Expand Up @@ -403,7 +403,6 @@ func TestActionService_ListRepositoryWorkflowRuns(t *testing.T) {
opts := &ListWorkflowRunsOptions{ListOptions: ListOptions{Page: 2, PerPage: 2}}
ctx := context.Background()
runs, _, err := client.Actions.ListRepositoryWorkflowRuns(ctx, "o", "r", opts)

if err != nil {
t.Errorf("Actions.ListRepositoryWorkflowRuns returned error: %v", err)
}
Expand Down Expand Up @@ -505,8 +504,8 @@ func TestActionsService_GetWorkflowRunUsageByID(t *testing.T) {
}

want := &WorkflowRunUsage{
Billable: &WorkflowRunEnvironment{
Ubuntu: &WorkflowRunBill{
Billable: &WorkflowRunBillMap{
"UBUNTU": &WorkflowRunBill{
TotalMS: Int64(180000),
Jobs: Int(1),
JobRuns: []*WorkflowRunJobRun{
Expand All @@ -516,7 +515,7 @@ func TestActionsService_GetWorkflowRunUsageByID(t *testing.T) {
},
},
},
MacOS: &WorkflowRunBill{
"MACOS": &WorkflowRunBill{
TotalMS: Int64(240000),
Jobs: Int(2),
JobRuns: []*WorkflowRunJobRun{
Expand All @@ -530,7 +529,7 @@ func TestActionsService_GetWorkflowRunUsageByID(t *testing.T) {
},
},
},
Windows: &WorkflowRunBill{
"WINDOWS": &WorkflowRunBill{
TotalMS: Int64(300000),
Jobs: Int(2),
},
Expand Down Expand Up @@ -975,7 +974,7 @@ func TestWorkflowRuns_Marshal(t *testing.T) {
"created_at": ` + referenceTimeStr + `,
"suspended_at": ` + referenceTimeStr + `,
"url": "u"
}
}
}
]
}`
Expand All @@ -999,19 +998,19 @@ func TestWorkflowRunBill_Marshal(t *testing.T) {
testJSONMarshal(t, u, want)
}

func TestWorkflowRunEnvironment_Marshal(t *testing.T) {
testJSONMarshal(t, &WorkflowRunEnvironment{}, "{}")
func TestWorkflowRunBillMap_Marshal(t *testing.T) {
testJSONMarshal(t, &WorkflowRunBillMap{}, "{}")

u := &WorkflowRunEnvironment{
Ubuntu: &WorkflowRunBill{
u := &WorkflowRunBillMap{
"UBUNTU": &WorkflowRunBill{
TotalMS: Int64(1),
Jobs: Int(1),
},
MacOS: &WorkflowRunBill{
"MACOS": &WorkflowRunBill{
TotalMS: Int64(1),
Jobs: Int(1),
},
Windows: &WorkflowRunBill{
"WINDOWS": &WorkflowRunBill{
TotalMS: Int64(1),
Jobs: Int(1),
},
Expand Down Expand Up @@ -1039,16 +1038,16 @@ func TestWorkflowRunUsage_Marshal(t *testing.T) {
testJSONMarshal(t, &WorkflowRunUsage{}, "{}")

u := &WorkflowRunUsage{
Billable: &WorkflowRunEnvironment{
Ubuntu: &WorkflowRunBill{
Billable: &WorkflowRunBillMap{
"UBUNTU": &WorkflowRunBill{
TotalMS: Int64(1),
Jobs: Int(1),
},
MacOS: &WorkflowRunBill{
"MACOS": &WorkflowRunBill{
TotalMS: Int64(1),
Jobs: Int(1),
},
Windows: &WorkflowRunBill{
"WINDOWS": &WorkflowRunBill{
TotalMS: Int64(1),
Jobs: Int(1),
},
Expand Down
11 changes: 4 additions & 7 deletions github/actions_workflows.go
Expand Up @@ -32,15 +32,12 @@ type Workflows struct {

// WorkflowUsage represents a usage of a specific workflow.
type WorkflowUsage struct {
Billable *WorkflowEnvironment `json:"billable,omitempty"`
Billable *WorkflowBillMap `json:"billable,omitempty"`
}

// WorkflowEnvironment represents different runner environments available for a workflow.
type WorkflowEnvironment struct {
Ubuntu *WorkflowBill `json:"UBUNTU,omitempty"`
MacOS *WorkflowBill `json:"MACOS,omitempty"`
Windows *WorkflowBill `json:"WINDOWS,omitempty"`
}
// WorkflowBillMap represents different runner environments available for a workflow.
// Its key is the name of its environment, e.g. "UBUNTU", "MACOS", "WINDOWS", etc.
type WorkflowBillMap map[string]*WorkflowBill

// WorkflowBill specifies billable time for a specific environment in a workflow.
type WorkflowBill struct {
Expand Down
36 changes: 18 additions & 18 deletions github/actions_workflows_test.go
Expand Up @@ -153,14 +153,14 @@ func TestActionsService_GetWorkflowUsageByID(t *testing.T) {
}

want := &WorkflowUsage{
Billable: &WorkflowEnvironment{
Ubuntu: &WorkflowBill{
Billable: &WorkflowBillMap{
"UBUNTU": &WorkflowBill{
TotalMS: Int64(180000),
},
MacOS: &WorkflowBill{
"MACOS": &WorkflowBill{
TotalMS: Int64(240000),
},
Windows: &WorkflowBill{
"WINDOWS": &WorkflowBill{
TotalMS: Int64(300000),
},
},
Expand Down Expand Up @@ -200,14 +200,14 @@ func TestActionsService_GetWorkflowUsageByFileName(t *testing.T) {
}

want := &WorkflowUsage{
Billable: &WorkflowEnvironment{
Ubuntu: &WorkflowBill{
Billable: &WorkflowBillMap{
"UBUNTU": &WorkflowBill{
TotalMS: Int64(180000),
},
MacOS: &WorkflowBill{
"MACOS": &WorkflowBill{
TotalMS: Int64(240000),
},
Windows: &WorkflowBill{
"WINDOWS": &WorkflowBill{
TotalMS: Int64(300000),
},
},
Expand Down Expand Up @@ -545,17 +545,17 @@ func TestWorkflowBill_Marshal(t *testing.T) {
testJSONMarshal(t, u, want)
}

func TestWorkflowEnvironment_Marshal(t *testing.T) {
testJSONMarshal(t, &WorkflowEnvironment{}, "{}")
func TestWorkflowBillMap_Marshal(t *testing.T) {
testJSONMarshal(t, &WorkflowBillMap{}, "{}")

u := &WorkflowEnvironment{
Ubuntu: &WorkflowBill{
u := &WorkflowBillMap{
"UBUNTU": &WorkflowBill{
TotalMS: Int64(1),
},
MacOS: &WorkflowBill{
"MACOS": &WorkflowBill{
TotalMS: Int64(1),
},
Windows: &WorkflowBill{
"WINDOWS": &WorkflowBill{
TotalMS: Int64(1),
},
}
Expand All @@ -579,14 +579,14 @@ func TestWorkflowUsage_Marshal(t *testing.T) {
testJSONMarshal(t, &WorkflowUsage{}, "{}")

u := &WorkflowUsage{
Billable: &WorkflowEnvironment{
Ubuntu: &WorkflowBill{
Billable: &WorkflowBillMap{
"UBUNTU": &WorkflowBill{
TotalMS: Int64(1),
},
MacOS: &WorkflowBill{
"MACOS": &WorkflowBill{
TotalMS: Int64(1),
},
Windows: &WorkflowBill{
"WINDOWS": &WorkflowBill{
TotalMS: Int64(1),
},
},
Expand Down
7 changes: 2 additions & 5 deletions github/billing.go
Expand Up @@ -24,11 +24,8 @@ type ActionBilling struct {
MinutesUsedBreakdown MinutesUsedBreakdown `json:"minutes_used_breakdown"`
}

type MinutesUsedBreakdown struct {
Ubuntu int `json:"UBUNTU"`
MacOS int `json:"MACOS"`
Windows int `json:"WINDOWS"`
}
// MinutesUsedBreakdown counts the actions minutes used by machine type (e.g. UBUNTU, WINDOWS, MACOS).
type MinutesUsedBreakdown = map[string]int

// PackageBilling represents a GitHub Package billing.
type PackageBilling struct {
Expand Down
24 changes: 12 additions & 12 deletions github/billing_test.go
Expand Up @@ -43,9 +43,9 @@ func TestBillingService_GetActionsBillingOrg(t *testing.T) {
TotalPaidMinutesUsed: 0,
IncludedMinutes: 3000,
MinutesUsedBreakdown: MinutesUsedBreakdown{
Ubuntu: 205,
MacOS: 10,
Windows: 90,
"UBUNTU": 205,
"MACOS": 10,
"WINDOWS": 90,
},
}
if !cmp.Equal(hook, want) {
Expand Down Expand Up @@ -209,9 +209,9 @@ func TestBillingService_GetActionsBillingUser(t *testing.T) {
TotalPaidMinutesUsed: 0,
IncludedMinutes: 3000,
MinutesUsedBreakdown: MinutesUsedBreakdown{
Ubuntu: 205,
MacOS: 10,
Windows: 90,
"UBUNTU": 205,
"MACOS": 10,
"WINDOWS": 90,
},
}
if !cmp.Equal(hook, want) {
Expand Down Expand Up @@ -350,9 +350,9 @@ func TestMinutesUsedBreakdown_Marshal(t *testing.T) {
testJSONMarshal(t, &MinutesUsedBreakdown{}, "{}")

u := &MinutesUsedBreakdown{
Ubuntu: 1,
MacOS: 1,
Windows: 1,
"UBUNTU": 1,
"MACOS": 1,
"WINDOWS": 1,
}

want := `{
Expand All @@ -372,9 +372,9 @@ func TestActionBilling_Marshal(t *testing.T) {
TotalPaidMinutesUsed: 1,
IncludedMinutes: 1,
MinutesUsedBreakdown: MinutesUsedBreakdown{
Ubuntu: 1,
MacOS: 1,
Windows: 1,
"UBUNTU": 1,
"MACOS": 1,
"WINDOWS": 1,
},
}

Expand Down
52 changes: 2 additions & 50 deletions github/github-accessors.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.