From b782646d37045a83f15c8762b4f28478a6397a37 Mon Sep 17 00:00:00 2001 From: Joshua Ward Date: Fri, 14 Feb 2025 13:39:43 -0500 Subject: [PATCH] feat: added self-hosted gitlab to catalog command (#3867) Co-authored-by: Joshua Ward --- cli/commands/catalog/module/repo.go | 6 ++++++ cli/commands/catalog/module/repo_test.go | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/cli/commands/catalog/module/repo.go b/cli/commands/catalog/module/repo.go index 109c15cacb..6f3d82d0c3 100644 --- a/cli/commands/catalog/module/repo.go +++ b/cli/commands/catalog/module/repo.go @@ -26,6 +26,7 @@ const ( gitlabHost = "gitlab.com" azuredevHost = "dev.azure.com" bitbucketHost = "bitbucket.org" + gitlabSelfHostedRegex = `^(gitlab\.(.+))$` ) var ( @@ -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) { @@ -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) } diff --git a/cli/commands/catalog/module/repo_test.go b/cli/commands/catalog/module/repo_test.go index 1720ab7999..86ce5cd807 100644 --- a/cli/commands/catalog/module/repo_test.go +++ b/cli/commands/catalog/module/repo_test.go @@ -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"),