forked from grafana/grafana
-
Notifications
You must be signed in to change notification settings - Fork 0
/
externalrelease.go
70 lines (60 loc) · 1.48 KB
/
externalrelease.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
package main
import (
"fmt"
"io/ioutil"
"net/http"
"strings"
"time"
)
type releaseFromExternalContent struct {
getter urlGetter
rawVersion string
artifactConfigurations []buildArtifact
}
func (re releaseFromExternalContent) prepareRelease(baseArchiveURL, whatsNewURL string, releaseNotesURL string, nightly bool) (*release, error) {
version := re.rawVersion[1:]
beta := strings.Contains(version, "beta")
var rt releaseType
if beta {
rt = BETA
} else if nightly {
rt = NIGHTLY
} else {
rt = STABLE
}
builds := []build{}
for _, ba := range re.artifactConfigurations {
sha256, err := re.getter.getContents(fmt.Sprintf("%s.sha256", ba.getURL(baseArchiveURL, version, rt)))
if err != nil {
return nil, err
}
builds = append(builds, newBuild(baseArchiveURL, ba, version, rt, sha256))
}
r := release{
Version: version,
ReleaseDate: time.Now().UTC(),
Stable: rt.stable(),
Beta: rt.beta(),
Nightly: rt.nightly(),
WhatsNewURL: whatsNewURL,
ReleaseNotesURL: releaseNotesURL,
Builds: builds,
}
return &r, nil
}
type urlGetter interface {
getContents(url string) (string, error)
}
type getHTTPContents struct{}
func (getHTTPContents) getContents(url string) (string, error) {
response, err := http.Get(url)
if err != nil {
return "", err
}
defer response.Body.Close()
all, err := ioutil.ReadAll(response.Body)
if err != nil {
return "", err
}
return string(all), nil
}