Add accurate context when run rerun fails (#10774)
* Add accurate context when run rerun fails * Update tests to verify behaviour for API errors Signed-off-by: Babak K. Shandiz <babakks@github.com> * Use the new `httpmock.JSONErrorResponse` helper Signed-off-by: Babak K. Shandiz <babakks@github.com> --------- Signed-off-by: Babak K. Shandiz <babakks@github.com> Co-authored-by: Babak K. Shandiz <babakks@github.com>
This commit is contained in:
parent
b83d335f2f
commit
1eee56ec00
2 changed files with 37 additions and 7 deletions
|
|
@ -202,10 +202,7 @@ func rerunRun(client *api.Client, repo ghrepo.Interface, run *shared.Run, onlyFa
|
|||
if err != nil {
|
||||
var httpError api.HTTPError
|
||||
if errors.As(err, &httpError) && httpError.StatusCode == 403 {
|
||||
if httpError.Message == "Unable to retry this workflow run because it was created over a month ago" {
|
||||
return fmt.Errorf("run %d cannot be rerun; %s", run.ID, httpError.Message)
|
||||
}
|
||||
return fmt.Errorf("run %d cannot be rerun; its workflow file may be broken", run.ID)
|
||||
return fmt.Errorf("run %d cannot be rerun; %s", run.ID, httpError.Message)
|
||||
}
|
||||
return fmt.Errorf("failed to rerun: %w", err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ import (
|
|||
"github.com/cli/cli/v2/pkg/cmdutil"
|
||||
"github.com/cli/cli/v2/pkg/httpmock"
|
||||
"github.com/cli/cli/v2/pkg/iostreams"
|
||||
"github.com/cli/go-gh/v2/pkg/api"
|
||||
"github.com/google/shlex"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
|
@ -374,7 +375,7 @@ func TestRerun(t *testing.T) {
|
|||
errOut: "no recent runs have failed; please specify a specific `<run-id>`",
|
||||
},
|
||||
{
|
||||
name: "unrerunnable",
|
||||
name: "API error (403)",
|
||||
tty: true,
|
||||
opts: &RerunOptions{
|
||||
RunID: "3",
|
||||
|
|
@ -392,10 +393,42 @@ func TestRerun(t *testing.T) {
|
|||
}))
|
||||
reg.Register(
|
||||
httpmock.REST("POST", "repos/OWNER/REPO/actions/runs/3/rerun"),
|
||||
httpmock.StatusStringResponse(403, "no"))
|
||||
httpmock.JSONErrorResponse(403, api.HTTPError{
|
||||
StatusCode: 403,
|
||||
Message: "blah blah",
|
||||
}),
|
||||
)
|
||||
},
|
||||
wantErr: true,
|
||||
errOut: "run 3 cannot be rerun; its workflow file may be broken",
|
||||
errOut: "run 3 cannot be rerun; blah blah",
|
||||
},
|
||||
{
|
||||
name: "API error (non-403)",
|
||||
tty: true,
|
||||
opts: &RerunOptions{
|
||||
RunID: "3",
|
||||
},
|
||||
httpStubs: func(reg *httpmock.Registry) {
|
||||
reg.Register(
|
||||
httpmock.REST("GET", "repos/OWNER/REPO/actions/runs/3"),
|
||||
httpmock.JSONResponse(shared.SuccessfulRun))
|
||||
reg.Register(
|
||||
httpmock.REST("GET", "repos/OWNER/REPO/actions/workflows/123"),
|
||||
httpmock.JSONResponse(workflowShared.WorkflowsPayload{
|
||||
Workflows: []workflowShared.Workflow{
|
||||
shared.TestWorkflow,
|
||||
},
|
||||
}))
|
||||
reg.Register(
|
||||
httpmock.REST("POST", "repos/OWNER/REPO/actions/runs/3/rerun"),
|
||||
httpmock.JSONErrorResponse(500, api.HTTPError{
|
||||
StatusCode: 500,
|
||||
Message: "blah blah",
|
||||
}),
|
||||
)
|
||||
},
|
||||
wantErr: true,
|
||||
errOut: "failed to rerun: HTTP 500: blah blah (https://api.github.com/repos/OWNER/REPO/actions/runs/3/rerun)",
|
||||
},
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue