feat: adding checks at GH PR view

Fixes #6117

Adding checks to PR view as a new line along with changes information.
Isolated 'status' display logic into a shared method in order to reuse it in 'view'.
Updated existing 'view' tests.

TODO: add new tests for PRs with checks.
This commit is contained in:
lpessoa 2022-09-16 13:47:50 -03:00
parent 0ecd424901
commit e8767b9706
No known key found for this signature in database
GPG key ID: CADF029CBD62ECCF
5 changed files with 43 additions and 19 deletions

View file

@ -269,6 +269,7 @@ func (pr *PullRequest) ChecksStatus() (summary PullRequestChecksStatus) {
}
summary.Total++
}
return
}

View file

@ -73,3 +73,19 @@ func ListHeader(repoName string, itemName string, matchCount int, totalMatchCoun
return fmt.Sprintf("Showing %d of %s in %s", matchCount, text.Pluralize(totalMatchCount, fmt.Sprintf("open %s", itemName)), repoName)
}
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)
}
} 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

@ -230,18 +230,7 @@ func printPrs(io *iostreams.IOStreams, totalCount int, prs ...api.PullRequest) {
}
if checks.Total > 0 {
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)
}
} else if checks.Pending > 0 {
summary = cs.Yellow("- Checks pending")
} else if checks.Passing == checks.Total {
summary = cs.Green("✓ Checks passing")
}
summary := shared.PrCheckStatusSummaryWithColor(cs, checks)
fmt.Fprint(w, summary)
}

View file

@ -81,7 +81,7 @@ var defaultFields = []string{
"isDraft", "maintainerCanModify", "mergeable", "additions", "deletions", "commitsCount",
"baseRefName", "headRefName", "headRepositoryOwner", "headRepository", "isCrossRepository",
"reviewRequests", "reviews", "assignees", "labels", "projectCards", "milestone",
"comments", "reactionGroups", "createdAt",
"comments", "reactionGroups", "createdAt", "statusCheckRollup",
}
func viewRun(opts *ViewOptions) error {
@ -171,17 +171,30 @@ func printHumanPrPreview(opts *ViewOptions, pr *api.PullRequest) error {
// Header (Title and State)
fmt.Fprintf(out, "%s #%d\n", cs.Bold(pr.Title), pr.Number)
fmt.Fprintf(out,
"%s • %s wants to merge %s into %s from %s • %s • %s %s \n",
"%s • %s wants to merge %s into %s from %s • %s\n",
shared.StateTitleWithColor(cs, *pr),
pr.Author.Login,
text.Pluralize(pr.Commits.TotalCount, "commit"),
pr.BaseRefName,
pr.HeadRefName,
text.FuzzyAgo(opts.Now(), pr.CreatedAt),
)
// added/removed
fmt.Fprintf(out,
"%s %s",
cs.Green("+"+strconv.Itoa(pr.Additions)),
cs.Red("-"+strconv.Itoa(pr.Deletions)),
)
// checks
checks := pr.ChecksStatus()
if summary := shared.PrCheckStatusSummaryWithColor(cs, checks); summary != "" {
fmt.Fprintf(out, " • %s\n", summary)
} else {
fmt.Fprintln(out)
}
// Reactions
if reactions := shared.ReactionGroupList(pr.ReactionGroups); reactions != "" {
fmt.Fprint(out, reactions)

View file

@ -353,7 +353,8 @@ func TestPRView_Preview(t *testing.T) {
},
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`,
`Open.*nobody wants to merge 12 commits into master from blueberries . about X years ago`,
`.+100.-10`,
`blueberries taste good`,
`View this pull request on GitHub: https://github.com/OWNER/REPO/pull/12`,
},
@ -366,7 +367,8 @@ func TestPRView_Preview(t *testing.T) {
},
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`,
`Open.*nobody wants to merge 12 commits into master from blueberries . about X years ago`,
`.+100.-10`,
`Reviewers:.*1 \(.*Requested.*\)\n`,
`Assignees:.*marseilles, monaco\n`,
`Labels:.*one, two, three, four, five\n`,
@ -398,7 +400,8 @@ func TestPRView_Preview(t *testing.T) {
},
expectedOutputs: []string{
`Blueberries are from a fork #12`,
`Closed.*nobody wants to merge 12 commits into master from blueberries . about X years ago.+100.-10`,
`Closed.*nobody wants to merge 12 commits into master from blueberries . about X years ago`,
`.+100.-10`,
`blueberries taste good`,
`View this pull request on GitHub: https://github.com/OWNER/REPO/pull/12`,
},
@ -411,7 +414,8 @@ func TestPRView_Preview(t *testing.T) {
},
expectedOutputs: []string{
`Blueberries are from a fork #12`,
`Merged.*nobody wants to merge 12 commits into master from blueberries . about X years ago.+100.-10`,
`Merged.*nobody wants to merge 12 commits into master from blueberries . about X years ago`,
`.+100.-10`,
`blueberries taste good`,
`View this pull request on GitHub: https://github.com/OWNER/REPO/pull/12`,
},
@ -424,7 +428,8 @@ func TestPRView_Preview(t *testing.T) {
},
expectedOutputs: []string{
`Blueberries are from a fork #12`,
`Draft.*nobody wants to merge 12 commits into master from blueberries . about X years ago.+100.-10`,
`Draft.*nobody wants to merge 12 commits into master from blueberries . about X years ago`,
`.+100.-10`,
`blueberries taste good`,
`View this pull request on GitHub: https://github.com/OWNER/REPO/pull/12`,
},