From decbbd21654a061d8a9c8ea1e200fbeb3da2d028 Mon Sep 17 00:00:00 2001 From: Raj Hawaldar Date: Sun, 24 Sep 2023 21:57:01 +0530 Subject: [PATCH] Show cancelled checks (#7960) --- pkg/cmd/pr/checks/aggregate.go | 6 ++- pkg/cmd/pr/checks/checks_test.go | 36 ++++++++++----- pkg/cmd/pr/checks/fixtures/someCancelled.json | 45 +++++++++++++++++++ pkg/cmd/pr/checks/fixtures/somePending.json | 8 ++++ pkg/cmd/pr/checks/output.go | 14 ++++-- 5 files changed, 92 insertions(+), 17 deletions(-) create mode 100644 pkg/cmd/pr/checks/fixtures/someCancelled.json diff --git a/pkg/cmd/pr/checks/aggregate.go b/pkg/cmd/pr/checks/aggregate.go index f9f0b73cb..40e34e79a 100644 --- a/pkg/cmd/pr/checks/aggregate.go +++ b/pkg/cmd/pr/checks/aggregate.go @@ -25,6 +25,7 @@ type checkCounts struct { Passed int Pending int Skipping int + Canceled int } func aggregateChecks(checkContexts []api.CheckContext, requiredChecks bool) (checks []check, counts checkCounts) { @@ -70,9 +71,12 @@ func aggregateChecks(checkContexts []api.CheckContext, requiredChecks bool) (che case "SKIPPED", "NEUTRAL": item.Bucket = "skipping" counts.Skipping++ - case "ERROR", "FAILURE", "CANCELLED", "TIMED_OUT", "ACTION_REQUIRED": + case "ERROR", "FAILURE", "TIMED_OUT", "ACTION_REQUIRED": item.Bucket = "fail" counts.Failed++ + case "CANCELLED": + item.Bucket = "cancel" + counts.Canceled++ default: // "EXPECTED", "REQUESTED", "WAITING", "QUEUED", "PENDING", "IN_PROGRESS", "STALE" item.Bucket = "pending" counts.Pending++ diff --git a/pkg/cmd/pr/checks/checks_test.go b/pkg/cmd/pr/checks/checks_test.go index 06377e516..dcab36117 100644 --- a/pkg/cmd/pr/checks/checks_test.go +++ b/pkg/cmd/pr/checks/checks_test.go @@ -167,9 +167,21 @@ func Test_checksRun(t *testing.T) { httpmock.FileResponse("./fixtures/someFailing.json"), ) }, - wantOut: "Some checks were not successful\n1 failing, 1 successful, 0 skipped, and 1 pending checks\n\nX sad tests 1m26s sweet link\n✓ cool tests 1m26s sweet link\n* slow tests 1m26s sweet link\n", + wantOut: "Some checks were not successful\n0 cancelled, 1 failing, 1 successful, 0 skipped, and 1 pending checks\n\nX sad tests 1m26s sweet link\n✓ cool tests 1m26s sweet link\n* slow tests 1m26s sweet link\n", wantErr: "SilentError", }, + { + name: "some cancelled tty", + tty: true, + httpStubs: func(reg *httpmock.Registry) { + reg.Register( + httpmock.GraphQL(`query PullRequestStatusChecks\b`), + httpmock.FileResponse("./fixtures/someCancelled.json"), + ) + }, + wantOut: "Some checks were cancelled\n1 cancelled, 0 failing, 2 successful, 0 skipped, and 0 pending checks\n\n✓ cool tests 1m26s sweet link\n- sad tests 1m26s sweet link\n✓ awesome tests 1m26s sweet link\n", + wantErr: "", + }, { name: "some pending tty", tty: true, @@ -179,7 +191,7 @@ func Test_checksRun(t *testing.T) { httpmock.FileResponse("./fixtures/somePending.json"), ) }, - 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", + wantOut: "Some checks are still pending\n1 cancelled, 0 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- sad tests 1m26s sweet link\n", wantErr: "PendingError", }, { @@ -191,7 +203,7 @@ func Test_checksRun(t *testing.T) { httpmock.FileResponse("./fixtures/allPassing.json"), ) }, - wantOut: "All checks were successful\n0 failing, 3 successful, 0 skipped, and 0 pending checks\n\n✓ awesome tests 1m26s sweet link\n✓ cool tests 1m26s sweet link\n✓ rad tests 1m26s sweet link\n", + wantOut: "All checks were successful\n0 cancelled, 0 failing, 3 successful, 0 skipped, and 0 pending checks\n\n✓ awesome tests 1m26s sweet link\n✓ cool tests 1m26s sweet link\n✓ rad tests 1m26s sweet link\n", wantErr: "", }, { @@ -204,7 +216,7 @@ func Test_checksRun(t *testing.T) { httpmock.FileResponse("./fixtures/allPassing.json"), ) }, - wantOut: "\x1b[?1049hAll checks were successful\n0 failing, 3 successful, 0 skipped, and 0 pending checks\n\n✓ awesome tests 1m26s sweet link\n✓ cool tests 1m26s sweet link\n✓ rad tests 1m26s sweet link\n\x1b[?1049lAll checks were successful\n0 failing, 3 successful, 0 skipped, and 0 pending checks\n\n✓ awesome tests 1m26s sweet link\n✓ cool tests 1m26s sweet link\n✓ rad tests 1m26s sweet link\n", + wantOut: "\x1b[?1049hAll checks were successful\n0 cancelled, 0 failing, 3 successful, 0 skipped, and 0 pending checks\n\n✓ awesome tests 1m26s sweet link\n✓ cool tests 1m26s sweet link\n✓ rad tests 1m26s sweet link\n\x1b[?1049lAll checks were successful\n0 cancelled, 0 failing, 3 successful, 0 skipped, and 0 pending checks\n\n✓ awesome tests 1m26s sweet link\n✓ cool tests 1m26s sweet link\n✓ rad tests 1m26s sweet link\n", wantErr: "", }, { @@ -218,7 +230,7 @@ func Test_checksRun(t *testing.T) { httpmock.FileResponse("./fixtures/someFailing.json"), ) }, - wantOut: "\x1b[?1049h\x1b[0;0H\x1b[JRefreshing checks status every 0 seconds. Press Ctrl+C to quit.\n\nSome checks were not successful\n1 failing, 1 successful, 0 skipped, and 1 pending checks\n\nX sad tests 1m26s sweet link\n✓ cool tests 1m26s sweet link\n* slow tests 1m26s sweet link\n\x1b[?1049lSome checks were not successful\n1 failing, 1 successful, 0 skipped, and 1 pending checks\n\nX sad tests 1m26s sweet link\n✓ cool tests 1m26s sweet link\n* slow tests 1m26s sweet link\n", + wantOut: "\x1b[?1049h\x1b[0;0H\x1b[JRefreshing checks status every 0 seconds. Press Ctrl+C to quit.\n\nSome checks were not successful\n0 cancelled, 1 failing, 1 successful, 0 skipped, and 1 pending checks\n\nX sad tests 1m26s sweet link\n✓ cool tests 1m26s sweet link\n* slow tests 1m26s sweet link\n\x1b[?1049lSome checks were not successful\n0 cancelled, 1 failing, 1 successful, 0 skipped, and 1 pending checks\n\nX sad tests 1m26s sweet link\n✓ cool tests 1m26s sweet link\n* slow tests 1m26s sweet link\n", wantErr: "SilentError", }, { @@ -230,7 +242,7 @@ func Test_checksRun(t *testing.T) { httpmock.FileResponse("./fixtures/withStatuses.json"), ) }, - wantOut: "Some checks were not successful\n1 failing, 2 successful, 0 skipped, and 0 pending checks\n\nX a status sweet link\n✓ cool tests 1m26s sweet link\n✓ rad tests 1m26s sweet link\n", + wantOut: "Some checks were not successful\n0 cancelled, 1 failing, 2 successful, 0 skipped, and 0 pending checks\n\nX a status sweet link\n✓ cool tests 1m26s sweet link\n✓ rad tests 1m26s sweet link\n", wantErr: "SilentError", }, { @@ -274,7 +286,7 @@ func Test_checksRun(t *testing.T) { httpmock.FileResponse("./fixtures/somePending.json"), ) }, - wantOut: "cool tests\tpass\t1m26s\tsweet link\t\nrad tests\tpass\t1m26s\tsweet link\t\nslow tests\tpending\t1m26s\tsweet link\t\n", + wantOut: "cool tests\tpass\t1m26s\tsweet link\t\nrad tests\tpass\t1m26s\tsweet link\t\nslow tests\tpending\t1m26s\tsweet link\t\nsad tests\tfail\t1m26s\tsweet link\t\n", wantErr: "PendingError", }, { @@ -308,7 +320,7 @@ func Test_checksRun(t *testing.T) { httpmock.FileResponse("./fixtures/someSkipping.json"), ) }, - wantOut: "All checks were successful\n0 failing, 1 successful, 2 skipped, and 0 pending checks\n\n✓ cool tests 1m26s sweet link\n- rad tests 1m26s sweet link\n- skip tests 1m26s sweet link\n", + wantOut: "All checks were successful\n0 cancelled, 0 failing, 1 successful, 2 skipped, and 0 pending checks\n\n✓ cool tests 1m26s sweet link\n- rad tests 1m26s sweet link\n- skip tests 1m26s sweet link\n", wantErr: "", }, { @@ -332,7 +344,7 @@ func Test_checksRun(t *testing.T) { httpmock.FileResponse("./fixtures/onlyRequired.json"), ) }, - wantOut: "All checks were successful\n0 failing, 1 successful, 0 skipped, and 0 pending checks\n\n✓ cool tests 1m26s sweet link\n", + wantOut: "All checks were successful\n0 cancelled, 0 failing, 1 successful, 0 skipped, and 0 pending checks\n\n✓ cool tests 1m26s sweet link\n", wantErr: "", }, { @@ -381,7 +393,7 @@ func Test_checksRun(t *testing.T) { httpmock.FileResponse("./fixtures/withDescriptions.json"), ) }, - wantOut: "All checks were successful\n0 failing, 3 successful, 0 skipped, and 0 pending checks\n\n✓ awesome tests awesome description 1m26s sweet link\n✓ cool tests cool description 1m26s sweet link\n✓ rad tests rad description 1m26s sweet link\n", + wantOut: "All checks were successful\n0 cancelled, 0 failing, 3 successful, 0 skipped, and 0 pending checks\n\n✓ awesome tests awesome description 1m26s sweet link\n✓ cool tests cool description 1m26s sweet link\n✓ rad tests rad description 1m26s sweet link\n", wantErr: "", }, { @@ -404,7 +416,7 @@ func Test_checksRun(t *testing.T) { httpmock.FileResponse("./fixtures/withEvents.json"), ) }, - wantOut: "All checks were successful\n0 failing, 2 successful, 0 skipped, and 0 pending checks\n\n✓ tests/cool tests (pull_request) cool description 1m26s sweet link\n✓ tests/cool tests (push) cool description 1m26s sweet link\n", + wantOut: "All checks were successful\n0 cancelled, 0 failing, 2 successful, 0 skipped, and 0 pending checks\n\n✓ tests/cool tests (pull_request) cool description 1m26s sweet link\n✓ tests/cool tests (push) cool description 1m26s sweet link\n", wantErr: "", }, { @@ -417,7 +429,7 @@ func Test_checksRun(t *testing.T) { httpmock.FileResponse("./fixtures/withoutEvents.json"), ) }, - wantOut: "All checks were successful\n0 failing, 1 successful, 0 skipped, and 0 pending checks\n\n✓ tests/cool tests cool description 1m26s sweet link\n", + wantOut: "All checks were successful\n0 cancelled, 0 failing, 1 successful, 0 skipped, and 0 pending checks\n\n✓ tests/cool tests cool description 1m26s sweet link\n", wantErr: "", }, { diff --git a/pkg/cmd/pr/checks/fixtures/someCancelled.json b/pkg/cmd/pr/checks/fixtures/someCancelled.json new file mode 100644 index 000000000..5e321a5f3 --- /dev/null +++ b/pkg/cmd/pr/checks/fixtures/someCancelled.json @@ -0,0 +1,45 @@ +{ + "data": { + "node": { + "statusCheckRollup": { + "nodes": [ + { + "commit": { + "oid": "abc", + "statusCheckRollup": { + "contexts": { + "nodes": [ + { + "conclusion": "SUCCESS", + "status": "COMPLETED", + "name": "cool tests", + "completedAt": "2020-08-27T19:00:12Z", + "startedAt": "2020-08-27T18:58:46Z", + "detailsUrl": "sweet link" + }, + { + "conclusion": "CANCELLED", + "status": "COMPLETED", + "name": "sad tests", + "completedAt": "2020-08-27T19:00:12Z", + "startedAt": "2020-08-27T18:58:46Z", + "detailsUrl": "sweet link" + }, + { + "conclusion": "SUCCESS", + "status": "COMPLETED", + "name": "awesome tests", + "completedAt": "2020-08-27T19:00:12Z", + "startedAt": "2020-08-27T18:58:46Z", + "detailsUrl": "sweet link" + } + ] + } + } + } + } + ] + } + } + } +} diff --git a/pkg/cmd/pr/checks/fixtures/somePending.json b/pkg/cmd/pr/checks/fixtures/somePending.json index a96ea4fda..c10cb2f84 100644 --- a/pkg/cmd/pr/checks/fixtures/somePending.json +++ b/pkg/cmd/pr/checks/fixtures/somePending.json @@ -32,6 +32,14 @@ "completedAt": "2020-08-27T19:00:12Z", "startedAt": "2020-08-27T18:58:46Z", "detailsUrl": "sweet link" + }, + { + "conclusion": "CANCELLED", + "status": "COMPLETED", + "name": "sad tests", + "completedAt": "2020-08-27T19:00:12Z", + "startedAt": "2020-08-27T18:58:46Z", + "detailsUrl": "sweet link" } ] } diff --git a/pkg/cmd/pr/checks/output.go b/pkg/cmd/pr/checks/output.go index a1e3f889a..9efee29cf 100644 --- a/pkg/cmd/pr/checks/output.go +++ b/pkg/cmd/pr/checks/output.go @@ -28,7 +28,7 @@ func addRow(tp *tableprinter.TablePrinter, io *iostreams.IOStreams, o check) { case "pending": mark = "*" markColor = cs.Yellow - case "skipping": + case "skipping", "cancel": mark = "-" markColor = cs.Gray } @@ -49,7 +49,11 @@ func addRow(tp *tableprinter.TablePrinter, io *iostreams.IOStreams, o check) { tp.AddField(o.Link) } else { tp.AddField(o.Name) - tp.AddField(o.Bucket) + if o.Bucket == "cancel" { + tp.AddField("fail") + } else { + tp.AddField(o.Bucket) + } if elapsed == "" { tp.AddField("0") } else { @@ -69,12 +73,14 @@ func printSummary(io *iostreams.IOStreams, counts checkCounts) { summary = "Some checks were not successful" } else if counts.Pending > 0 { summary = "Some checks are still pending" + } else if counts.Canceled > 0 { + summary = "Some checks were cancelled" } else { summary = "All checks were successful" } - tallies := fmt.Sprintf("%d failing, %d successful, %d skipped, and %d pending checks", - counts.Failed, counts.Passed, counts.Skipping, counts.Pending) + tallies := fmt.Sprintf("%d cancelled, %d failing, %d successful, %d skipped, and %d pending checks", + counts.Canceled, counts.Failed, counts.Passed, counts.Skipping, counts.Pending) summary = fmt.Sprintf("%s\n%s", io.ColorScheme().Bold(summary), tallies) }