import is from '@sindresorhus/is' ; import { loadAll } from 'js-yaml' ; import { GitTagsDatasource } from '../../datasource/git-tags' ; import { HelmDatasource } from '../../datasource/helm' ; import type { ExtractConfig , PackageDependency , PackageFile } from '../types' ; import type { ApplicationDefinition } from './types' ; import { fileTestRegex } from './util' ; function createDependency ( definition ) { const source = definition ?. spec ?. source ; if ( ! source || ! is . nonEmptyString ( source . repoURL ) || ! is . nonEmptyString ( source . targetRevision ) ) { return null ; } if ( source . chart ) { return { depName : source . chart , registryUrls : [ source . repoURL ] , currentValue : source . targetRevision , datasource : HelmDatasource . id , } ; } return { depName : source . repoURL , currentValue : source . targetRevision , datasource : GitTagsDatasource . id , } ; } export function extractPackageFile ( content , fileName , config ? ) { if ( fileTestRegex . test ( content ) === false ) { return null ; } const definitions = loadAll ( content ) as ApplicationDefinition [ ] ; const deps = definitions . map ( ( definition ) => createDependency ( definition ) ) . filter ( Boolean ) ; return deps . length ? { deps } : null ; }