From 1980cc83b9dc93dae11d653fadff73944a0f79e5 Mon Sep 17 00:00:00 2001 From: Des Preston Date: Fri, 9 Jul 2021 11:54:58 -0400 Subject: [PATCH 1/2] return SilentError if completed run failed If `gh run watch ${ID} --exit-status` is run and "ID" is the ID of a completed job that failed, return a SilentError. This ensures that the program returns a non-zero code. Fixes #3962 --- pkg/cmd/run/watch/watch.go | 3 +++ 1 file changed, 3 insertions(+) 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 } From 13037226c232659db87aa44c0bf99ad3a5b769a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Mon, 12 Jul 2021 16:58:45 +0200 Subject: [PATCH 2/2] Add test for `gh run watch --exit-status` with completed runs --- pkg/cmd/run/watch/watch_test.go | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) 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())