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