Skip to content

Commit

Permalink
fix(terragrunt): package name regex order (#28739)
Browse files Browse the repository at this point in the history
  • Loading branch information
lstoeferle committed Apr 29, 2024
1 parent 5558b0d commit 0688e23
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 9 deletions.
2 changes: 1 addition & 1 deletion lib/modules/manager/terragrunt/__fixtures__/2.hcl
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/modules/manager/terragrunt/__fixtures__/3.hcl
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/modules/manager/terragrunt/__fixtures__/4.hcl
Expand Up @@ -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
Expand Down
13 changes: 7 additions & 6 deletions lib/modules/manager/terragrunt/modules.ts
Expand Up @@ -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) {
Expand All @@ -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}`,
];
Expand Down

0 comments on commit 0688e23

Please sign in to comment.