Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(terragrunt): package name regex order #28739

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/modules/manager/terragrunt/__fixtures__/2.hcl
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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