Skip to content

Commit

Permalink
feat: added self-hosted gitlab to catalog command (#3867)
Browse files Browse the repository at this point in the history
Co-authored-by: Joshua Ward <[email protected]>
  • Loading branch information
j2udev and Joshua Ward authored Feb 14, 2025
1 parent ea30d8e commit b782646
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
6 changes: 6 additions & 0 deletions cli/commands/catalog/module/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const (
gitlabHost = "gitlab.com"
azuredevHost = "dev.azure.com"
bitbucketHost = "bitbucket.org"
gitlabSelfHostedRegex = `^(gitlab\.(.+))$`
)

var (
Expand Down Expand Up @@ -125,6 +126,7 @@ func (repo *Repo) FindModules(ctx context.Context) (Modules, error) {
}

var githubEnterprisePatternReg = regexp.MustCompile(githubEnterpriseRegex)
var gitlabSelfHostedPatternReg = regexp.MustCompile(gitlabSelfHostedRegex)

// ModuleURL returns the URL of the module in this repository. `moduleDir` is the path from the repository root.
func (repo *Repo) ModuleURL(moduleDir string) (string, error) {
Expand Down Expand Up @@ -154,6 +156,10 @@ func (repo *Repo) ModuleURL(moduleDir string) (string, error) {
return fmt.Sprintf("https://%s/%s/tree/%s/%s", remote.Host, remote.FullName, repo.BranchName, moduleDir), nil
}

if gitlabSelfHostedPatternReg.MatchString(string(remote.Host)) {
return fmt.Sprintf("https://%s/%s/-/tree/%s/%s", remote.Host, remote.FullName, repo.BranchName, moduleDir), nil
}

return "", errors.Errorf("hosting: %q is not supported yet", remote.Host)
}

Expand Down
7 changes: 7 additions & 0 deletions cli/commands/catalog/module/repo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,13 @@ func TestModuleURL(t *testing.T) {
"https://gitlab.com/acme/terraform-aws-modules/-/tree/main/.",
nil,
},
{
"gitlab self-hosted",
newRepo(t, "https://gitlab.acme.com/acme/terraform-aws-modules"),
".",
"https://gitlab.acme.com/acme/terraform-aws-modules/-/tree/main/.",
nil,
},
{
"bitbucket",
newRepo(t, "https://bitbucket.org/acme/terraform-aws-modules"),
Expand Down

0 comments on commit b782646

Please sign in to comment.