Skip to content

Commit 84cc7d5

Browse files
Change actions billing structs to maps (#2597)
Fixes: #2595.
1 parent c5d656a commit 84cc7d5

File tree

8 files changed

+58
-158
lines changed

8 files changed

+58
-158
lines changed

github/actions_workflow_runs.go

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,16 +65,13 @@ type ListWorkflowRunsOptions struct {
6565

6666
// WorkflowRunUsage represents a usage of a specific workflow run.
6767
type WorkflowRunUsage struct {
68-
Billable *WorkflowRunEnvironment `json:"billable,omitempty"`
69-
RunDurationMS *int64 `json:"run_duration_ms,omitempty"`
68+
Billable *WorkflowRunBillMap `json:"billable,omitempty"`
69+
RunDurationMS *int64 `json:"run_duration_ms,omitempty"`
7070
}
7171

72-
// WorkflowRunEnvironment represents different runner environments available for a workflow run.
73-
type WorkflowRunEnvironment struct {
74-
Ubuntu *WorkflowRunBill `json:"UBUNTU,omitempty"`
75-
MacOS *WorkflowRunBill `json:"MACOS,omitempty"`
76-
Windows *WorkflowRunBill `json:"WINDOWS,omitempty"`
77-
}
72+
// WorkflowRunBillMap represents different runner environments available for a workflow run.
73+
// Its key is the name of its environment, e.g. "UBUNTU", "MACOS", "WINDOWS", etc.
74+
type WorkflowRunBillMap map[string]*WorkflowRunBill
7875

7976
// WorkflowRunBill specifies billable time for a specific environment in a workflow run.
8077
type WorkflowRunBill struct {

github/actions_workflow_runs_test.go

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,6 @@ func TestActionService_ListRepositoryWorkflowRuns(t *testing.T) {
403403
opts := &ListWorkflowRunsOptions{ListOptions: ListOptions{Page: 2, PerPage: 2}}
404404
ctx := context.Background()
405405
runs, _, err := client.Actions.ListRepositoryWorkflowRuns(ctx, "o", "r", opts)
406-
407406
if err != nil {
408407
t.Errorf("Actions.ListRepositoryWorkflowRuns returned error: %v", err)
409408
}
@@ -505,8 +504,8 @@ func TestActionsService_GetWorkflowRunUsageByID(t *testing.T) {
505504
}
506505

507506
want := &WorkflowRunUsage{
508-
Billable: &WorkflowRunEnvironment{
509-
Ubuntu: &WorkflowRunBill{
507+
Billable: &WorkflowRunBillMap{
508+
"UBUNTU": &WorkflowRunBill{
510509
TotalMS: Int64(180000),
511510
Jobs: Int(1),
512511
JobRuns: []*WorkflowRunJobRun{
@@ -516,7 +515,7 @@ func TestActionsService_GetWorkflowRunUsageByID(t *testing.T) {
516515
},
517516
},
518517
},
519-
MacOS: &WorkflowRunBill{
518+
"MACOS": &WorkflowRunBill{
520519
TotalMS: Int64(240000),
521520
Jobs: Int(2),
522521
JobRuns: []*WorkflowRunJobRun{
@@ -530,7 +529,7 @@ func TestActionsService_GetWorkflowRunUsageByID(t *testing.T) {
530529
},
531530
},
532531
},
533-
Windows: &WorkflowRunBill{
532+
"WINDOWS": &WorkflowRunBill{
534533
TotalMS: Int64(300000),
535534
Jobs: Int(2),
536535
},
@@ -975,7 +974,7 @@ func TestWorkflowRuns_Marshal(t *testing.T) {
975974
"created_at": ` + referenceTimeStr + `,
976975
"suspended_at": ` + referenceTimeStr + `,
977976
"url": "u"
978-
}
977+
}
979978
}
980979
]
981980
}`
@@ -999,19 +998,19 @@ func TestWorkflowRunBill_Marshal(t *testing.T) {
999998
testJSONMarshal(t, u, want)
1000999
}
10011000

1002-
func TestWorkflowRunEnvironment_Marshal(t *testing.T) {
1003-
testJSONMarshal(t, &WorkflowRunEnvironment{}, "{}")
1001+
func TestWorkflowRunBillMap_Marshal(t *testing.T) {
1002+
testJSONMarshal(t, &WorkflowRunBillMap{}, "{}")
10041003

1005-
u := &WorkflowRunEnvironment{
1006-
Ubuntu: &WorkflowRunBill{
1004+
u := &WorkflowRunBillMap{
1005+
"UBUNTU": &WorkflowRunBill{
10071006
TotalMS: Int64(1),
10081007
Jobs: Int(1),
10091008
},
1010-
MacOS: &WorkflowRunBill{
1009+
"MACOS": &WorkflowRunBill{
10111010
TotalMS: Int64(1),
10121011
Jobs: Int(1),
10131012
},
1014-
Windows: &WorkflowRunBill{
1013+
"WINDOWS": &WorkflowRunBill{
10151014
TotalMS: Int64(1),
10161015
Jobs: Int(1),
10171016
},
@@ -1039,16 +1038,16 @@ func TestWorkflowRunUsage_Marshal(t *testing.T) {
10391038
testJSONMarshal(t, &WorkflowRunUsage{}, "{}")
10401039

10411040
u := &WorkflowRunUsage{
1042-
Billable: &WorkflowRunEnvironment{
1043-
Ubuntu: &WorkflowRunBill{
1041+
Billable: &WorkflowRunBillMap{
1042+
"UBUNTU": &WorkflowRunBill{
10441043
TotalMS: Int64(1),
10451044
Jobs: Int(1),
10461045
},
1047-
MacOS: &WorkflowRunBill{
1046+
"MACOS": &WorkflowRunBill{
10481047
TotalMS: Int64(1),
10491048
Jobs: Int(1),
10501049
},
1051-
Windows: &WorkflowRunBill{
1050+
"WINDOWS": &WorkflowRunBill{
10521051
TotalMS: Int64(1),
10531052
Jobs: Int(1),
10541053
},

github/actions_workflows.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,12 @@ type Workflows struct {
3232

3333
// WorkflowUsage represents a usage of a specific workflow.
3434
type WorkflowUsage struct {
35-
Billable *WorkflowEnvironment `json:"billable,omitempty"`
35+
Billable *WorkflowBillMap `json:"billable,omitempty"`
3636
}
3737

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

4542
// WorkflowBill specifies billable time for a specific environment in a workflow.
4643
type WorkflowBill struct {

github/actions_workflows_test.go

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -153,14 +153,14 @@ func TestActionsService_GetWorkflowUsageByID(t *testing.T) {
153153
}
154154

155155
want := &WorkflowUsage{
156-
Billable: &WorkflowEnvironment{
157-
Ubuntu: &WorkflowBill{
156+
Billable: &WorkflowBillMap{
157+
"UBUNTU": &WorkflowBill{
158158
TotalMS: Int64(180000),
159159
},
160-
MacOS: &WorkflowBill{
160+
"MACOS": &WorkflowBill{
161161
TotalMS: Int64(240000),
162162
},
163-
Windows: &WorkflowBill{
163+
"WINDOWS": &WorkflowBill{
164164
TotalMS: Int64(300000),
165165
},
166166
},
@@ -200,14 +200,14 @@ func TestActionsService_GetWorkflowUsageByFileName(t *testing.T) {
200200
}
201201

202202
want := &WorkflowUsage{
203-
Billable: &WorkflowEnvironment{
204-
Ubuntu: &WorkflowBill{
203+
Billable: &WorkflowBillMap{
204+
"UBUNTU": &WorkflowBill{
205205
TotalMS: Int64(180000),
206206
},
207-
MacOS: &WorkflowBill{
207+
"MACOS": &WorkflowBill{
208208
TotalMS: Int64(240000),
209209
},
210-
Windows: &WorkflowBill{
210+
"WINDOWS": &WorkflowBill{
211211
TotalMS: Int64(300000),
212212
},
213213
},
@@ -545,17 +545,17 @@ func TestWorkflowBill_Marshal(t *testing.T) {
545545
testJSONMarshal(t, u, want)
546546
}
547547

548-
func TestWorkflowEnvironment_Marshal(t *testing.T) {
549-
testJSONMarshal(t, &WorkflowEnvironment{}, "{}")
548+
func TestWorkflowBillMap_Marshal(t *testing.T) {
549+
testJSONMarshal(t, &WorkflowBillMap{}, "{}")
550550

551-
u := &WorkflowEnvironment{
552-
Ubuntu: &WorkflowBill{
551+
u := &WorkflowBillMap{
552+
"UBUNTU": &WorkflowBill{
553553
TotalMS: Int64(1),
554554
},
555-
MacOS: &WorkflowBill{
555+
"MACOS": &WorkflowBill{
556556
TotalMS: Int64(1),
557557
},
558-
Windows: &WorkflowBill{
558+
"WINDOWS": &WorkflowBill{
559559
TotalMS: Int64(1),
560560
},
561561
}
@@ -579,14 +579,14 @@ func TestWorkflowUsage_Marshal(t *testing.T) {
579579
testJSONMarshal(t, &WorkflowUsage{}, "{}")
580580

581581
u := &WorkflowUsage{
582-
Billable: &WorkflowEnvironment{
583-
Ubuntu: &WorkflowBill{
582+
Billable: &WorkflowBillMap{
583+
"UBUNTU": &WorkflowBill{
584584
TotalMS: Int64(1),
585585
},
586-
MacOS: &WorkflowBill{
586+
"MACOS": &WorkflowBill{
587587
TotalMS: Int64(1),
588588
},
589-
Windows: &WorkflowBill{
589+
"WINDOWS": &WorkflowBill{
590590
TotalMS: Int64(1),
591591
},
592592
},

github/billing.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,8 @@ type ActionBilling struct {
2424
MinutesUsedBreakdown MinutesUsedBreakdown `json:"minutes_used_breakdown"`
2525
}
2626

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

3330
// PackageBilling represents a GitHub Package billing.
3431
type PackageBilling struct {

github/billing_test.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ func TestBillingService_GetActionsBillingOrg(t *testing.T) {
4343
TotalPaidMinutesUsed: 0,
4444
IncludedMinutes: 3000,
4545
MinutesUsedBreakdown: MinutesUsedBreakdown{
46-
Ubuntu: 205,
47-
MacOS: 10,
48-
Windows: 90,
46+
"UBUNTU": 205,
47+
"MACOS": 10,
48+
"WINDOWS": 90,
4949
},
5050
}
5151
if !cmp.Equal(hook, want) {
@@ -209,9 +209,9 @@ func TestBillingService_GetActionsBillingUser(t *testing.T) {
209209
TotalPaidMinutesUsed: 0,
210210
IncludedMinutes: 3000,
211211
MinutesUsedBreakdown: MinutesUsedBreakdown{
212-
Ubuntu: 205,
213-
MacOS: 10,
214-
Windows: 90,
212+
"UBUNTU": 205,
213+
"MACOS": 10,
214+
"WINDOWS": 90,
215215
},
216216
}
217217
if !cmp.Equal(hook, want) {
@@ -350,9 +350,9 @@ func TestMinutesUsedBreakdown_Marshal(t *testing.T) {
350350
testJSONMarshal(t, &MinutesUsedBreakdown{}, "{}")
351351

352352
u := &MinutesUsedBreakdown{
353-
Ubuntu: 1,
354-
MacOS: 1,
355-
Windows: 1,
353+
"UBUNTU": 1,
354+
"MACOS": 1,
355+
"WINDOWS": 1,
356356
}
357357

358358
want := `{
@@ -372,9 +372,9 @@ func TestActionBilling_Marshal(t *testing.T) {
372372
TotalPaidMinutesUsed: 1,
373373
IncludedMinutes: 1,
374374
MinutesUsedBreakdown: MinutesUsedBreakdown{
375-
Ubuntu: 1,
376-
MacOS: 1,
377-
Windows: 1,
375+
"UBUNTU": 1,
376+
"MACOS": 1,
377+
"WINDOWS": 1,
378378
},
379379
}
380380

github/github-accessors.go

Lines changed: 2 additions & 50 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)