pr checks return distinct exit code for PENDING checks (#7866)

This commit is contained in:
Raj Hawaldar 2023-08-25 23:00:45 +05:30 committed by GitHub
parent 6f618b522c
commit 9fc571499f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 15 additions and 7 deletions

View file

@ -34,10 +34,11 @@ var updaterEnabled = ""
type exitCode int
const (
exitOK exitCode = 0
exitError exitCode = 1
exitCancel exitCode = 2
exitAuth exitCode = 4
exitOK exitCode = 0
exitError exitCode = 1
exitCancel exitCode = 2
exitAuth exitCode = 4
exitPending exitCode = 8
)
func main() {
@ -113,6 +114,8 @@ func mainRun() exitCode {
var authError *root.AuthError
if err == cmdutil.SilentError {
return exitError
} else if err == cmdutil.PendingError {
return exitPending
} else if cmdutil.IsUserCancellation(err) {
if errors.Is(err, terminal.InterruptErr) {
// ensure the next shell prompt will start on its own line

View file

@ -216,8 +216,10 @@ func checksRun(opts *ChecksOptions) error {
}
}
if counts.Failed+counts.Pending > 0 {
if counts.Failed > 0 {
return cmdutil.SilentError
} else if counts.Pending > 0 {
return cmdutil.PendingError
}
return nil

View file

@ -180,7 +180,7 @@ func Test_checksRun(t *testing.T) {
)
},
wantOut: "Some checks are still pending\n0 failing, 2 successful, 0 skipped, and 1 pending checks\n\n✓ cool tests 1m26s sweet link\n✓ rad tests 1m26s sweet link\n* slow tests 1m26s sweet link\n",
wantErr: "SilentError",
wantErr: "PendingError",
},
{
name: "all passing tty",
@ -275,7 +275,7 @@ func Test_checksRun(t *testing.T) {
)
},
wantOut: "cool tests\tpass\t1m26s\tsweet link\t\nrad tests\tpass\t1m26s\tsweet link\t\nslow tests\tpending\t1m26s\tsweet link\t\n",
wantErr: "SilentError",
wantErr: "PendingError",
},
{
name: "all passing",

View file

@ -37,6 +37,9 @@ var SilentError = errors.New("SilentError")
// CancelError signals user-initiated cancellation
var CancelError = errors.New("CancelError")
// PendingError signals nothing failed but something is pending
var PendingError = errors.New("PendingError")
func IsUserCancellation(err error) bool {
return errors.Is(err, CancelError) || errors.Is(err, terminal.InterruptErr)
}