Exemplo n.º 1
0
func (s Stemcell) Latest() (string, error) {
	latestVersion := "0"

	if len(s.Versions) == 0 {
		return "", errors.New("no stemcell versions found, cannot get latest")
	}

	for _, version := range s.Versions {

		semVersion, err := semver.ParseTolerant(version)
		if err != nil {
			return "", err
		}

		semLatestVersion, err := semver.ParseTolerant(latestVersion)
		if err != nil {
			// Not tested
			return "", err
		}

		if semVersion.GT(semLatestVersion) {
			latestVersion = version
		}
	}

	return latestVersion, nil
}
Exemplo n.º 2
0
// IsNewer returns true if this release is newer than a given semver string
func (g *GitHubRelease) IsNewer(ver string) (isNewer bool, err error) {
	var version semver.Version
	if version, err = semver.ParseTolerant(ver); err != nil {
		return
	}
	isNewer = g.Version.GT(version)
	return
}
Exemplo n.º 3
0
func getReleases(owner, repo string) (releases []GitHubRelease, err error) {
	var data []byte
	if data, err = get(fmt.Sprintf("https://api.github.com/repos/%s/%s/releases", owner, repo), nil); err != nil {
		return
	}

	if err = json.NewDecoder(bytes.NewReader(data)).Decode(&releases); err != nil {
		return
	}

	for i := range releases {
		releases[i].Version, _ = semver.ParseTolerant(releases[i].Tag)
	}

	sort.Sort(byVersion(releases))

	return
}