-
Notifications
You must be signed in to change notification settings - Fork 5.3k
/
display.go
93 lines (82 loc) · 2.41 KB
/
display.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package shared
import (
"fmt"
"github.com/cli/cli/v2/api"
"github.com/cli/cli/v2/internal/text"
"github.com/cli/cli/v2/pkg/cmdutil"
"github.com/cli/cli/v2/pkg/iostreams"
)
func StateTitleWithColor(cs *iostreams.ColorScheme, pr api.PullRequest) string {
prStateColorFunc := cs.ColorFromString(ColorForPRState(pr))
if pr.State == "OPEN" && pr.IsDraft {
return prStateColorFunc("Draft")
}
return prStateColorFunc(text.Title(pr.State))
}
func ColorForPRState(pr api.PullRequest) string {
switch pr.State {
case "OPEN":
if pr.IsDraft {
return "gray"
}
return "green"
case "CLOSED":
return "red"
case "MERGED":
return "magenta"
default:
return ""
}
}
func ColorForIssueState(issue api.Issue) string {
switch issue.State {
case "OPEN":
return "green"
case "CLOSED":
if issue.StateReason == "NOT_PLANNED" {
return "gray"
}
return "magenta"
default:
return ""
}
}
func PrintHeader(io *iostreams.IOStreams, s string) {
fmt.Fprintln(io.Out, io.ColorScheme().Bold(s))
}
func PrintMessage(io *iostreams.IOStreams, s string) {
fmt.Fprintln(io.Out, io.ColorScheme().Gray(s))
}
func ListNoResults(repoName string, itemName string, hasFilters bool) error {
if hasFilters {
return cmdutil.NewNoResultsError(fmt.Sprintf("no %ss match your search in %s", itemName, repoName))
}
return cmdutil.NewNoResultsError(fmt.Sprintf("no open %ss in %s", itemName, repoName))
}
func ListHeader(repoName string, itemName string, matchCount int, totalMatchCount int, hasFilters bool) string {
if hasFilters {
matchVerb := "match"
if totalMatchCount == 1 {
matchVerb = "matches"
}
return fmt.Sprintf("Showing %d of %s in %s that %s your search", matchCount, text.Pluralize(totalMatchCount, itemName), repoName, matchVerb)
}
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 = 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")
}
}
return summary
}