summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/mcuadros/go-version/stability.go
blob: 566f7d9074579d2aa7a0a8b915b541833142bdb4 (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
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package version

import (
	"regexp"
	"strings"
)

const (
	Development = iota
	Alpha
	Beta
	RC
	Stable
)

func expandStability(stability string) string {
	stability = strings.ToLower(stability)

	switch stability {
	case "a":
		return "alpha"
	case "b":
		return "beta"
	case "p":
		return "patch"
	case "pl":
		return "patch"
	case "rc":
		return "RC"
	}

	return stability
}

func parseStability(version string) string {
	version = regexp.MustCompile(`(?i)#.+$`).ReplaceAllString(version, " ")
	version = strings.ToLower(version)

	if strings.HasPrefix(version, "dev-") || strings.HasSuffix(version, "-dev") {
		return "dev"
	}

	result := RegFind(`(?i)^v?(\d{1,3})(\.\d+)?(\.\d+)?(\.\d+)?`+modifierRegex+`$`, version)
	if result != nil {
		if len(result) > 3 {
			return "dev"
		}
	}

	if result[1] != "" {
		if "beta" == result[1] || "b" == result[1] {
			return "beta"
		}
		if "alpha" == result[1] || "a" == result[1] {
			return "alpha"
		}
		if "rc" == result[1] {
			return "RC"
		}
	}

	return "stable"
}

func GetStability(version string) int {
	result := RegFind(`(?i)(stable|RC|beta|alpha|dev)`, Normalize(version))
	if len(result) == 0 {
		return Stable
	}

	switch result[1] {
	case "dev":
		return Development
	case "alpha":
		return Alpha
	case "beta":
		return Beta
	case "RC":
		return RC
	}

	return Stable
}