forked from Masterminds/glide
/
semver.go
48 lines (41 loc) · 984 Bytes
/
semver.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
package cmd
import (
"github.com/Masterminds/semver"
"github.com/Masterminds/vcs"
)
// Filter a list of versions to only included semantic versions. The response
// is a mapping of the original version to the semantic version.
func getSemVers(refs []string) []*semver.Version {
sv := []*semver.Version{}
for _, r := range refs {
v, err := semver.NewVersion(r)
if err == nil {
sv = append(sv, v)
}
}
return sv
}
// Get all the references for a repo. This includes the tags and branches.
func getAllVcsRefs(repo vcs.Repo) ([]string, error) {
tags, err := repo.Tags()
if err != nil {
return []string{}, err
}
branches, err := repo.Branches()
if err != nil {
return []string{}, err
}
return append(branches, tags...), nil
}
func isBranch(branch string, repo vcs.Repo) (bool, error) {
branches, err := repo.Branches()
if err != nil {
return false, err
}
for _, b := range branches {
if b == branch {
return true, nil
}
}
return false, nil
}