forked from Songmu/tagpr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
semver.go
58 lines (49 loc) · 961 Bytes
/
semver.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
package tagpr
import "github.com/Masterminds/semver/v3"
type semv struct {
v *semver.Version
vPrefix bool
}
func newSemver(v string) (*semv, error) {
var err error
sv := &semv{}
sv.v, err = semver.NewVersion(v)
if err != nil {
return nil, err
}
sv.vPrefix = v[0] == 'v'
return sv, nil
}
func (sv *semv) Naked() string {
return sv.v.String()
}
func (sv *semv) Tag() string {
if sv.vPrefix {
return "v" + sv.Naked()
}
return sv.Naked()
}
func (sv *semv) GuessNext(labels []string) *semv {
var isMajor, isMinor bool
for _, l := range labels {
switch l {
case autoLableName + ":major", autoLableName + "/major":
isMajor = true
case autoLableName + ":minor", autoLableName + "/minor":
isMinor = true
}
}
var nextv semver.Version
switch {
case isMajor:
nextv = sv.v.IncMajor()
case isMinor:
nextv = sv.v.IncMinor()
default:
nextv = sv.v.IncPatch()
}
return &semv{
v: &nextv,
vPrefix: sv.vPrefix,
}
}