From 39f03b2b6632e0f70448d8c3ab5c9b710127bda7 Mon Sep 17 00:00:00 2001 From: Etienne <etienne.tremel@orange.fr> Date: Sat, 9 May 2020 07:57:55 +0200 Subject: [PATCH] fix(terraform): extract github repository name containing dots (#6154) --- lib/manager/terraform/__fixtures__/1.tf | 8 ++++++++ .../terraform/__snapshots__/extract.spec.ts.snap | 16 ++++++++++++++++ lib/manager/terraform/extract.spec.ts | 2 +- lib/manager/terraform/extract.ts | 9 +++++---- 4 files changed, 30 insertions(+), 5 deletions(-) diff --git a/lib/manager/terraform/__fixtures__/1.tf b/lib/manager/terraform/__fixtures__/1.tf index 9ee1515d28..835c564b38 100644 --- a/lib/manager/terraform/__fixtures__/1.tf +++ b/lib/manager/terraform/__fixtures__/1.tf @@ -6,6 +6,14 @@ module "bar" { source = "github.com/hashicorp/example?ref=next" } +module "repo-with-dot" { + source = "github.com/hashicorp/example.2.3?ref=v1.0.0" +} + +module "repo-with-dot-and-git-suffix" { + source = "github.com/hashicorp/example.2.3.git?ref=v1.0.0" +} + module "consul" { source = "hashicorp/consul/aws" version = "0.1.0" diff --git a/lib/manager/terraform/__snapshots__/extract.spec.ts.snap b/lib/manager/terraform/__snapshots__/extract.spec.ts.snap index d1cdedfa31..3fb1bb2597 100644 --- a/lib/manager/terraform/__snapshots__/extract.spec.ts.snap +++ b/lib/manager/terraform/__snapshots__/extract.spec.ts.snap @@ -20,6 +20,22 @@ Object { "lookupName": "hashicorp/example", "skipReason": "unsupported-version", }, + Object { + "currentValue": "v1.0.0", + "datasource": "github-tags", + "depName": "github.com/hashicorp/example.2.3", + "depNameShort": "hashicorp/example.2.3", + "depType": "github", + "lookupName": "hashicorp/example.2.3", + }, + Object { + "currentValue": "v1.0.0", + "datasource": "github-tags", + "depName": "github.com/hashicorp/example.2.3", + "depNameShort": "hashicorp/example.2.3", + "depType": "github", + "lookupName": "hashicorp/example.2.3", + }, Object { "currentValue": "0.1.0", "datasource": "terraform-module", diff --git a/lib/manager/terraform/extract.spec.ts b/lib/manager/terraform/extract.spec.ts index 5926e15182..c0417b9564 100644 --- a/lib/manager/terraform/extract.spec.ts +++ b/lib/manager/terraform/extract.spec.ts @@ -19,7 +19,7 @@ describe('lib/manager/terraform/extract', () => { it('extracts', () => { const res = extractPackageFile(tf1); expect(res).toMatchSnapshot(); - expect(res.deps).toHaveLength(22); + expect(res.deps).toHaveLength(24); expect(res.deps.filter((dep) => dep.skipReason)).toHaveLength(6); }); it('returns null if only local deps', () => { diff --git a/lib/manager/terraform/extract.ts b/lib/manager/terraform/extract.ts index d1e303a607..507697cc62 100644 --- a/lib/manager/terraform/extract.ts +++ b/lib/manager/terraform/extract.ts @@ -85,7 +85,7 @@ export function extractPackageFile(content: string): PackageFile | null { dep.managerData.terraformDependencyType === TerraformDependencyTypes.module ) { - const githubRefMatch = /github.com(\/|:)([^/]+\/[a-z0-9-]+).*\?ref=(.*)$/.exec( + const githubRefMatch = /github.com(\/|:)([^/]+\/[a-z0-9-.]+).*\?ref=(.*)$/.exec( dep.managerData.source ); // Regex would need to be updated to support ssh:// @@ -94,12 +94,13 @@ export function extractPackageFile(content: string): PackageFile | null { ); /* eslint-disable no-param-reassign */ if (githubRefMatch) { + const depNameShort = githubRefMatch[2].replace(/\.git$/, ''); dep.depType = 'github'; - dep.depName = 'github.com/' + githubRefMatch[2]; - dep.depNameShort = githubRefMatch[2]; + dep.depName = 'github.com/' + depNameShort; + dep.depNameShort = depNameShort; dep.currentValue = githubRefMatch[3]; dep.datasource = datasourceGithubTags.id; - dep.lookupName = githubRefMatch[2]; + dep.lookupName = depNameShort; dep.managerData.lineNumber = dep.managerData.sourceLine; if (!isVersion(dep.currentValue)) { dep.skipReason = SkipReason.UnsupportedVersion; -- GitLab