diff --git a/lib/modules/manager/terraform/extractors/others/modules.spec.ts b/lib/modules/manager/terraform/extractors/others/modules.spec.ts index 88c204c1b46826a3e03ff2640d563aff37e3ebb1..eb2ff9844bc401ed977f777bd36b26262a95e959 100644 --- a/lib/modules/manager/terraform/extractors/others/modules.spec.ts +++ b/lib/modules/manager/terraform/extractors/others/modules.spec.ts @@ -19,10 +19,24 @@ describe('modules/manager/terraform/extractors/others/modules', () => { const groups = githubRefMatchRegex.exec( 'github.com/hashicorp/example?ref=v1.0.0' )?.groups; + const depth = githubRefMatchRegex.exec( + 'github.com/hashicorp/example?depth=1&ref=v1.0.0' + )?.groups; + const depth2 = githubRefMatchRegex.exec( + 'github.com/hashicorp/example?ref=v1.0.0&depth=1' + )?.groups; expect(groups).toEqual({ project: 'hashicorp/example', tag: 'v1.0.0', }); + expect(depth).toEqual({ + project: 'hashicorp/example', + tag: 'v1.0.0', + }); + expect(depth2).toEqual({ + project: 'hashicorp/example', + tag: 'v1.0.0', + }); }); it('should parse alpha-numeric characters as well as dots, underscores, and dashes in repo names', () => { @@ -47,6 +61,15 @@ describe('modules/manager/terraform/extractors/others/modules', () => { const ssh = gitTagsRefMatchRegex.exec( 'ssh://github.com/hashicorp/example?ref=v1.0.0' )?.groups; + const depth = gitTagsRefMatchRegex.exec( + 'ssh://github.com/hashicorp/example?depth=1&ref=v1.0.0' + )?.groups; + const depth2 = gitTagsRefMatchRegex.exec( + 'ssh://github.com/hashicorp/example?ref=v1.0.0&depth=1' + )?.groups; + const folder = gitTagsRefMatchRegex.exec( + 'git::ssh://git@git.example.com/modules/foo-module.git//bar?depth=1&ref=v1.0.0' + )?.groups; expect(http).toMatchObject({ project: 'hashicorp/example', @@ -60,6 +83,18 @@ describe('modules/manager/terraform/extractors/others/modules', () => { project: 'hashicorp/example', tag: 'v1.0.0', }); + expect(depth).toMatchObject({ + project: 'hashicorp/example', + tag: 'v1.0.0', + }); + expect(depth2).toMatchObject({ + project: 'hashicorp/example', + tag: 'v1.0.0', + }); + expect(folder).toMatchObject({ + project: '/bar', + tag: 'v1.0.0', + }); }); it('should parse alpha-numeric characters as well as dots, underscores, and dashes in repo names', () => { @@ -113,6 +148,12 @@ describe('modules/manager/terraform/extractors/others/modules', () => { const subfolderWithDoubleSlash = bitbucketRefMatchRegex.exec( 'bitbucket.org/hashicorp/example.git//terraform?ref=v1.0.0' )?.groups; + const depth = bitbucketRefMatchRegex.exec( + 'git::https://git@bitbucket.org/hashicorp/example.git?depth=1&ref=v1.0.0' + )?.groups; + const depth2 = bitbucketRefMatchRegex.exec( + 'git::https://git@bitbucket.org/hashicorp/example.git?ref=v1.0.0&depth=1' + )?.groups; expect(ssh).toMatchObject({ workspace: 'hashicorp', @@ -139,6 +180,16 @@ describe('modules/manager/terraform/extractors/others/modules', () => { project: 'example', tag: 'v1.0.0', }); + expect(depth).toMatchObject({ + workspace: 'hashicorp', + project: 'example', + tag: 'v1.0.0', + }); + expect(depth2).toMatchObject({ + workspace: 'hashicorp', + project: 'example', + tag: 'v1.0.0', + }); }); it('should parse alpha-numeric characters as well as dots, underscores, and dashes in repo names', () => { @@ -200,6 +251,32 @@ describe('modules/manager/terraform/extractors/others/modules', () => { }); }); + it('should split organization, project, repository and tag from source url with depth argument', () => { + const depth = azureDevOpsSshRefMatchRegex.exec( + 'git::git@ssh.dev.azure.com:v3/MyOrg/MyProject/MyRepository//some-module/path?depth=1&ref=1.0.0' + )?.groups; + const depth2 = azureDevOpsSshRefMatchRegex.exec( + 'git::git@ssh.dev.azure.com:v3/MyOrg/MyProject/MyRepository//some-module/path?ref=1.0.0&depth=1' + )?.groups; + + expect(depth).toEqual({ + modulepath: '//some-module/path', + organization: 'MyOrg', + project: 'MyProject', + repository: 'MyRepository', + tag: '1.0.0', + url: 'git@ssh.dev.azure.com:v3/MyOrg/MyProject/MyRepository', + }); + expect(depth2).toEqual({ + modulepath: '//some-module/path', + organization: 'MyOrg', + project: 'MyProject', + repository: 'MyRepository', + tag: '1.0.0', + url: 'git@ssh.dev.azure.com:v3/MyOrg/MyProject/MyRepository', + }); + }); + it('should parse alpha-numeric characters as well as dots, underscores, and dashes in repo names', () => { const dots = azureDevOpsSshRefMatchRegex.exec( 'git::git@ssh.dev.azure.com:v3/MyOrg/MyProject/MyRepository//some-module/path?ref=v1.0.0' diff --git a/lib/modules/manager/terraform/extractors/others/modules.ts b/lib/modules/manager/terraform/extractors/others/modules.ts index 3eba9cc81aa02c4bea6d2b5d1108f5cec814807f..2c135d995d55f3569ce558b857d90b0c94472187 100644 --- a/lib/modules/manager/terraform/extractors/others/modules.ts +++ b/lib/modules/manager/terraform/extractors/others/modules.ts @@ -10,16 +10,16 @@ import { DependencyExtractor } from '../../base'; import type { TerraformDefinitionFile } from '../../hcl/types'; export const githubRefMatchRegex = regEx( - /github\.com([/:])(?<project>[^/]+\/[a-z0-9-_.]+).*\?ref=(?<tag>.*)$/i + /github\.com([/:])(?<project>[^/]+\/[a-z0-9-_.]+).*\?(depth=\d+&)?ref=(?<tag>.*?)(&depth=\d+)?$/i ); export const bitbucketRefMatchRegex = regEx( - /(?:git::)?(?<url>(?:http|https|ssh)?(?::\/\/)?(?:.*@)?(?<path>bitbucket\.org\/(?<workspace>.*)\/(?<project>.*).git\/?(?<subfolder>.*)))\?ref=(?<tag>.*)$/ + /(?:git::)?(?<url>(?:http|https|ssh)?(?::\/\/)?(?:.*@)?(?<path>bitbucket\.org\/(?<workspace>.*)\/(?<project>.*).git\/?(?<subfolder>.*)))\?(depth=\d+&)?ref=(?<tag>.*?)(&depth=\d+)?$/ ); export const gitTagsRefMatchRegex = regEx( - /(?:git::)?(?<url>(?:(?:http|https|ssh):\/\/)?(?:.*@)?(?<path>.*\/(?<project>.*\/.*)))\?ref=(?<tag>.*)$/ + /(?:git::)?(?<url>(?:(?:http|https|ssh):\/\/)?(?:.*@)?(?<path>.*\/(?<project>.*\/.*)))\?(depth=\d+&)?ref=(?<tag>.*?)(&depth=\d+)?$/ ); export const azureDevOpsSshRefMatchRegex = regEx( - /(?:git::)?(?<url>git@ssh\.dev\.azure\.com:v3\/(?<organization>[^/]*)\/(?<project>[^/]*)\/(?<repository>[^/]*))(?<modulepath>.*)?\?ref=(?<tag>.*)$/ + /(?:git::)?(?<url>git@ssh\.dev\.azure\.com:v3\/(?<organization>[^/]*)\/(?<project>[^/]*)\/(?<repository>[^/]*))(?<modulepath>.*)?\?(depth=\d+&)?ref=(?<tag>.*?)(&depth=\d+)?$/ ); const hostnameMatchRegex = regEx(/^(?<hostname>([\w|\d]+\.)+[\w|\d]+)/);