mirror of
https://github.com/renovatebot/renovate.git
synced 2026-10-27 07:50:47 +00:00
c32e2391a0
Refs #45216 The object counterpart to `prefer-coerce-array`: `x ?? {}` becomes `coerceObject(x)`. The rule flags a `??` whose default is a bare `{}` literal, so a populated default or an asserted `({} as Foo)` still passes; a `x ?? y ?? {}` chain maps onto `coerceObject(x, y)`. Every hit across `lib/` converted cleanly, so no disable comments were needed.
63 lines
1.5 KiB
TypeScript
63 lines
1.5 KiB
TypeScript
import { logger } from '../../../logger/index.ts';
|
|
import { coerceArray } from '../../../util/array.ts';
|
|
import { coerceObject } from '../../../util/object.ts';
|
|
import { parseSingleYaml } from '../../../util/yaml.ts';
|
|
import { getDep } from '../dockerfile/extract.ts';
|
|
import type { PackageDependency, PackageFileContent } from '../types.ts';
|
|
import type { VelaPipelineConfiguration } from './types.ts';
|
|
|
|
export function extractPackageFile(
|
|
file: string,
|
|
packageFile?: string,
|
|
): PackageFileContent | null {
|
|
let doc: VelaPipelineConfiguration;
|
|
|
|
try {
|
|
// TODO: use schema (#9610)
|
|
doc = parseSingleYaml(file);
|
|
} catch (err) {
|
|
logger.debug({ err, packageFile }, 'Failed to parse Vela file.');
|
|
return null;
|
|
}
|
|
|
|
const deps: PackageDependency[] = [];
|
|
|
|
// iterate over steps
|
|
for (const step of coerceArray(doc.steps)) {
|
|
const dep = getDep(step.image);
|
|
|
|
deps.push(dep);
|
|
}
|
|
|
|
// iterate over services
|
|
for (const service of coerceArray(doc.services)) {
|
|
const dep = getDep(service.image);
|
|
|
|
deps.push(dep);
|
|
}
|
|
|
|
// iterate over stages
|
|
for (const stage of Object.values(coerceObject(doc.stages))) {
|
|
for (const step of coerceArray(stage.steps)) {
|
|
const dep = getDep(step.image);
|
|
|
|
deps.push(dep);
|
|
}
|
|
}
|
|
|
|
// check secrets
|
|
for (const secret of Object.values(coerceObject(doc.secrets))) {
|
|
if (secret.origin) {
|
|
const dep = getDep(secret.origin.image);
|
|
|
|
deps.push(dep);
|
|
}
|
|
}
|
|
|
|
if (!deps.length) {
|
|
return null;
|
|
}
|
|
|
|
return { deps };
|
|
}
|