Skip to content

Commit

Permalink
Fix GitHub collector to accept explicit tag in urls (#1818)
Browse files Browse the repository at this point in the history
Signed-off-by: Eszter Szucs-Matyas <eszter.szucs.matyas@gmail.com>
  • Loading branch information
huggingpixels committed Apr 8, 2024
1 parent 2180123 commit 71c5547
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
2 changes: 1 addition & 1 deletion pkg/handler/collector/github/github.go
Expand Up @@ -383,7 +383,7 @@ func ParseGithubReleaseDataSource(source datasource.Source) (*client.Repo, TagOr
if len(path) < 3 || len(path) > 5 {
return nil, "", fmt.Errorf("invalid github url path: %v invalid number of subpaths: %v", u.Path, len(path))
}
if path[2] != "releases" || (len(path) == 5 && path[3] != "tags") {
if path[2] != "releases" || (len(path) == 5 && path[3] != "tag") {
return nil, "", fmt.Errorf("invalid github path: %v", u.Path)
}
var tol TagOrLatest
Expand Down
25 changes: 20 additions & 5 deletions pkg/handler/collector/github/github_test.go
Expand Up @@ -37,11 +37,12 @@ type MockGithubClient struct {
}

const (
mockTag = "mockTag"
mockCommit = "mockCommit"
mockReleaseUrlLatest = "https://github.com/mock/repo/releases"
mockReleaseUrlWithTag = "https://github.com/mock/repo/releases/v1"
mockAssetUrl = "https://github.com/mock/repo/releases/releaseAsset.json"
mockTag = "mockTag"
mockCommit = "mockCommit"
mockReleaseUrlLatest = "https://github.com/mock/repo/releases"
mockReleaseUrlWithTag = "https://github.com/mock/repo/releases/v1"
mockReleaseUrlWithTagFullPath = "https://github.com/mock/repo/releases/tag/v1"
mockAssetUrl = "https://github.com/mock/repo/releases/releaseAsset.json"
)

func mockReleaseAsset() client.ReleaseAsset {
Expand Down Expand Up @@ -589,6 +590,20 @@ func TestParseGithubReleaseDataSource(t *testing.T) {
want1: "v1",
wantErr: false,
},
{
name: "parse valid tag github url with full path",
args: args{
source: datasource.Source{
Value: mockReleaseUrlWithTagFullPath,
},
},
want: &client.Repo{
Owner: "mock",
Repo: "repo",
},
want1: "v1",
wantErr: false,
},
{
name: "non-https github url",
args: args{
Expand Down

0 comments on commit 71c5547

Please sign in to comment.