diff --git a/lib/modules/manager/terragrunt/extract.spec.ts b/lib/modules/manager/terragrunt/extract.spec.ts index bf997f14654a50..90eaca7caf16e5 100644 --- a/lib/modules/manager/terragrunt/extract.spec.ts +++ b/lib/modules/manager/terragrunt/extract.spec.ts @@ -66,7 +66,13 @@ describe('modules/manager/terragrunt/extract', () => { depType: 'github', packageName: 'hashicorp/example', }, - {}, + { + currentValue: 'next', + datasource: 'git-tags', + depName: '104.196.242.174/example', + depType: 'gitTags', + packageName: 'https://104.196.242.174/example', + }, {}, { datasource: 'terraform-module', @@ -205,21 +211,24 @@ describe('modules/manager/terragrunt/extract', () => { datasource: 'bitbucket-tags', depName: 'bitbucket.com/hashicorp/example', depType: 'gitTags', - packageName: 'https://bitbucket.com/hashicorp/example', + packageName: 'hashicorp/example', + registryUrls: ['https://bitbucket.com'], }, { currentValue: 'v1.0.0', datasource: 'gitlab-tags', depName: 'gitlab.com/hashicorp/example', depType: 'gitTags', - packageName: 'https://gitlab.com/hashicorp/example', + packageName: 'hashicorp/example', + registryUrls: ['https://gitlab.com'], }, { currentValue: 'v1.0.0', datasource: 'gitea-tags', depName: 'gitea.com/hashicorp/example', depType: 'gitTags', - packageName: 'https://gitea.com/hashicorp/example', + packageName: 'hashicorp/example', + registryUrls: ['https://gitea.com'], }, ], }); @@ -252,7 +261,13 @@ describe('modules/manager/terragrunt/extract', () => { depType: 'github', packageName: 'hashicorp/example', }, - {}, + { + currentValue: 'next', + datasource: 'git-tags', + depName: '104.196.242.174/example', + depType: 'gitTags', + packageName: 'https://104.196.242.174/example', + }, {}, { datasource: 'terraform-module', @@ -391,21 +406,24 @@ describe('modules/manager/terragrunt/extract', () => { datasource: 'bitbucket-tags', depName: 'bitbucket.com/hashicorp/example', depType: 'gitTags', - packageName: 'https://bitbucket.com/hashicorp/example', + packageName: 'hashicorp/example', + registryUrls: ['https://bitbucket.com'], }, { currentValue: 'v1.0.0', datasource: 'gitlab-tags', depName: 'gitlab.com/hashicorp/example', depType: 'gitTags', - packageName: 'https://gitlab.com/hashicorp/example', + packageName: 'hashicorp/example', + registryUrls: ['https://gitlab.com'], }, { currentValue: 'v1.0.0', datasource: 'gitea-tags', depName: 'gitea.com/hashicorp/example', depType: 'gitTags', - packageName: 'https://gitea.com/hashicorp/example', + packageName: 'hashicorp/example', + registryUrls: ['https://gitea.com'], }, ], }); @@ -438,7 +456,13 @@ describe('modules/manager/terragrunt/extract', () => { depType: 'github', packageName: 'hashicorp/example', }, - {}, + { + currentValue: 'next', + datasource: 'git-tags', + depName: '104.196.242.174/example', + depType: 'gitTags', + packageName: 'https://104.196.242.174/example', + }, {}, { datasource: 'terraform-module', @@ -577,21 +601,24 @@ describe('modules/manager/terragrunt/extract', () => { datasource: 'bitbucket-tags', depName: 'bitbucket.com/hashicorp/example', depType: 'gitTags', - packageName: 'https://bitbucket.com/hashicorp/example', + packageName: 'hashicorp/example', + registryUrls: ['https://bitbucket.com'], }, { currentValue: 'v1.0.0', datasource: 'gitlab-tags', depName: 'gitlab.com/hashicorp/example', depType: 'gitTags', - packageName: 'https://gitlab.com/hashicorp/example', + packageName: 'hashicorp/example', + registryUrls: ['https://gitlab.com'], }, { currentValue: 'v1.0.0', datasource: 'gitea-tags', depName: 'gitea.com/hashicorp/example', depType: 'gitTags', - packageName: 'https://gitea.com/hashicorp/example', + packageName: 'hashicorp/example', + registryUrls: ['https://gitea.com'], }, ], }); diff --git a/lib/modules/manager/terragrunt/modules.spec.ts b/lib/modules/manager/terragrunt/modules.spec.ts index b2b30361860704..40d9b806c9f03d 100644 --- a/lib/modules/manager/terragrunt/modules.spec.ts +++ b/lib/modules/manager/terragrunt/modules.spec.ts @@ -24,7 +24,7 @@ describe('modules/manager/terragrunt/modules', () => { }); describe('gitTagsRefMatchRegex', () => { - it('should split project and tag from source', () => { + it('should split host, path and tag from source', () => { const http = gitTagsRefMatchRegex.exec( 'http://github.com/hashicorp/example?ref=v1.0.0', )?.groups; @@ -36,15 +36,18 @@ describe('modules/manager/terragrunt/modules', () => { )?.groups; expect(http).toMatchObject({ - project: 'hashicorp/example', + host: 'github.com', + path: 'hashicorp/example', tag: 'v1.0.0', }); expect(https).toMatchObject({ - project: 'hashicorp/example', + host: 'github.com', + path: 'hashicorp/example', tag: 'v1.0.0', }); expect(ssh).toMatchObject({ - project: 'hashicorp/example', + host: 'github.com', + path: 'hashicorp/example', tag: 'v1.0.0', }); }); @@ -61,15 +64,15 @@ describe('modules/manager/terragrunt/modules', () => { )?.groups; expect(http).toMatchObject({ - project: 'hashicorp/example.repo-123', + path: 'hashicorp/example.repo-123', tag: 'v1.0.0', }); expect(https).toMatchObject({ - project: 'hashicorp/example.repo-123', + path: 'hashicorp/example.repo-123', tag: 'v1.0.0', }); expect(ssh).toMatchObject({ - project: 'hashicorp/example.repo-123', + path: 'hashicorp/example.repo-123', tag: 'v1.0.0', }); }); diff --git a/lib/modules/manager/terragrunt/modules.ts b/lib/modules/manager/terragrunt/modules.ts index f881a78a95ca90..c214abb4570825 100644 --- a/lib/modules/manager/terragrunt/modules.ts +++ b/lib/modules/manager/terragrunt/modules.ts @@ -15,7 +15,7 @@ export const githubRefMatchRegex = regEx( /github\.com([/:])(?[^/]+\/[a-z0-9-_.]+).*\?(depth=\d+&)?ref=(?.*?)(&depth=\d+)?$/i, ); export const gitTagsRefMatchRegex = regEx( - /(?:git::)?(?(?:http|https|ssh):\/\/(?:.*@)?(?.*.*\/(?.*\/.*)))\?(depth=\d+&)?ref=(?.*?)(&depth=\d+)?$/, + /(?:git::)?(?(?:http|https|ssh):\/\/(?:.*@)?(?[^/]*)\/(?.*))\?(depth=\d+&)?ref=(?.*?)(&depth=\d+)?$/, ); export const tfrVersionMatchRegex = regEx( /tfr:\/\/(?.*?)\/(?[^/]+?)\/(?[^/]+?)\/(?[^/?]+).*\?(?:ref|version)=(?.*?)$/, @@ -68,18 +68,28 @@ export function analyseTerragruntModule( dep.currentValue = githubRefMatch.groups.tag; dep.datasource = GithubTagsDatasource.id; } else if (gitTagsRefMatch?.groups) { - dep.depType = 'gitTags'; - if (gitTagsRefMatch.groups.path.includes('//')) { + const { url, host, path, tag } = gitTagsRefMatch.groups; + const containsSubDirectory = path.includes('//'); + if (containsSubDirectory) { logger.debug('Terragrunt module contains subdirectory'); - dep.depName = gitTagsRefMatch.groups.path.split('//')[0]; - const tempLookupName = gitTagsRefMatch.groups.url.split('//'); - dep.packageName = tempLookupName[0] + '//' + tempLookupName[1]; + } + dep.depType = 'gitTags'; + // We don't want to have .git or subdirectory in the depName + dep.depName = `${host}/${path.split('//')[0].replace('.git', '')}`; + dep.currentValue = tag; + dep.datasource = detectGitTagDatasource(url); + if (dep.datasource === GitTagsDatasource.id) { + if (containsSubDirectory) { + const [protocol, hostAndPath] = url.split('//'); + dep.packageName = `${protocol}//${hostAndPath}`; + } else { + dep.packageName = url; + } } else { - dep.depName = gitTagsRefMatch.groups.path.replace('.git', ''); - dep.packageName = gitTagsRefMatch.groups.url; + // The packageName should only contain the path to the repository + dep.packageName = path.split('//')[0]; + dep.registryUrls = [`https://${host}`]; } - dep.currentValue = gitTagsRefMatch.groups.tag; - dep.datasource = detectGitTagDatasource(gitTagsRefMatch.groups.url); } else if (tfrVersionMatch?.groups) { dep.depType = 'terragrunt'; dep.depName =