Skip to content

Commit

Permalink
fix(skipreason): make better comunication of the issue
Browse files Browse the repository at this point in the history
  • Loading branch information
gmelillo committed Feb 1, 2020
1 parent 4264a36 commit 0a49e6f
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 13 deletions.
31 changes: 21 additions & 10 deletions lib/manager/helmfile/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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;
}
Expand All @@ -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;
}
46 changes: 43 additions & 3 deletions test/manager/helmfile/__snapshots__/extract.spec.ts.snap
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -8,7 +48,7 @@ Object {
"currentValue": "1.0.0",
"depName": "example",
"registryUrls": Array [],
"skipReason": "invalid-registry",
"skipReason": "unknown-registry",
},
],
}
Expand All @@ -22,7 +62,7 @@ Object {
"currentValue": "1.0.0",
"depName": "example",
"registryUrls": Array [],
"skipReason": "invalid-registry",
"skipReason": "unknown-registry",
},
],
}
Expand Down Expand Up @@ -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",
Expand Down
44 changes: 44 additions & 0 deletions test/manager/helmfile/extract.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
});
});
});

0 comments on commit 0a49e6f

Please sign in to comment.