Merge pull request #3982 from despreston/des/err-return

Return SilentError if completed run failed
This commit is contained in:
Mislav Marohnić 2021-07-12 17:05:41 +02:00 committed by GitHub
commit cd3df4cdf9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 7 deletions

View file

@ -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
}

View file

@ -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())