From 0688e23983498768cfcfe437bf9f51054f29ec41 Mon Sep 17 00:00:00 2001 From: lstoeferle <48953604+lstoeferle@users.noreply.github.com> Date: Mon, 29 Apr 2024 18:17:41 +0200 Subject: [PATCH] fix(terragrunt): package name regex order (#28739) --- lib/modules/manager/terragrunt/__fixtures__/2.hcl | 2 +- lib/modules/manager/terragrunt/__fixtures__/3.hcl | 2 +- lib/modules/manager/terragrunt/__fixtures__/4.hcl | 2 +- lib/modules/manager/terragrunt/modules.ts | 13 +++++++------ 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/lib/modules/manager/terragrunt/__fixtures__/2.hcl b/lib/modules/manager/terragrunt/__fixtures__/2.hcl index ac753da5b3a8ac..523dd78b898881 100644 --- a/lib/modules/manager/terragrunt/__fixtures__/2.hcl +++ b/lib/modules/manager/terragrunt/__fixtures__/2.hcl @@ -182,7 +182,7 @@ terraform { # gitlab-tags ssh with custom port terraform { - source = "git::ssh://gitlab.com:1234/hashicorp/example.git?ref=v1.0.2" + source = "git::ssh://gitlab.com:1234/hashicorp/example.git//foo/bar?ref=v1.0.2" } # gitea-tags diff --git a/lib/modules/manager/terragrunt/__fixtures__/3.hcl b/lib/modules/manager/terragrunt/__fixtures__/3.hcl index b33f8d4fedfc02..24e81c345cfc7b 100644 --- a/lib/modules/manager/terragrunt/__fixtures__/3.hcl +++ b/lib/modules/manager/terragrunt/__fixtures__/3.hcl @@ -182,7 +182,7 @@ terraform { # gitlab-tags ssh with custom port terraform { - source = "git::ssh://gitlab.com:1234/hashicorp/example.git?ref=v1.0.2" + source = "git::ssh://gitlab.com:1234/hashicorp/example.git//foo/bar?ref=v1.0.2" } # gitea-tags diff --git a/lib/modules/manager/terragrunt/__fixtures__/4.hcl b/lib/modules/manager/terragrunt/__fixtures__/4.hcl index 42a0a46e47944d..8ac54753fe0d21 100644 --- a/lib/modules/manager/terragrunt/__fixtures__/4.hcl +++ b/lib/modules/manager/terragrunt/__fixtures__/4.hcl @@ -183,7 +183,7 @@ terraform { # gitlab-tags ssh with custom port terraform { - source = "git::ssh://gitlab.com:1234/hashicorp/example.git?ref=v1.0.2" + source = "git::ssh://gitlab.com:1234/hashicorp/example.git//foo/bar?ref=v1.0.2" } # gitea-tags diff --git a/lib/modules/manager/terragrunt/modules.ts b/lib/modules/manager/terragrunt/modules.ts index 665966c0295689..9d71e1e8aa6483 100644 --- a/lib/modules/manager/terragrunt/modules.ts +++ b/lib/modules/manager/terragrunt/modules.ts @@ -75,8 +75,12 @@ export function analyseTerragruntModule( logger.debug('Terragrunt module contains subdirectory'); } dep.depType = 'gitTags'; - // We don't want to have .git or subdirectory in the depName - dep.depName = `${hostname}${pathname.split('//')[0].replace(regEx('.git$'), '')}`; + // We don't want to have leading slash, .git or subdirectory in the repository path + const repositoryPath = pathname + .replace(regEx(/^\//), '') + .split('//')[0] + .replace(regEx('.git$'), ''); + dep.depName = `${hostname}/${repositoryPath}`; dep.currentValue = tag; dep.datasource = detectGitTagDatasource(url); if (dep.datasource === GitTagsDatasource.id) { @@ -87,10 +91,7 @@ export function analyseTerragruntModule( } } else { // The packageName should only contain the path to the repository - dep.packageName = pathname - .replace(regEx(/^\//), '') - .replace(regEx('.git$'), '') - .split('//')[0]; + dep.packageName = repositoryPath; dep.registryUrls = [ protocol === 'https:' ? `https://${host}` : `https://${hostname}`, ];