-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrelease_yaml.go
65 lines (52 loc) · 1.13 KB
/
release_yaml.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
package main
import (
"errors"
"fmt"
"io/ioutil"
"net/http"
"strings"
ver "github.com/hashicorp/go-version"
yaml "gopkg.in/yaml.v2"
)
type releaseYaml struct {
version *ver.Version
content []byte
}
func newReleaseYaml(v *ver.Version) (*releaseYaml, error) {
y := &releaseYaml{
version: v,
}
nv := y.version.String()
if v.Prerelease() != "" {
nv = strings.Replace(nv, "-", ".", -1)
nv = strings.Replace(nv, "rc.", "rc", -1)
fmt.Println(nv)
}
baseURL := "https://github-enterprise.s3.amazonaws.com"
url := baseURL + "/release/release-" + nv + ".yml"
fmt.Println("Getting " + url)
resp, err := http.Get(url)
if err != nil {
return nil, err
}
if resp.StatusCode != http.StatusOK {
return nil, errors.New("Error: failed to load yaml, " + resp.Status)
}
defer resp.Body.Close()
y.content, err = ioutil.ReadAll(resp.Body)
if err != nil {
return nil, err
}
return y, nil
}
func (y *releaseYaml) getId(r release) (string, error) {
err := yaml.Unmarshal(y.content, r)
if err != nil {
return "", err
}
version := r.getId()
if version == "" {
return "", errors.New("AMI not found")
}
return version, nil
}