From 6b81b75a84d08f96ec9c1e6fdec842273e92add9 Mon Sep 17 00:00:00 2001 From: Marcelo Carlos Date: Thu, 18 Nov 2021 21:41:47 +0000 Subject: [PATCH] Add missing attribute job_runs in WorkflowRunBill --- github/actions_workflow_runs.go | 11 +++++++++-- github/actions_workflow_runs_test.go | 20 ++++++++++++++++++-- github/github-accessors.go | 16 ++++++++++++++++ github/github-accessors_test.go | 20 ++++++++++++++++++++ 4 files changed, 63 insertions(+), 4 deletions(-) diff --git a/github/actions_workflow_runs.go b/github/actions_workflow_runs.go index 4ccb7a6db4..14165acc8e 100644 --- a/github/actions_workflow_runs.go +++ b/github/actions_workflow_runs.go @@ -70,8 +70,15 @@ type WorkflowRunEnvironment struct { // WorkflowRunBill specifies billable time for a specific environment in a workflow run. type WorkflowRunBill struct { - TotalMS *int64 `json:"total_ms,omitempty"` - Jobs *int `json:"jobs,omitempty"` + TotalMS *int64 `json:"total_ms,omitempty"` + Jobs *int `json:"jobs,omitempty"` + JobRuns []*WorkflowRunJobRun `json:"job_runs,omitempty"` +} + +// WorkflowRunJobRun represents a usage of individual jobs of a specific workflow run. +type WorkflowRunJobRun struct { + JobID *int `json:"job_id,omitempty"` + DurationMS *int64 `json:"duration_ms,omitempty"` } func (s *ActionsService) listWorkflowRuns(ctx context.Context, endpoint string, opts *ListWorkflowRunsOptions) (*WorkflowRuns, *Response, error) { diff --git a/github/actions_workflow_runs_test.go b/github/actions_workflow_runs_test.go index df5be99070..9836249dcb 100644 --- a/github/actions_workflow_runs_test.go +++ b/github/actions_workflow_runs_test.go @@ -366,7 +366,7 @@ func TestActionsService_GetWorkflowRunUsageByID(t *testing.T) { mux.HandleFunc("/repos/o/r/actions/runs/29679449/timing", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") - fmt.Fprint(w, `{"billable":{"UBUNTU":{"total_ms":180000,"jobs":1},"MACOS":{"total_ms":240000,"jobs":4},"WINDOWS":{"total_ms":300000,"jobs":2}},"run_duration_ms":500000}`) + fmt.Fprint(w, `{"billable":{"UBUNTU":{"total_ms":180000,"jobs":1,"job_runs":[{"job_id":1,"duration_ms":60000}]},"MACOS":{"total_ms":240000,"jobs":2,"job_runs":[{"job_id":2,"duration_ms":30000},{"job_id":3,"duration_ms":10000}]},"WINDOWS":{"total_ms":300000,"jobs":2}},"run_duration_ms":500000}`) }) ctx := context.Background() @@ -380,10 +380,26 @@ func TestActionsService_GetWorkflowRunUsageByID(t *testing.T) { Ubuntu: &WorkflowRunBill{ TotalMS: Int64(180000), Jobs: Int(1), + JobRuns: []*WorkflowRunJobRun{ + { + JobID: Int(1), + DurationMS: Int64(60000), + }, + }, }, MacOS: &WorkflowRunBill{ TotalMS: Int64(240000), - Jobs: Int(4), + Jobs: Int(2), + JobRuns: []*WorkflowRunJobRun{ + { + JobID: Int(2), + DurationMS: Int64(30000), + }, + { + JobID: Int(3), + DurationMS: Int64(10000), + }, + }, }, Windows: &WorkflowRunBill{ TotalMS: Int64(300000), diff --git a/github/github-accessors.go b/github/github-accessors.go index 0ec41280f5..c4cc9672cf 100644 --- a/github/github-accessors.go +++ b/github/github-accessors.go @@ -15724,6 +15724,22 @@ func (w *WorkflowRunEvent) GetSender() *User { return w.Sender } +// GetDurationMS returns the DurationMS field if it's non-nil, zero value otherwise. +func (w *WorkflowRunJobRun) GetDurationMS() int64 { + if w == nil || w.DurationMS == nil { + return 0 + } + return *w.DurationMS +} + +// GetJobID returns the JobID field if it's non-nil, zero value otherwise. +func (w *WorkflowRunJobRun) GetJobID() int { + if w == nil || w.JobID == nil { + return 0 + } + return *w.JobID +} + // GetTotalCount returns the TotalCount field if it's non-nil, zero value otherwise. func (w *WorkflowRuns) GetTotalCount() int { if w == nil || w.TotalCount == nil { diff --git a/github/github-accessors_test.go b/github/github-accessors_test.go index 28ffcc6a7b..522d77f48e 100644 --- a/github/github-accessors_test.go +++ b/github/github-accessors_test.go @@ -18423,6 +18423,26 @@ func TestWorkflowRunEvent_GetSender(tt *testing.T) { w.GetSender() } +func TestWorkflowRunJobRun_GetDurationMS(tt *testing.T) { + var zeroValue int64 + w := &WorkflowRunJobRun{DurationMS: &zeroValue} + w.GetDurationMS() + w = &WorkflowRunJobRun{} + w.GetDurationMS() + w = nil + w.GetDurationMS() +} + +func TestWorkflowRunJobRun_GetJobID(tt *testing.T) { + var zeroValue int + w := &WorkflowRunJobRun{JobID: &zeroValue} + w.GetJobID() + w = &WorkflowRunJobRun{} + w.GetJobID() + w = nil + w.GetJobID() +} + func TestWorkflowRuns_GetTotalCount(tt *testing.T) { var zeroValue int w := &WorkflowRuns{TotalCount: &zeroValue}