diff --git a/pkg/cmd/run/shared/shared.go b/pkg/cmd/run/shared/shared.go index cd9d481b8..516e70b50 100644 --- a/pkg/cmd/run/shared/shared.go +++ b/pkg/cmd/run/shared/shared.go @@ -429,7 +429,7 @@ type JobsPayload struct { Jobs []Job } -func GetJobs(client *api.Client, repo ghrepo.Interface, run *Run) ([]Job, error) { +func GetJobs(client *api.Client, repo ghrepo.Interface, run *Run, attempt uint64) ([]Job, error) { if run.Jobs != nil { return run.Jobs, nil } @@ -438,6 +438,10 @@ func GetJobs(client *api.Client, repo ghrepo.Interface, run *Run) ([]Job, error) query.Set("per_page", "100") jobsPath := fmt.Sprintf("%s?%s", run.JobsURL, query.Encode()) + if attempt > 0 { + jobsPath = fmt.Sprintf("repos/%s/actions/runs/%d/attempts/%d/jobs?%s", ghrepo.FullName(repo), run.ID, attempt, query.Encode()) + } + for jobsPath != "" { var resp JobsPayload var err error diff --git a/pkg/cmd/run/view/view.go b/pkg/cmd/run/view/view.go index 6b96c90f8..bc40b66ee 100644 --- a/pkg/cmd/run/view/view.go +++ b/pkg/cmd/run/view/view.go @@ -221,7 +221,7 @@ func runView(opts *ViewOptions) error { if shouldFetchJobs(opts) { opts.IO.StartProgressIndicator() - jobs, err = shared.GetJobs(client, repo, run) + jobs, err = shared.GetJobs(client, repo, run, attempt) opts.IO.StopProgressIndicator() if err != nil { return err @@ -259,7 +259,7 @@ func runView(opts *ViewOptions) error { if selectedJob == nil && len(jobs) == 0 { opts.IO.StartProgressIndicator() - jobs, err = shared.GetJobs(client, repo, run) + jobs, err = shared.GetJobs(client, repo, run, attempt) opts.IO.StopProgressIndicator() if err != nil { return fmt.Errorf("failed to get jobs: %w", err) diff --git a/pkg/cmd/run/view/view_test.go b/pkg/cmd/run/view/view_test.go index 36d563eee..86aab619b 100644 --- a/pkg/cmd/run/view/view_test.go +++ b/pkg/cmd/run/view/view_test.go @@ -256,7 +256,7 @@ func TestViewRun(t *testing.T) { "name": "REPO"}} ]}}}}`)) reg.Register( - httpmock.REST("GET", "runs/3/jobs"), + httpmock.REST("GET", "repos/OWNER/REPO/actions/runs/3/attempts/3/jobs"), httpmock.JSONResponse(shared.JobsPayload{ Jobs: []shared.Job{ shared.SuccessfulJob, @@ -369,7 +369,7 @@ func TestViewRun(t *testing.T) { httpmock.GraphQL(`query PullRequestForRun`), httpmock.StringResponse(``)) reg.Register( - httpmock.REST("GET", "runs/3/jobs"), + httpmock.REST("GET", "repos/OWNER/REPO/actions/runs/3/attempts/3/jobs"), httpmock.JSONResponse(shared.JobsPayload{})) reg.Register( httpmock.REST("GET", "repos/OWNER/REPO/actions/workflows/123"), @@ -442,7 +442,7 @@ func TestViewRun(t *testing.T) { httpmock.GraphQL(`query PullRequestForRun`), httpmock.StringResponse(``)) reg.Register( - httpmock.REST("GET", "runs/3/jobs"), + httpmock.REST("GET", "repos/OWNER/REPO/actions/runs/3/attempts/3/jobs"), httpmock.JSONResponse(shared.JobsPayload{ Jobs: []shared.Job{ shared.SuccessfulJob, @@ -616,7 +616,7 @@ func TestViewRun(t *testing.T) { httpmock.REST("GET", "repos/OWNER/REPO/actions/runs/3/attempts/3"), httpmock.JSONResponse(shared.SuccessfulRun)) reg.Register( - httpmock.REST("GET", "runs/3/jobs"), + httpmock.REST("GET", "repos/OWNER/REPO/actions/runs/3/attempts/3/jobs"), httpmock.JSONResponse(shared.JobsPayload{ Jobs: []shared.Job{ shared.SuccessfulJob, @@ -846,7 +846,7 @@ func TestViewRun(t *testing.T) { httpmock.REST("GET", "repos/OWNER/REPO/actions/runs/1234/attempts/3"), httpmock.JSONResponse(shared.FailedRun)) reg.Register( - httpmock.REST("GET", "runs/1234/jobs"), + httpmock.REST("GET", "repos/OWNER/REPO/actions/runs/1234/attempts/3/jobs"), httpmock.JSONResponse(shared.JobsPayload{ Jobs: []shared.Job{ shared.SuccessfulJob, diff --git a/pkg/cmd/run/watch/watch.go b/pkg/cmd/run/watch/watch.go index 48d50ed57..27a7ba272 100644 --- a/pkg/cmd/run/watch/watch.go +++ b/pkg/cmd/run/watch/watch.go @@ -207,7 +207,7 @@ func renderRun(out io.Writer, opts WatchOptions, client *api.Client, repo ghrepo return nil, fmt.Errorf("failed to get run: %w", err) } - jobs, err := shared.GetJobs(client, repo, run) + jobs, err := shared.GetJobs(client, repo, run, 0) if err != nil { return nil, fmt.Errorf("failed to get jobs: %w", err) }