Return HTTP errors properly for some commands (#8037)
* Return HTTP error for `run watch` Partially fixes #8026 * Return HTTP error for `gpg-key delete` Partially fixes #8026
This commit is contained in:
parent
60f2da2d1f
commit
073ec3426b
4 changed files with 44 additions and 2 deletions
|
|
@ -91,7 +91,7 @@ func deleteRun(opts *DeleteOptions) error {
|
|||
|
||||
err = deleteGPGKey(httpClient, host, id)
|
||||
if err != nil {
|
||||
return nil
|
||||
return err
|
||||
}
|
||||
|
||||
if opts.IO.IsStdoutTTY() {
|
||||
|
|
|
|||
|
|
@ -10,6 +10,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"
|
||||
)
|
||||
|
|
@ -170,6 +171,19 @@ func Test_deleteRun(t *testing.T) {
|
|||
wantErr: true,
|
||||
wantErrMsg: "unable to delete GPG key ABC123: either the GPG key is not found or it is not owned by you",
|
||||
},
|
||||
{
|
||||
name: "delete failed",
|
||||
opts: DeleteOptions{KeyID: "ABC123", Confirmed: true},
|
||||
httpStubs: func(reg *httpmock.Registry) {
|
||||
reg.Register(httpmock.REST("GET", "user/gpg_keys"), httpmock.StatusStringResponse(200, keysResp))
|
||||
reg.Register(httpmock.REST("DELETE", "user/gpg_keys/123"), httpmock.StatusJSONResponse(404, api.HTTPError{
|
||||
StatusCode: 404,
|
||||
Message: "GPG key 123 not found",
|
||||
}))
|
||||
},
|
||||
wantErr: true,
|
||||
wantErrMsg: "HTTP 404: GPG key 123 not found (https://api.github.com/user/gpg_keys/123)",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
|
|
|
|||
|
|
@ -173,7 +173,7 @@ func watchRun(opts *WatchOptions) error {
|
|||
opts.IO.StopAlternateScreenBuffer()
|
||||
|
||||
if err != nil {
|
||||
return nil
|
||||
return err
|
||||
}
|
||||
|
||||
// Write the last temporary buffer one last time
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
)
|
||||
|
|
@ -298,6 +299,33 @@ func TestWatchRun(t *testing.T) {
|
|||
wantErr: true,
|
||||
errMsg: "SilentError",
|
||||
},
|
||||
{
|
||||
name: "failed to get run status",
|
||||
tty: true,
|
||||
opts: &WatchOptions{
|
||||
RunID: "1234",
|
||||
},
|
||||
httpStubs: func(reg *httpmock.Registry) {
|
||||
reg.Register(
|
||||
httpmock.REST("GET", "repos/OWNER/REPO/actions/runs/1234"),
|
||||
httpmock.JSONResponse(shared.TestRunWithCommit(1234, shared.InProgress, "", "commit2")),
|
||||
)
|
||||
reg.Register(
|
||||
httpmock.REST("GET", "repos/OWNER/REPO/actions/workflows/123"),
|
||||
httpmock.JSONResponse(shared.TestWorkflow),
|
||||
)
|
||||
reg.Register(
|
||||
httpmock.REST("GET", "repos/OWNER/REPO/actions/runs/1234"),
|
||||
httpmock.StatusJSONResponse(404, api.HTTPError{
|
||||
StatusCode: 404,
|
||||
Message: "run 1234 not found",
|
||||
}),
|
||||
)
|
||||
},
|
||||
wantOut: "\x1b[?1049h\x1b[?1049l",
|
||||
wantErr: true,
|
||||
errMsg: "failed to get run: HTTP 404: run 1234 not found (https://api.github.com/repos/OWNER/REPO/actions/runs/1234?exclude_pull_requests=true)",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue