From aed7c2950989d7bdaf4b72c2a91725e1016632f6 Mon Sep 17 00:00:00 2001 From: Yuki Osaki Date: Sun, 31 Oct 2021 22:40:39 +0900 Subject: [PATCH] move pr color logic to own method --- pkg/gui/presentation/branches.go | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/pkg/gui/presentation/branches.go b/pkg/gui/presentation/branches.go index d3da172f7..6b02fc135 100644 --- a/pkg/gui/presentation/branches.go +++ b/pkg/gui/presentation/branches.go @@ -55,18 +55,7 @@ func getBranchDisplayStrings( res := []string{recencyColor.Sprint(b.Recency), coloredName} if showGithub { pr, hasPr := prs[b] - if hasPr { - colour := style.FgMagenta // = state MERGED - switch pr.State { - case "OPEN": - colour = style.FgGreen - case "CLOSED": - colour = style.FgRed - } - res = append(res, colour.Sprint("#"+strconv.Itoa(pr.Number))) - } else { - res = append(res, "") - } + res = append(res, coloredPrNumber(pr, hasPr)) } if fullDescription { @@ -105,3 +94,18 @@ func ColoredBranchStatus(branch *models.Branch) string { func BranchStatus(branch *models.Branch) string { return fmt.Sprintf("↑%s↓%s", branch.Pushables, branch.Pullables) } + +func coloredPrNumber(pr *models.GithubPullRequest, hasPr bool) string { + if hasPr { + colour := style.FgMagenta // = state MERGED + switch pr.State { + case "OPEN": + colour = style.FgGreen + case "CLOSED": + colour = style.FgRed + } + return colour.Sprint("#" + strconv.Itoa(pr.Number)) + } + + return "" +}