move pr color logic to own method

This commit is contained in:
Yuki Osaki 2021-10-31 22:40:39 +09:00
parent 4a1fa4889d
commit aed7c29509

View file

@ -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 ""
}