Merge pull request #7647 from rajhawaldar/ghRunCancelInputValidation
This commit is contained in:
commit
0809eb7247
2 changed files with 20 additions and 3 deletions
|
|
@ -4,6 +4,7 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/cli/cli/v2/api"
|
||||
"github.com/cli/cli/v2/internal/ghrepo"
|
||||
|
|
@ -59,6 +60,12 @@ func NewCmdCancel(f *cmdutil.Factory, runF func(*CancelOptions) error) *cobra.Co
|
|||
}
|
||||
|
||||
func runCancel(opts *CancelOptions) error {
|
||||
if opts.RunID != "" {
|
||||
_, err := strconv.Atoi(opts.RunID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("invalid run_id %#v", opts.RunID)
|
||||
}
|
||||
}
|
||||
httpClient, err := opts.HttpClient()
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to create http client: %w", err)
|
||||
|
|
@ -120,7 +127,7 @@ func runCancel(opts *CancelOptions) error {
|
|||
return err
|
||||
}
|
||||
|
||||
fmt.Fprintf(opts.IO.Out, "%s Request to cancel workflow submitted.\n", cs.SuccessIcon())
|
||||
fmt.Fprintf(opts.IO.Out, "%s Request to cancel workflow %s submitted.\n", cs.SuccessIcon(), runID)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -111,7 +111,7 @@ func TestRunCancel(t *testing.T) {
|
|||
httpmock.REST("POST", "repos/OWNER/REPO/actions/runs/1234/cancel"),
|
||||
httpmock.StatusStringResponse(202, "{}"))
|
||||
},
|
||||
wantOut: "✓ Request to cancel workflow submitted.\n",
|
||||
wantOut: "✓ Request to cancel workflow 1234 submitted.\n",
|
||||
},
|
||||
{
|
||||
name: "not found",
|
||||
|
|
@ -201,7 +201,17 @@ func TestRunCancel(t *testing.T) {
|
|||
return prompter.IndexFor(opts, "* cool commit, CI (trunk) Feb 23, 2021")
|
||||
})
|
||||
},
|
||||
wantOut: "✓ Request to cancel workflow submitted.\n",
|
||||
wantOut: "✓ Request to cancel workflow 1234 submitted.\n",
|
||||
},
|
||||
{
|
||||
name: "invalid run_id",
|
||||
opts: &CancelOptions{
|
||||
RunID: "12\n34",
|
||||
},
|
||||
httpStubs: func(reg *httpmock.Registry) {
|
||||
},
|
||||
wantErr: true,
|
||||
errMsg: "invalid run_id \"12\\n34\"",
|
||||
},
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue