(io *iostreams.IOStreams, totalCount int, prs ...api.PullRequest)
| 228 | } |
| 229 | |
| 230 | func printPrs(io *iostreams.IOStreams, totalCount int, prs ...api.PullRequest) { |
| 231 | w := io.Out |
| 232 | cs := io.ColorScheme() |
| 233 | |
| 234 | for _, pr := range prs { |
| 235 | prNumber := fmt.Sprintf("#%d", pr.Number) |
| 236 | |
| 237 | prStateColorFunc := cs.ColorFromString(shared.ColorForPRState(pr)) |
| 238 | |
| 239 | fmt.Fprintf(w, " %s %s %s", prStateColorFunc(prNumber), text.Truncate(50, text.RemoveExcessiveWhitespace(pr.Title)), cs.Cyan("["+pr.HeadLabel()+"]")) |
| 240 | |
| 241 | checks := pr.ChecksStatus() |
| 242 | reviews := pr.ReviewStatus() |
| 243 | |
| 244 | if pr.State == "OPEN" { |
| 245 | reviewStatus := reviews.ChangesRequested || reviews.Approved || reviews.ReviewRequired |
| 246 | if checks.Total > 0 || reviewStatus { |
| 247 | // show checks & reviews on their own line |
| 248 | fmt.Fprintf(w, "\n ") |
| 249 | } |
| 250 | |
| 251 | if checks.Total > 0 { |
| 252 | summary := shared.PrCheckStatusSummaryWithColor(cs, checks) |
| 253 | fmt.Fprint(w, summary) |
| 254 | } |
| 255 | |
| 256 | if checks.Total > 0 && reviewStatus { |
| 257 | // add padding between checks & reviews |
| 258 | fmt.Fprint(w, " ") |
| 259 | } |
| 260 | |
| 261 | if reviews.ChangesRequested { |
| 262 | fmt.Fprint(w, cs.Red("+ Changes requested")) |
| 263 | } else if reviews.ReviewRequired { |
| 264 | fmt.Fprint(w, cs.Yellow("- Review required")) |
| 265 | } else if reviews.Approved { |
| 266 | numRequiredApprovals := pr.BaseRef.BranchProtectionRule.RequiredApprovingReviewCount |
| 267 | gotApprovals := totalApprovals(&pr) |
| 268 | s := fmt.Sprintf("%d", gotApprovals) |
| 269 | if numRequiredApprovals > 0 { |
| 270 | s = fmt.Sprintf("%d/%d", gotApprovals, numRequiredApprovals) |
| 271 | } |
| 272 | fmt.Fprint(w, cs.Green(fmt.Sprintf("✓ %s Approved", s))) |
| 273 | } |
| 274 | |
| 275 | if pr.Mergeable == api.PullRequestMergeableMergeable { |
| 276 | // prefer "No merge conflicts" to "Mergeable" as there is more to mergeability |
| 277 | // than the git status. Missing or failing required checks prevent merging |
| 278 | // even though a PR is technically mergeable, which is often a source of confusion. |
| 279 | fmt.Fprintf(w, " %s", cs.Green("✓ No merge conflicts")) |
| 280 | } else if pr.Mergeable == api.PullRequestMergeableConflicting { |
| 281 | fmt.Fprintf(w, " %s", cs.Red("× Merge conflicts")) |
| 282 | } else if pr.Mergeable == api.PullRequestMergeableUnknown { |
| 283 | fmt.Fprintf(w, " %s", cs.Yellow("! Merge conflict status unknown")) |
| 284 | } |
| 285 | |
| 286 | if pr.BaseRef.BranchProtectionRule.RequiresStrictStatusChecks { |
| 287 | switch pr.MergeStateStatus { |
no test coverage detected