import { load } from 'js-yaml' ; import { logger } from '../../logger' ; import { id as dockerVersioning } from '../../versioning/docker' ; import { getDep } from '../dockerfile/extract' ; import type { PackageDependency , PackageFile } from '../types' ; import type { HelmDockerImageDependency } from './types' ; import { matchesHelmValuesDockerHeuristic , matchesHelmValuesInlineImage , } from './util' ; function getHelmDep ( { registry , repository , tag , } ) { const dep = getDep ( `${ registry }${ repository }:${ tag }` , false ) ; dep . replaceString = tag ; dep . versioning = dockerVersioning ; dep . autoReplaceStringTemplate = '{{newValue}}{{#if newDigest}}@{{newDigest}}{{/if}}' ; return dep ; } param parsedContent function findDependencies ( parsedContent , packageDependencies ) { if ( ! parsedContent || typeof parsedContent !== 'object' ) { return packageDependencies ; } Object . keys ( parsedContent ) . forEach ( ( key ) => { if ( matchesHelmValuesDockerHeuristic ( key , parsedContent [ key ] ) ) { const currentItem = parsedContent [ key ] ; let registry = currentItem . registry ; registry = registry ? `${ registry }/` : '' ; const repository = String ( currentItem . repository ) ; const tag = String ( currentItem . tag ) ; packageDependencies . push ( getHelmDep ( { repository , tag , registry } ) ) ; } else if ( matchesHelmValuesInlineImage ( key , parsedContent [ key ] ) ) { const currentItem = parsedContent [ key ] ; packageDependencies . push ( getDep ( currentItem ) ) ; } else { findDependencies ( parsedContent [ key ] , packageDependencies ) ; } } ) ; return packageDependencies ; } export function extractPackageFile ( content ) { let parsedContent ; try { parsedContent = load ( content , { json : true } ) as any ; } catch ( err ) { logger . debug ( { err } , 'Failed to parse helm-values YAML' ) ; return null ; } try { const deps = findDependencies ( parsedContent , [ ] ) ; if ( deps . length ) { return { deps } ; } } catch ( err ) { logger . warn ( { err } , 'Error parsing helm-values parsed content' ) ; } return null ; }