summaryrefslogtreecommitdiffstats
path: root/branch.go
blob: 78c2e55aab2ed31bc47ffc854b1eec25ce99d644 (plain)
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
package main

import (
	"strings"

	"github.com/fatih/color"
)

// Branch : A git branch
type Branch struct {
	Name    string
	Recency string
}

func (b *Branch) getDisplayString() string {
	return withPadding(b.Recency, 4) + coloredString(b.Name, b.getColor())
}

func (b *Branch) getColor() color.Attribute {
	switch b.getType() {
	case "feature":
		return color.FgGreen
	case "bugfix":
		return color.FgYellow
	case "hotfix":
		return color.FgRed
	default:
		return color.FgWhite
	}
}

// expected to return feature/bugfix/hotfix or blank string
func (b *Branch) getType() string {
	return strings.Split(b.Name, "/")[0]
}