From 0a49e6fcfeccad23eacab533e1ad5a01a36f2395 Mon Sep 17 00:00:00 2001 From: Gabriel Melillo Date: Fri, 31 Jan 2020 10:47:06 +0100 Subject: [PATCH] fix(skipreason): make better comunication of the issue --- lib/manager/helmfile/extract.ts | 31 +++++++++---- .../__snapshots__/extract.spec.ts.snap | 46 +++++++++++++++++-- test/manager/helmfile/extract.spec.ts | 44 ++++++++++++++++++ 3 files changed, 108 insertions(+), 13 deletions(-) diff --git a/lib/manager/helmfile/extract.ts b/lib/manager/helmfile/extract.ts index a71e4b01fe352a..08a78de4726b06 100644 --- a/lib/manager/helmfile/extract.ts +++ b/lib/manager/helmfile/extract.ts @@ -3,6 +3,11 @@ import yaml from 'js-yaml'; import { logger } from '../../logger'; import { PackageFile, PackageDependency, ExtractConfig } from '../common'; +import { re } from 'github-url-from-git'; + +const isValidChartName = (name: string): boolean => { + return name.match(/[!@#$%^&*(),.?":{}/|<>A-Z]/) === null; +}; export function extractPackageFile( content: string, @@ -34,6 +39,7 @@ export function extractPackageFile( let depName = dep.chart; let repoName = null; + // If starts with ./ is for sure a local path if (dep.chart.startsWith('./')) { return { depName, @@ -43,8 +49,8 @@ export function extractPackageFile( if (dep.chart.includes('/')) { const v = dep.chart.split('/'); - depName = v[1]; - repoName = v[0]; + repoName = v.shift(); + depName = v.join('/'); } else { repoName = dep.chart; } @@ -57,19 +63,24 @@ export function extractPackageFile( .filter(Boolean), }; - if (res.depName.includes('{') || res.depName.includes('}')) { - res.skipReason = 'invalid-chart'; + // If version is null is probably a local chart + if (!res.currentValue) { + res.skipReason = 'local-chart'; + } + + // By definition on helm the chart name should be lowecase letter + number + - + // However helmfile support templating of that field + if (!isValidChartName(res.depName)) { + res.skipReason = 'unsupported-chart-type'; } + // Skip in case we cannot locate the registry if (is.emptyArray(res.registryUrls)) { - res.skipReason = 'invalid-registry'; + res.skipReason = 'unknown-registry'; } return res; }); - const res = { - deps, - datasource: 'helm', - }; - return res; + + return { deps, datasource: 'helm' } as PackageFile; } diff --git a/test/manager/helmfile/__snapshots__/extract.spec.ts.snap b/test/manager/helmfile/__snapshots__/extract.spec.ts.snap index 5bc93382742aab..5a093a75ea2afb 100644 --- a/test/manager/helmfile/__snapshots__/extract.spec.ts.snap +++ b/test/manager/helmfile/__snapshots__/extract.spec.ts.snap @@ -1,5 +1,45 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`lib/manager/helmfile/extract extractPackageFile() skip chart that does not have specified version 1`] = ` +Object { + "datasource": "helm", + "deps": Array [ + Object { + "currentValue": undefined, + "depName": "example", + "registryUrls": Array [ + "https://kubernetes-charts.storage.googleapis.com/", + ], + "skipReason": "local-chart", + }, + ], +} +`; + +exports[`lib/manager/helmfile/extract extractPackageFile() skip chart with special character in the name 1`] = ` +Object { + "datasource": "helm", + "deps": Array [ + Object { + "currentValue": "1.0.0", + "depName": "example/example", + "registryUrls": Array [ + "https://kiwigrid.github.io", + ], + "skipReason": "unsupported-chart-type", + }, + Object { + "currentValue": "1.0.0", + "depName": "example?example", + "registryUrls": Array [ + "https://kiwigrid.github.io", + ], + "skipReason": "unsupported-chart-type", + }, + ], +} +`; + exports[`lib/manager/helmfile/extract extractPackageFile() skip chart with unknown repository 1`] = ` Object { "datasource": "helm", @@ -8,7 +48,7 @@ Object { "currentValue": "1.0.0", "depName": "example", "registryUrls": Array [], - "skipReason": "invalid-registry", + "skipReason": "unknown-registry", }, ], } @@ -22,7 +62,7 @@ Object { "currentValue": "1.0.0", "depName": "example", "registryUrls": Array [], - "skipReason": "invalid-registry", + "skipReason": "unknown-registry", }, ], } @@ -50,7 +90,7 @@ Object { "registryUrls": Array [ "https://kubernetes-charts.storage.googleapis.com/", ], - "skipReason": "invalid-chart", + "skipReason": "unsupported-chart-type", }, Object { "currentValue": "1.0.0", diff --git a/test/manager/helmfile/extract.spec.ts b/test/manager/helmfile/extract.spec.ts index 4ff5f9ab62e8c9..1360aa8a9f1480 100644 --- a/test/manager/helmfile/extract.spec.ts +++ b/test/manager/helmfile/extract.spec.ts @@ -123,5 +123,49 @@ describe('lib/manager/helmfile/extract', () => { expect(result).toMatchSnapshot(); expect(result.deps.every(dep => dep.skipReason)); }); + + it('skip chart with special character in the name', async () => { + const content = ` + repositories: + - name: kiwigrid + url: https://kiwigrid.github.io + releases: + - name: example + version: 1.0.0 + chart: kiwigrid/example/example + - name: example2 + version: 1.0.0 + chart: kiwigrid/example?example + `; + const fileName = 'helmfile.yaml'; + const result = await extractPackageFile(content, fileName, { + aliases: { + stable: 'https://kubernetes-charts.storage.googleapis.com/', + }, + }); + expect(result).not.toBeNull(); + expect(result).toMatchSnapshot(); + expect(result.deps.every(dep => dep.skipReason)); + }); + + it('skip chart that does not have specified version', async () => { + const content = ` + repositories: + - name: kiwigrid + url: https://kiwigrid.github.io + releases: + - name: example + chart: stable/example + `; + const fileName = 'helmfile.yaml'; + const result = await extractPackageFile(content, fileName, { + aliases: { + stable: 'https://kubernetes-charts.storage.googleapis.com/', + }, + }); + expect(result).not.toBeNull(); + expect(result).toMatchSnapshot(); + expect(result.deps.every(dep => dep.skipReason)); + }); }); });