-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelpers.go
107 lines (93 loc) · 2.32 KB
/
helpers.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package api
import (
"fmt"
"strings"
"cloud.google.com/go/storage"
"github.com/blang/semver"
)
func getVersion(name string) (semver.Version, error) {
matches := RegexSemanticVersion.FindAllStringSubmatch(name, 1)
if matches == nil {
return semver.Version{}, fmt.Errorf(
`failed to retrieve version information from "%s"`, name)
}
version := matches[0][1]
if strings.Count(version, ".") == 1 {
version += ".0"
}
return semver.Make(version)
}
func getFullVersion(name string) (string, error) {
matches := RegexFullVersion.FindAllStringSubmatch(name, 1)
if matches == nil {
return "", fmt.Errorf(
`failed to retrieve full version information from "%s"`, name)
}
return matches[0][1], nil
}
func stripSuffix(name string) string {
if strings.Contains(name, ".tar.gz") {
return strings.TrimRight(name, ".tar.gz")
}
split := strings.Split(name, ".")
return strings.TrimRight(name, "."+split[len(split)-1])
}
func getArchitecture(name string) (string, error) {
switch strings.Count(name, "-") {
case 1, 2:
split := strings.Split(strings.Split(name, "-")[1], ".")
return split[len(split)-1], nil
default:
return "", fmt.Errorf(`failed to retrieve architecture from "%s"`, name)
}
}
func getPlatform(name string) (string, error) {
switch strings.Count(name, "-") {
case 1, 2:
split := strings.Split(strings.Split(name, "-")[0], ".")
return split[len(split)-1], nil
default:
return "", fmt.Errorf(`failed to retrieve platform from "%s"`, name)
}
}
func skip(object *storage.ObjectAttrs) bool {
switch object.ContentType {
case "text/plain", "text/plain; charset=utf-8":
return true
}
if strings.HasPrefix(object.Name, "getgo/") {
return true
}
if strings.HasSuffix(object.Name, ".asc") {
return true
}
if strings.Contains(object.Name, ".src.") {
return true
}
return false
}
func getVersionFromName(name string) (*Version, error) {
platform, err := getPlatform(name)
if err != nil {
return nil, err
}
version, err := getVersion(name)
if err != nil {
return nil, err
}
fullVersion, err := getFullVersion(name)
if err != nil {
return nil, err
}
architecture, err := getArchitecture(name)
if err != nil {
return nil, err
}
return &Version{
Name: name,
Platform: platform,
Version: version,
FullVersion: fullVersion,
Architecture: architecture,
}, nil
}