forked from renovatebot/renovate
/
extract.ts
61 lines (51 loc) · 1.52 KB
/
extract.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import { safeLoadAll } from 'js-yaml';
import * as gitTags from '../../datasource/git-tags';
import * as helm from '../../datasource/helm';
import type { ExtractConfig, PackageDependency, PackageFile } from '../types';
import type { ApplicationDefinition } from './types';
import { fileTestRegex } from './util';
function loadYaml(content: string): ApplicationDefinition[] {
return safeLoadAll(content);
}
function createDependency(
definition: ApplicationDefinition
): PackageDependency {
let result: PackageDependency;
const source = definition.spec.source;
if (source == null) {
return null;
}
// a chart variable is defined this is helm declaration
if (source.chart) {
result = {
depName: source.chart,
registryUrls: [source.repoURL],
currentValue: source.targetRevision,
datasource: helm.id,
};
} else {
result = {
depName: source.repoURL,
currentValue: source.targetRevision,
datasource: gitTags.id,
};
}
return result;
}
export function extractPackageFile(
content: string,
fileName: string,
config?: ExtractConfig
): PackageFile | null {
// check for argo reference. API version for the kind attribute is used
if (fileTestRegex.test(content) === false) {
return null;
}
const definitions = loadYaml(content);
const deps = definitions.map((definition) => createDependency(definition));
const filteredDeps = deps.filter((value) => value);
if (filteredDeps.length === 0) {
return null;
}
return { deps: filteredDeps };
}