diff --git a/pkg/cmd/run/cancel/cancel.go b/pkg/cmd/run/cancel/cancel.go index e5f77e016..c29de543a 100644 --- a/pkg/cmd/run/cancel/cancel.go +++ b/pkg/cmd/run/cancel/cancel.go @@ -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 } diff --git a/pkg/cmd/run/cancel/cancel_test.go b/pkg/cmd/run/cancel/cancel_test.go index fdfedfa0c..78906ad2e 100644 --- a/pkg/cmd/run/cancel/cancel_test.go +++ b/pkg/cmd/run/cancel/cancel_test.go @@ -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\"", }, }