Skip to content
Snippets Groups Projects
Unverified Commit ac342796 authored by Sergei Zharinov's avatar Sergei Zharinov Committed by GitHub
Browse files

feat(regex-manager): Support for registryUrl capture group (#7792)

parent 6afc9d86
No related merge requests found
......@@ -73,3 +73,30 @@ Object {
],
}
`;
exports[`manager/regex/index extracts registryUrl 1`] = `
Object {
"deps": Array [
Object {
"currentValue": "8.12.13",
"datasource": "helm",
"depName": "prometheus-operator",
"registryUrls": Array [
"https://kubernetes-charts.storage.googleapis.com/",
],
"replaceString": "chart:
repository: https://kubernetes-charts.storage.googleapis.com/
name: prometheus-operator
version: 8.12.13
",
},
],
"matchStrings": Array [
"chart:
*repository: (?<registryUrl>.*?)
*name: (?<depName>.*?)
*version: (?<currentValue>.*)
",
],
}
`;
......@@ -60,4 +60,30 @@ describe(getName(__filename), () => {
);
expect(res).toBeNull();
});
it('extracts registryUrl', async () => {
const config = {
matchStrings: [
'chart:\n *repository: (?<registryUrl>.*?)\n *name: (?<depName>.*?)\n *version: (?<currentValue>.*)\n',
],
datasourceTemplate: 'helm',
};
const res = await extractPackageFile(
`
apiVersion: helm.fluxcd.io/v1
kind: HelmRelease
metadata:
name: prometheus-operator
namespace: monitoring
spec:
releaseName: prometheus-operator
chart:
repository: https://kubernetes-charts.storage.googleapis.com/
name: prometheus-operator
version: 8.12.13
`,
'Dockerfile',
config
);
expect(res).toMatchSnapshot();
});
});
import url from 'url';
import { logger } from '../../logger';
import { regEx } from '../../util/regex';
import * as template from '../../util/template';
......@@ -27,6 +28,7 @@ export function extractPackageFile(
'currentDigest',
'datasource',
'versioning',
'registryUrl',
];
for (const field of fields) {
const fieldTemplate = `${field}Template`;
......@@ -45,6 +47,12 @@ export function extractPackageFile(
}
}
dep.replaceString = String(matchResult[0]);
if (dep.registryUrl) {
if (url.parse(dep.registryUrl)) {
dep.registryUrls = [dep.registryUrl];
}
delete dep.registryUrl;
}
deps.push(dep);
}
} while (matchResult);
......
......@@ -23,6 +23,7 @@ Configuration-wise, it works like this:
- You must have either a `datasource` capture group or a `datasourceTemplate` config field
- You can optionally have a `versioning` capture group or a `versioningTemplate` config field. If neither are present, `semver` will be used as the default
- You can optionally have a `currentDigest` capture group.
- You can optionally have a `registryUrl` capture group. If it's a valid URL, it will be converted to the `registryUrls` field as a single-length array.
### Regular Expression Capture Groups
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment