diff --git a/pkg/cmd/pr/shared/display.go b/pkg/cmd/pr/shared/display.go index 16194e039..7bd306104 100644 --- a/pkg/cmd/pr/shared/display.go +++ b/pkg/cmd/pr/shared/display.go @@ -75,17 +75,19 @@ func ListHeader(repoName string, itemName string, matchCount int, totalMatchCoun } func PrCheckStatusSummaryWithColor(cs *iostreams.ColorScheme, checks api.PullRequestChecksStatus) string { - var summary string - if checks.Failing > 0 { - if checks.Failing == checks.Total { - summary = cs.Red("× All checks failing") - } else { - summary = cs.Redf("× %d/%d checks failing", checks.Failing, checks.Total) + var summary = cs.Gray("No checks") + if checks.Total > 0 { + if checks.Failing > 0 { + if checks.Failing == checks.Total { + summary = cs.Red("× All checks failing") + } else { + summary = cs.Redf("× %d/%d checks failing", checks.Failing, checks.Total) + } + } else if checks.Pending > 0 { + summary = cs.Yellow("- Checks pending") + } else if checks.Passing == checks.Total { + summary = cs.Green("✓ Checks passing") } - } else if checks.Pending > 0 { - summary = cs.Yellow("- Checks pending") - } else if checks.Passing == checks.Total { - summary = cs.Green("✓ Checks passing") } return summary } diff --git a/pkg/cmd/pr/shared/display_test.go b/pkg/cmd/pr/shared/display_test.go index 3a09fe782..89fdef129 100644 --- a/pkg/cmd/pr/shared/display_test.go +++ b/pkg/cmd/pr/shared/display_test.go @@ -103,6 +103,16 @@ func TestPrCheckStatusSummaryWithColor(t *testing.T) { args api.PullRequestChecksStatus want string }{ + { + Name: "No Checks", + args: api.PullRequestChecksStatus{ + Total: 0, + Failing: 0, + Passing: 0, + Pending: 0, + }, + want: "No checks", + }, { Name: "All Passing", args: api.PullRequestChecksStatus{ diff --git a/pkg/cmd/pr/view/fixtures/prViewPreviewWithNoChecks.json b/pkg/cmd/pr/view/fixtures/prViewPreviewWithNoChecks.json new file mode 100644 index 000000000..563aa6c6b --- /dev/null +++ b/pkg/cmd/pr/view/fixtures/prViewPreviewWithNoChecks.json @@ -0,0 +1,58 @@ +{ + "data": { + "repository": { + "pullRequest": { + "number": 12, + "title": "Blueberries are from a fork", + "state": "OPEN", + "body": "**blueberries taste good**", + "url": "https://github.com/OWNER/REPO/pull/12", + "author": { + "login": "nobody" + }, + "additions": 100, + "deletions": 10, + "assignees": { + "nodes": [], + "totalcount": 0 + }, + "labels": { + "nodes": [], + "totalcount": 0 + }, + "projectcards": { + "nodes": [], + "totalcount": 0 + }, + "milestone": { + "title": "" + }, + "commits": { + "totalCount": 12 + }, + "baseRefName": "master", + "headRefName": "blueberries", + "headRepositoryOwner": { + "login": "hubot" + }, + "isCrossRepository": true, + "isDraft": false, + "statusCheckRollup": { + "nodes": [ + { + "commit": { + "oid": "abc", + "statusCheckRollup": { + "contexts": { + "nodes": [ + ] + } + } + } + } + ] + } + } + } + } +} diff --git a/pkg/cmd/pr/view/view_test.go b/pkg/cmd/pr/view/view_test.go index c9ed388c3..166289050 100644 --- a/pkg/cmd/pr/view/view_test.go +++ b/pkg/cmd/pr/view/view_test.go @@ -490,6 +490,20 @@ func TestPRView_Preview(t *testing.T) { `View this pull request on GitHub: https://github.com/OWNER/REPO/pull/12`, }, }, + "Open PR with no checks": { + branch: "master", + args: "12", + fixtures: map[string]string{ + "PullRequestByNumber": "./fixtures/prViewPreviewWithNoChecks.json", + }, + expectedOutputs: []string{ + `Blueberries are from a fork #12`, + `Open.*nobody wants to merge 12 commits into master from blueberries . about X years ago`, + `.+100.-10 • No checks`, + `blueberries taste good`, + `View this pull request on GitHub: https://github.com/OWNER/REPO/pull/12`, + }, + }, } for name, tc := range tests {