-
Notifications
You must be signed in to change notification settings - Fork 45
/
bumper.go
66 lines (57 loc) · 1.31 KB
/
bumper.go
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package autotag
import (
"fmt"
"github.com/hashicorp/go-version"
)
type bumper interface {
bump(*version.Version) (*version.Version, error)
}
type major struct{}
type minor struct{}
type patch struct{}
var (
majorBumper major
minorBumper minor
patchBumper patch
)
func (m major) bump(cv *version.Version) (*version.Version, error) {
segments := cv.Segments()
vString := fmt.Sprintf("%d", segments[0]+1)
for index := range segments {
if index == 0 {
continue
}
if index == 1 || index == 2 {
vString += ".0"
}
}
return version.NewVersion(vString)
}
func (m minor) bump(cv *version.Version) (*version.Version, error) {
segments := cv.Segments()
vString := fmt.Sprintf("%d", segments[0])
if len(segments) >= 2 {
vString += fmt.Sprintf(".%d", segments[1]+1)
}
if len(segments) >= 3 {
for index, value := range segments {
if index > 2 {
vString += fmt.Sprintf(".%d", value)
}
}
}
return version.NewVersion(vString)
}
func (m patch) bump(cv *version.Version) (*version.Version, error) {
segments := cv.Segments()
vString := cv.String()
if len(segments) >= 3 {
vString = fmt.Sprintf("%d.%d.%d", segments[0], segments[1], segments[2]+1)
for index, value := range segments {
if index > 2 {
vString += fmt.Sprintf(".%d", value)
}
}
}
return version.NewVersion(vString)
}