Skip to content

Commit

Permalink
feat: add regex to support gitlab. gitlab-
Browse files Browse the repository at this point in the history
  • Loading branch information
ts-mini committed Jan 31, 2025
1 parent 4dab0b7 commit 63b6f1f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
4 changes: 4 additions & 0 deletions internal/controller/phases_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,10 @@ func TestRepositoryFactory(t *testing.T) {
name: "gitlab repo",
fetchURL: "https://gitlab.example.org/api/v4/projects/group%2Fproject/packages/generic/cluster-api-proviver-aws/v1.4.1/path",
},
{
name: "gitlab hyphenated repo",
fetchURL: "https://gitlab-test.example.org/api/v4/projects/group%2Fproject/packages/generic/cluster-api-proviver-aws/v1.4.1/path",
},
{
name: "unsupported url",
fetchURL: "https://unsupported.xyz/kubernetes-sigs/cluster-api-provider-aws/releases/v1.4.1/infrastructure-components.yaml",
Expand Down
8 changes: 5 additions & 3 deletions util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"context"
"fmt"
"net/url"
"regexp"
"strings"

operatorv1 "sigs.k8s.io/cluster-api-operator/api/v1alpha2"
Expand All @@ -33,7 +34,7 @@ import (
const (
httpsScheme = "https"
githubDomain = "github.com"
gitlabHostPrefix = "gitlab."
gitlabHostPrefix = "gitlab"
gitlabPackagesAPIPrefix = "/api/v4/projects/"
)

Expand Down Expand Up @@ -128,8 +129,9 @@ func RepositoryFactory(ctx context.Context, providerConfig configclient.Provider
return repo, err
}

// if the url is a GitLab repository
if strings.HasPrefix(rURL.Host, gitlabHostPrefix) && strings.HasPrefix(rURL.Path, gitlabPackagesAPIPrefix) {
// if the url is a GitLab repository starting with gitlab- or gitlab.
gitlabHostRegex := regexp.MustCompile(`^` + regexp.QuoteMeta(gitlabHostPrefix) + `(-.*)?\.`) // ^gitlab(-.*)?\. to match gitlab- or gitlab.
if gitlabHostRegex.MatchString(rURL.Host) && strings.HasPrefix(rURL.Path, gitlabPackagesAPIPrefix) {
repo, err := repository.NewGitLabRepository(providerConfig, configVariablesClient)
if err != nil {
return nil, fmt.Errorf("error creating the GitLab repository client: %w", err)
Expand Down

0 comments on commit 63b6f1f

Please sign in to comment.