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

Add ListWorkflowJobsAttempt method to ActionsService #3060

Merged
merged 2 commits into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
26 changes: 26 additions & 0 deletions github/actions_workflow_jobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,32 @@
return jobs, resp, nil
}

// ListWorkflowJobsAttempt lists jobs for a workflow run Attempt.
//
// GitHub API docs: https://docs.github.com/rest/actions/workflow-jobs#list-jobs-for-a-workflow-run-attempt
//
//meta:operation GET /repos/{owner}/{repo}/actions/runs/{run_id}/attempts/{attempt_number}/jobs
func (s *ActionsService) ListWorkflowJobsAttempt(ctx context.Context, owner, repo string, runID, attemptNumber int64, opts *ListOptions) (*Jobs, *Response, error) {
u := fmt.Sprintf("repos/%s/%s/actions/runs/%v/attempts/%v/jobs", owner, repo, runID, attemptNumber)
u, err := addOptions(u, opts)
if err != nil {
return nil, nil, err
}

Check warning on line 107 in github/actions_workflow_jobs.go

View check run for this annotation

Codecov / codecov/patch

github/actions_workflow_jobs.go#L106-L107

Added lines #L106 - L107 were not covered by tests

req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}

Check warning on line 112 in github/actions_workflow_jobs.go

View check run for this annotation

Codecov / codecov/patch

github/actions_workflow_jobs.go#L111-L112

Added lines #L111 - L112 were not covered by tests

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

Check warning on line 118 in github/actions_workflow_jobs.go

View check run for this annotation

Codecov / codecov/patch

github/actions_workflow_jobs.go#L117-L118

Added lines #L117 - L118 were not covered by tests

return jobs, resp, nil
}

// GetWorkflowJobByID gets a specific job in a workflow run by ID.
//
// GitHub API docs: https://docs.github.com/rest/actions/workflow-jobs#get-a-job-for-a-workflow-run
Expand Down
40 changes: 40 additions & 0 deletions github/actions_workflow_jobs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,46 @@ func TestActionsService_ListWorkflowJobs_Filter(t *testing.T) {
}
}

func TestActionsService_ListWorkflowJobsAttempt(t *testing.T) {
client, mux, _, teardown := setup()
defer teardown()

mux.HandleFunc("/repos/o/r/actions/runs/29679449/attempts/1/jobs", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
testFormValues(t, r, values{"per_page": "2", "page": "2"})
fmt.Fprint(w, `{"total_count":4,"jobs":[{"id":399444496,"run_id":29679449,"started_at":"2019-01-02T15:04:05Z","completed_at":"2020-01-02T15:04:05Z","run_attempt":2},{"id":399444497,"run_id":29679449,"started_at":"2019-01-02T15:04:05Z","completed_at":"2020-01-02T15:04:05Z","run_attempt":2}]}`)
})
opts := &ListOptions{Page: 2, PerPage: 2}
ctx := context.Background()
jobs, _, err := client.Actions.ListWorkflowJobsAttempt(ctx, "o", "r", 29679449, 1, opts)
if err != nil {
t.Errorf("Actions.ListWorkflowJobsAttempt returned error: %v", err)
}

want := &Jobs{
TotalCount: Int(4),
Jobs: []*WorkflowJob{
{
ID: Int64(399444496),
RunID: Int64(29679449),
StartedAt: &Timestamp{time.Date(2019, time.January, 02, 15, 04, 05, 0, time.UTC)},
CompletedAt: &Timestamp{time.Date(2020, time.January, 02, 15, 04, 05, 0, time.UTC)},
RunAttempt: Int64(2),
},
{
ID: Int64(399444497),
RunID: Int64(29679449),
StartedAt: &Timestamp{time.Date(2019, time.January, 02, 15, 04, 05, 0, time.UTC)},
CompletedAt: &Timestamp{time.Date(2020, time.January, 02, 15, 04, 05, 0, time.UTC)},
RunAttempt: Int64(2),
},
},
}
if !cmp.Equal(jobs, want) {
t.Errorf("Actions.ListWorkflowJobsAttempt returned %+v, want %+v", jobs, want)
}
}
gmlewis marked this conversation as resolved.
Show resolved Hide resolved

func TestActionsService_GetWorkflowJobByID(t *testing.T) {
client, mux, _, teardown := setup()
defer teardown()
Expand Down