Skip to content

Commit 63b6f1f

Browse files
committed
feat: add regex to support gitlab. gitlab-
1 parent 4dab0b7 commit 63b6f1f

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

internal/controller/phases_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,10 @@ func TestRepositoryFactory(t *testing.T) {
641641
name: "gitlab repo",
642642
fetchURL: "https://gitlab.example.org/api/v4/projects/group%2Fproject/packages/generic/cluster-api-proviver-aws/v1.4.1/path",
643643
},
644+
{
645+
name: "gitlab hyphenated repo",
646+
fetchURL: "https://gitlab-test.example.org/api/v4/projects/group%2Fproject/packages/generic/cluster-api-proviver-aws/v1.4.1/path",
647+
},
644648
{
645649
name: "unsupported url",
646650
fetchURL: "https://unsupported.xyz/kubernetes-sigs/cluster-api-provider-aws/releases/v1.4.1/infrastructure-components.yaml",

util/util.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"context"
2121
"fmt"
2222
"net/url"
23+
"regexp"
2324
"strings"
2425

2526
operatorv1 "sigs.k8s.io/cluster-api-operator/api/v1alpha2"
@@ -33,7 +34,7 @@ import (
3334
const (
3435
httpsScheme = "https"
3536
githubDomain = "github.com"
36-
gitlabHostPrefix = "gitlab."
37+
gitlabHostPrefix = "gitlab"
3738
gitlabPackagesAPIPrefix = "/api/v4/projects/"
3839
)
3940

@@ -128,8 +129,9 @@ func RepositoryFactory(ctx context.Context, providerConfig configclient.Provider
128129
return repo, err
129130
}
130131

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

0 commit comments

Comments
 (0)