diff --git a/pkg/kamelet/repository/github_repository.go b/pkg/kamelet/repository/github_repository.go index 1363a4b88f..2e3fbd8876 100644 --- a/pkg/kamelet/repository/github_repository.go +++ b/pkg/kamelet/repository/github_repository.go @@ -23,6 +23,7 @@ import ( "fmt" "io" "net/http" + neturl "net/url" "os" "sort" "strings" @@ -112,12 +113,20 @@ func (c *githubKameletRepository) listFiles(ctx context.Context) ([]*github.Repo } func (c *githubKameletRepository) downloadKamelet(ctx context.Context, url string) (*v1.Kamelet, error) { + return downloadGithubKamelet(ctx, url, c.httpClient) +} + +func downloadGithubKamelet(ctx context.Context, url string, httpClient *http.Client) (*v1.Kamelet, error) { + parsedURL, err := neturl.Parse(url) + if err != nil { + return nil, err + } req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil) if err != nil { return nil, err } - resp, err := c.httpClient.Do(req) + resp, err := httpClient.Do(req) if err != nil { return nil, err } @@ -131,7 +140,7 @@ func (c *githubKameletRepository) downloadKamelet(ctx context.Context, url strin if err != nil { return nil, err } - if strings.HasSuffix(url, ".yaml") || strings.HasSuffix(url, ".yml") { + if strings.HasSuffix(parsedURL.Path, ".yaml") || strings.HasSuffix(parsedURL.Path, ".yml") { content, err = yaml.ToJSON(content) if err != nil { return nil, err diff --git a/pkg/kamelet/repository/github_repository_test.go b/pkg/kamelet/repository/github_repository_test.go index 60471aa6c4..7b5219a2fd 100644 --- a/pkg/kamelet/repository/github_repository_test.go +++ b/pkg/kamelet/repository/github_repository_test.go @@ -19,6 +19,7 @@ package repository import ( "context" + "net/http" "os" "testing" @@ -50,3 +51,16 @@ func TestGithubRepository(t *testing.T) { } } + +func TestDownloadKamelet(t *testing.T) { + c := &http.Client{} + kamelet, err := downloadGithubKamelet( + context.Background(), + // the appended parameter test the strength of the func which should load the kamelet regardless any + // additional parameter provided + "https://raw.githubusercontent.com/apache/camel-kamelets/main/kamelets/timer-source.kamelet.yaml?test=test", + c, + ) + require.NoError(t, err) + assert.Equal(t, "timer-source", kamelet.Name) +}