import { load } from 'js-yaml' ; import { GitTagsDatasource } from '../../datasource/git-tags' ; import { logger } from '../../logger' ; import { getDep } from '../dockerfile/extract' ; import type { PackageDependency , PackageFile } from '../types' ; import type { AzurePipelines , Container , Repository } from './types' ; export function extractRepository ( repository ) { if ( repository . type !== 'github' ) { return null ; } if ( ! repository . ref ?. startsWith ( 'refs/tags/' ) ) { return null ; } return { autoReplaceStringTemplate : 'refs/tags/{{newValue}}' , currentValue : repository . ref . replace ( 'refs/tags/' , '' ) , datasource : GitTagsDatasource . id , depName : repository . name , depType : 'gitTags' , lookupName : `https://github.com/${ repository . name }.git` , replaceString : repository . ref , } ; } export function extractContainer ( container ) { if ( ! container . image ) { return null ; } const dep = getDep ( container . image ) ; logger . debug ( { depName : dep . depName , currentValue : dep . currentValue , currentDigest : dep . currentDigest , } , 'Azure pipelines docker image' ) ; dep . depType = 'docker' ; return dep ; } export function parseAzurePipelines ( content , filename ) { let pkg = null ; try { pkg = load ( content , { json : true } ) ; } catch ( err ) { logger . info ( { filename , err } , 'Error parsing azure-pipelines content' ) ; return null ; } if ( ! pkg || ! pkg . resources ) { return null ; } pkg . resources . containers = pkg . resources . containers || [ ] ; pkg . resources . repositories = pkg . resources . repositories || [ ] ; return pkg ; } export function extractPackageFile ( content , filename ) { logger . trace ( `azurePipelines.extractPackageFile(${ filename })` ) ; const deps = [ ] ; const pkg = parseAzurePipelines ( content , filename ) ; if ( ! pkg ) { return null ; } for ( const repository of pkg . resources . repositories ) { const dep = extractRepository ( repository ) ; if ( dep ) { deps . push ( dep ) ; } } for ( const container of pkg . resources . containers ) { const dep = extractContainer ( container ) ; if ( dep ) { deps . push ( dep ) ; } } if ( ! deps . length ) { return null ; } return { deps } ; }