Skip to content

Commit faa4bed

Browse files
committed
Move colorFuncForState for a PR/issue state to the utils package
1 parent d429bab commit faa4bed

File tree

3 files changed

+16
-15
lines changed

3 files changed

+16
-15
lines changed

command/issue.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ func issueList(cmd *cobra.Command, args []string) error {
148148
if labels != "" && table.IsTTY() {
149149
labels = fmt.Sprintf("(%s)", labels)
150150
}
151-
table.AddField(issueNum, nil, colorFuncForState(issue.State))
151+
table.AddField(issueNum, nil, utils.ColorFuncForState(issue.State))
152152
table.AddField(replaceExcessiveWhitespace(issue.Title), nil, nil)
153153
table.AddField(labels, nil, utils.Gray)
154154
table.EndRow()

command/pr.go

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -232,20 +232,7 @@ func colorFuncForPR(pr api.PullRequest) func(string) string {
232232
if pr.State == "OPEN" && pr.IsDraft {
233233
return utils.Gray
234234
} else {
235-
return colorFuncForState(pr.State)
236-
}
237-
}
238-
239-
func colorFuncForState(state string) func(string) string {
240-
switch state {
241-
case "OPEN":
242-
return utils.Green
243-
case "CLOSED":
244-
return utils.Red
245-
case "MERGED":
246-
return utils.Magenta
247-
default:
248-
return nil
235+
return utils.ColorFuncForState(pr.State)
249236
}
250237
}
251238

utils/utils.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,17 @@ func FuzzyAgo(ago time.Duration) string {
5757
func Spinner() *spinner.Spinner {
5858
return spinner.New(spinner.CharSets[11], 400*time.Millisecond)
5959
}
60+
61+
// ColorFuncForState returns a color function for a PR/Issue state
62+
func ColorFuncForState(state string) func(string) string {
63+
switch state {
64+
case "OPEN":
65+
return Green
66+
case "CLOSED":
67+
return Red
68+
case "MERGED":
69+
return Magenta
70+
default:
71+
return nil
72+
}
73+
}

0 commit comments

Comments
 (0)