update(run): Use attempt input when fetching jobs (#7831)
* Introduce attempt flag for run watch and use attempt input when fetching jobs * Handle attempt input for 'run watch' commands instead of using the latest attempt * Revert attempt flag implementation for 'run watch' command because it is intended only for the latest attempt * Fix tests for cases when attempt flag is used on 'run view' command --------- Co-authored-by: Andy Feller <andyfeller@github.com>
This commit is contained in:
parent
8d53e246f2
commit
9d04ee6c8d
4 changed files with 13 additions and 9 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue