Move colorFuncForState for a PR/issue state to the utils package
This commit is contained in:
parent
d429babe2b
commit
faa4bed67a
3 changed files with 16 additions and 15 deletions
|
|
@ -148,7 +148,7 @@ func issueList(cmd *cobra.Command, args []string) error {
|
|||
if labels != "" && table.IsTTY() {
|
||||
labels = fmt.Sprintf("(%s)", labels)
|
||||
}
|
||||
table.AddField(issueNum, nil, colorFuncForState(issue.State))
|
||||
table.AddField(issueNum, nil, utils.ColorFuncForState(issue.State))
|
||||
table.AddField(replaceExcessiveWhitespace(issue.Title), nil, nil)
|
||||
table.AddField(labels, nil, utils.Gray)
|
||||
table.EndRow()
|
||||
|
|
|
|||
|
|
@ -232,20 +232,7 @@ func colorFuncForPR(pr api.PullRequest) func(string) string {
|
|||
if pr.State == "OPEN" && pr.IsDraft {
|
||||
return utils.Gray
|
||||
} else {
|
||||
return colorFuncForState(pr.State)
|
||||
}
|
||||
}
|
||||
|
||||
func colorFuncForState(state string) func(string) string {
|
||||
switch state {
|
||||
case "OPEN":
|
||||
return utils.Green
|
||||
case "CLOSED":
|
||||
return utils.Red
|
||||
case "MERGED":
|
||||
return utils.Magenta
|
||||
default:
|
||||
return nil
|
||||
return utils.ColorFuncForState(pr.State)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -57,3 +57,17 @@ func FuzzyAgo(ago time.Duration) string {
|
|||
func Spinner() *spinner.Spinner {
|
||||
return spinner.New(spinner.CharSets[11], 400*time.Millisecond)
|
||||
}
|
||||
|
||||
// ColorFuncForState returns a color function for a PR/Issue state
|
||||
func ColorFuncForState(state string) func(string) string {
|
||||
switch state {
|
||||
case "OPEN":
|
||||
return Green
|
||||
case "CLOSED":
|
||||
return Red
|
||||
case "MERGED":
|
||||
return Magenta
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue