From 9fc571499f79bd2c76fd07cd780f6c35929b2347 Mon Sep 17 00:00:00 2001 From: Raj Hawaldar Date: Fri, 25 Aug 2023 23:00:45 +0530 Subject: [PATCH] pr checks return distinct exit code for PENDING checks (#7866) --- cmd/gh/main.go | 11 +++++++---- pkg/cmd/pr/checks/checks.go | 4 +++- pkg/cmd/pr/checks/checks_test.go | 4 ++-- pkg/cmdutil/errors.go | 3 +++ 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/cmd/gh/main.go b/cmd/gh/main.go index 15af90721..bcce3b427 100644 --- a/cmd/gh/main.go +++ b/cmd/gh/main.go @@ -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 diff --git a/pkg/cmd/pr/checks/checks.go b/pkg/cmd/pr/checks/checks.go index 6cd47cc98..335226a9c 100644 --- a/pkg/cmd/pr/checks/checks.go +++ b/pkg/cmd/pr/checks/checks.go @@ -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 diff --git a/pkg/cmd/pr/checks/checks_test.go b/pkg/cmd/pr/checks/checks_test.go index e73e15731..06377e516 100644 --- a/pkg/cmd/pr/checks/checks_test.go +++ b/pkg/cmd/pr/checks/checks_test.go @@ -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", diff --git a/pkg/cmdutil/errors.go b/pkg/cmdutil/errors.go index d9729bd83..26a059d25 100644 --- a/pkg/cmdutil/errors.go +++ b/pkg/cmdutil/errors.go @@ -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) }