import is from '@sindresorhus/is' ; import { loadAll } from 'js-yaml' ; import { HelmDatasource } from '../../datasource/helm' ; import { logger } from '../../logger' ; import { SkipReason } from '../../types' ; import { regEx } from '../../util/regex' ; import type { ExtractConfig , PackageDependency , PackageFile } from '../types' ; import type { Doc } from './types' ; const isValidChartName = ( name ) : boolean => ! regEx ( /[!@#$%^&*(),.?":{}/|<>A-Z]/ ) . test ( name ) ; export function extractPackageFile ( content , fileName , config ) { let deps = [ ] ; let docs ; const aliases = { } ; try { docs = loadAll ( content , null , { json : true } ) ; } catch ( err ) { logger . debug ( { err , fileName } , 'Failed to parse helmfile helmfile.yaml' ) ; return null ; } for ( const doc of docs ) { if ( ! ( doc && is . array ( doc . releases ) ) ) { continue ; } if ( doc . repositories ) { for ( let i = 0 ; i < doc . repositories . length ; i += 1 ) { aliases [ doc . repositories [ i ] . name ] = doc . repositories [ i ] . url ; } } logger . debug ( { aliases } , 'repositories discovered.' ) ; deps = doc . releases . map ( ( dep ) => { let depName = dep . chart ; let repoName = null ; if ( ! is . string ( dep . chart ) ) { return { depName : dep . name , skipReason : SkipReason . InvalidName , } ; } if ( dep . chart . startsWith ( './' ) ) { return { depName , skipReason : SkipReason . LocalChart , } ; } if ( dep . chart . includes ( '/' ) ) { const v = dep . chart . split ( '/' ) ; repoName = v . shift ( ) ; depName = v . join ( '/' ) ; } else { repoName = dep . chart ; } const res = { depName , currentValue : dep . version , registryUrls : [ aliases [ repoName ] ] . concat ( [ config . aliases [ repoName ] ] ) . filter ( Boolean ) , } ; if ( ! res . currentValue ) { res . skipReason = SkipReason . LocalChart ; } if ( ! isValidChartName ( res . depName ) ) { res . skipReason = SkipReason . UnsupportedChartType ; } if ( is . emptyArray ( res . registryUrls ) ) { res . skipReason = SkipReason . UnknownRegistry ; } return res ; } ) ; } if ( ! deps . length ) { logger . debug ( { fileName } , 'helmfile.yaml has no releases' ) ; return null ; } return { deps , datasource : HelmDatasource . id } as PackageFile ; }