-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathformat.go
53 lines (44 loc) · 1.11 KB
/
format.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
package main
import (
"regexp"
"strconv"
"strings"
"time"
)
// GetNextVersion gets next version according to the tag of the format.
func GetNextVersion(tag string) (string, error) {
if tag == "" {
return "v1.0.0", nil
}
tags := strings.Split(tag, ".")
len := len(tags)
// semantic version(e.g. v1.2.3)
if len > 2 {
patch, err := strconv.Atoi(tags[len-1])
if err != nil {
return "", err
}
tags[len-1] = strconv.Itoa(patch + 1)
return strings.Join(tags, "."), nil
}
// date version(e.g. 20180525.1 or release_20180525.1)
const layout = "20060102"
today := time.Now().Format(layout)
dateRe := regexp.MustCompile(`(.*)(\d{8})\.(.+)`)
if m := dateRe.FindStringSubmatch(tag); m != nil {
if m[2] == today {
minor, err := strconv.Atoi(m[3])
if err != nil {
return "", err
}
next := strconv.Itoa(minor + 1)
return m[1] + today + "." + next, nil
}
return m[1] + today + "." + "1", nil
}
return today + ".1", nil
}
// GetReleaseNote formats merge-commits list.
func GetReleaseNote(tag string, list string) string {
return "Release " + tag + "\n\n" + "## " + tag + "\n" + list
}