Skip to content

Commit 8a6d52f

Browse files
authored
Merge pull request #77 from pete0emerson/pete/75/tags_without_semver
Skip tags that are not Semantically Versioned
2 parents 9554201 + 505acf4 commit 8a6d52f

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

github.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"strings"
1313

1414
"github.com/dustin/go-humanize"
15+
"github.com/hashicorp/go-version"
1516
)
1617

1718
type GitHubRepo struct {
@@ -96,7 +97,7 @@ func ParseUrlIntoGithubInstance(repoUrl string, apiv string) (GitHubInstance, *F
9697
return instance, nil
9798
}
9899

99-
// Fetch all tags from the given GitHub repo
100+
// Fetch all SemVer tags from the given GitHub repo
100101
func FetchTags(githubRepoUrl string, githubToken string, instance GitHubInstance) ([]string, *FetchError) {
101102
var tagsString []string
102103

@@ -126,7 +127,10 @@ func FetchTags(githubRepoUrl string, githubToken string, instance GitHubInstance
126127
}
127128

128129
for _, tag := range tags {
129-
tagsString = append(tagsString, tag.Name)
130+
// Skip tags that are not semantically versioned so that they don't cause errors. (issue #75)
131+
if _, err := version.NewVersion(tag.Name); err == nil {
132+
tagsString = append(tagsString, tag.Name)
133+
}
130134
}
131135

132136
return tagsString, nil

github_test.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,15 @@ func TestGetListOfReleasesFromGitHubRepo(t *testing.T) {
1818
repoUrl string
1919
firstReleaseTag string
2020
lastReleaseTag string
21+
expectedNumTags int
2122
gitHubOAuthToken string
2223
testInst GitHubInstance
2324
}{
2425
// Test on a public repo whose sole purpose is to be a test fixture for this tool
25-
{"https://github.com/gruntwork-io/fetch-test-public", "v0.0.1", "v0.0.3", "", testInst},
26+
{"https://github.com/gruntwork-io/fetch-test-public", "v0.0.1", "v0.0.3", 3, "", testInst},
2627

2728
// Private repo equivalent
28-
{"https://github.com/gruntwork-io/fetch-test-private", "v0.0.2", "v0.0.2", os.Getenv("GITHUB_OAUTH_TOKEN"), testInst},
29+
{"https://github.com/gruntwork-io/fetch-test-private", "v0.0.2", "v0.0.2", 1, os.Getenv("GITHUB_OAUTH_TOKEN"), testInst},
2930
}
3031

3132
for _, tc := range cases {
@@ -42,6 +43,10 @@ func TestGetListOfReleasesFromGitHubRepo(t *testing.T) {
4243
t.Fatalf("expected non-empty list of releases for repo %s, but no releases were found", tc.repoUrl)
4344
}
4445

46+
if len(releases) != tc.expectedNumTags {
47+
t.Fatalf("expected %d releases, but got %d", tc.expectedNumTags, len(releases))
48+
}
49+
4550
if releases[len(releases)-1] != tc.firstReleaseTag {
4651
t.Fatalf("error parsing github releases for repo %s. expected first release = %s, actual = %s", tc.repoUrl, tc.firstReleaseTag, releases[len(releases)-1])
4752
}

0 commit comments

Comments
 (0)