mirror of
https://github.com/renovatebot/renovate.git
synced 2025-01-15 00:56:26 +00:00
82 lines
2.4 KiB
TypeScript
82 lines
2.4 KiB
TypeScript
import is from '@sindresorhus/is';
|
|
import yaml from 'js-yaml';
|
|
import { SkipReason } from '../../types';
|
|
import { logger } from '../../logger';
|
|
import { PackageFile, PackageDependency, ExtractConfig } from '../common';
|
|
import * as datasourceHelm from '../../datasource/helm';
|
|
import { readLocalFile, getSiblingFileName } from '../../util/fs';
|
|
|
|
export async function extractPackageFile(
|
|
content: string,
|
|
fileName: string,
|
|
config: ExtractConfig
|
|
): Promise<PackageFile> {
|
|
try {
|
|
const chartFileName = getSiblingFileName(fileName, 'Chart.yaml');
|
|
const chartContents = await readLocalFile(chartFileName, 'utf8');
|
|
if (!chartContents) {
|
|
logger.debug({ fileName }, 'Failed to find helm Chart.yaml');
|
|
return null;
|
|
}
|
|
const chart = yaml.safeLoad(chartContents, { json: true });
|
|
if (!(chart && chart.apiVersion && chart.name && chart.version)) {
|
|
logger.debug(
|
|
{ fileName },
|
|
'Failed to find required fields in Chart.yaml'
|
|
);
|
|
return null;
|
|
}
|
|
} catch (err) {
|
|
logger.debug({ fileName }, 'Failed to parse helm Chart.yaml');
|
|
return null;
|
|
}
|
|
let deps = [];
|
|
let doc;
|
|
try {
|
|
doc = yaml.safeLoad(content, { json: true });
|
|
} catch (err) {
|
|
logger.debug({ fileName }, 'Failed to parse helm requirements.yaml');
|
|
return null;
|
|
}
|
|
if (!(doc && is.array(doc.dependencies))) {
|
|
logger.debug({ fileName }, 'requirements.yaml has no dependencies');
|
|
return null;
|
|
}
|
|
deps = doc.dependencies.map((dep) => {
|
|
const res: PackageDependency = {
|
|
depName: dep.name,
|
|
currentValue: dep.version,
|
|
};
|
|
if (dep.repository) {
|
|
res.registryUrls = [dep.repository];
|
|
if (dep.repository.startsWith('@')) {
|
|
const repoWithAtRemoved = dep.repository.slice(1);
|
|
const alias = config.aliases[repoWithAtRemoved];
|
|
if (alias) {
|
|
res.registryUrls = [alias];
|
|
return res;
|
|
}
|
|
|
|
res.skipReason = SkipReason.PlaceholderUrl;
|
|
} else {
|
|
try {
|
|
const url = new URL(dep.repository);
|
|
if (url.protocol === 'file:') {
|
|
res.skipReason = SkipReason.LocalDependency;
|
|
}
|
|
} catch (err) {
|
|
logger.debug({ err }, 'Error parsing url');
|
|
res.skipReason = SkipReason.InvalidUrl;
|
|
}
|
|
}
|
|
} else {
|
|
res.skipReason = SkipReason.NoRepository;
|
|
}
|
|
return res;
|
|
});
|
|
const res = {
|
|
deps,
|
|
datasource: datasourceHelm.id,
|
|
};
|
|
return res;
|
|
}
|