Adding no checks message when PR has no checks

Including additional tests.
This commit is contained in:
lpessoa 2022-10-05 22:10:38 -03:00
parent 6246f89690
commit fb6f538f88
No known key found for this signature in database
GPG key ID: CADF029CBD62ECCF
4 changed files with 94 additions and 10 deletions

View file

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

View file

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

View file

@ -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": [
]
}
}
}
}
]
}
}
}
}
}

View file

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