diff --git a/pkg/cmd/run/watch/watch.go b/pkg/cmd/run/watch/watch.go index 70c7d7558..5b51b37ac 100644 --- a/pkg/cmd/run/watch/watch.go +++ b/pkg/cmd/run/watch/watch.go @@ -123,6 +123,9 @@ func watchRun(opts *WatchOptions) error { if run.Status == shared.Completed { fmt.Fprintf(out, "Run %s (%s) has already completed with '%s'\n", cs.Bold(run.Name), cs.Cyanf("%d", run.ID), run.Conclusion) + if opts.ExitStatus && run.Conclusion != shared.Success { + return cmdutil.SilentError + } return nil } diff --git a/pkg/cmd/run/watch/watch_test.go b/pkg/cmd/run/watch/watch_test.go index 4152aad52..8b02ea24d 100644 --- a/pkg/cmd/run/watch/watch_test.go +++ b/pkg/cmd/run/watch/watch_test.go @@ -190,6 +190,21 @@ func TestWatchRun(t *testing.T) { }, wantOut: "Run failed (1234) has already completed with 'failure'\n", }, + { + name: "already completed, exit status", + opts: &WatchOptions{ + RunID: "1234", + ExitStatus: true, + }, + httpStubs: func(reg *httpmock.Registry) { + reg.Register( + httpmock.REST("GET", "repos/OWNER/REPO/actions/runs/1234"), + httpmock.JSONResponse(shared.FailedRun)) + }, + wantOut: "Run failed (1234) has already completed with 'failure'\n", + wantErr: true, + errMsg: "SilentError", + }, { name: "prompt, no in progress runs", tty: true, @@ -307,13 +322,8 @@ func TestWatchRun(t *testing.T) { t.Run(tt.name, func(t *testing.T) { err := watchRun(tt.opts) if tt.wantErr { - assert.Error(t, err) - assert.Equal(t, tt.errMsg, err.Error()) - if !tt.opts.ExitStatus { - return - } - } - if !tt.opts.ExitStatus { + assert.EqualError(t, err, tt.errMsg) + } else { assert.NoError(t, err) } assert.Equal(t, tt.wantOut, stdout.String())