forked from redhat-developer/odo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
notify.go
56 lines (44 loc) · 1.5 KB
/
notify.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
package notify
import (
"strings"
"github.com/blang/semver"
"github.com/openshift/odo/pkg/util"
"github.com/pkg/errors"
)
const (
// VersionFetchURL is the URL to fetch latest version number
VersionFetchURL = "https://raw.githubusercontent.com/openshift/odo/master/build/VERSION"
)
// getLatestReleaseTag polls odo's upstream GitHub repository to get the
// tag of the latest release
func getLatestReleaseTag() (string, error) {
request := util.HTTPRequestParams{
URL: VersionFetchURL,
}
// Make request and cache response for 60 minutes
body, err := util.HTTPGetRequest(request, 60)
if err != nil {
return "", errors.Wrap(err, "error getting latest release")
}
return strings.TrimSuffix(string(body), "\n"), nil
}
// CheckLatestReleaseTag returns the latest release tag if a newer latest
// release is available, else returns an empty string
func CheckLatestReleaseTag(currentVersion string) (string, error) {
currentSemver, err := semver.Make(strings.TrimPrefix(currentVersion, "v"))
if err != nil {
return "", errors.Wrapf(err, "unable to make semver from the current version: %v", currentVersion)
}
latestTag, err := getLatestReleaseTag()
if err != nil {
return "", errors.Wrap(err, "unable to get latest release tag")
}
latestSemver, err := semver.Make(strings.TrimPrefix(latestTag, "v"))
if err != nil {
return "", errors.Wrapf(err, "unable to make semver from the latest release tag: %v", latestTag)
}
if currentSemver.LT(latestSemver) {
return latestTag, nil
}
return "", nil
}