import { replaceDoubleToSingleQuotes } from '../utils' ; import { REGEXP_AUTHOR } from '../constants' ; import { VCSConnector } from '../vcs-connector/connector-models' ; async function updateAuthorMetadataString ( defaultMetadata = '' , vcsConnector ? ) { if ( ! vcsConnector ) { return defaultMetadata ; } const matchAuthor = defaultMetadata . match ( REGEXP_AUTHOR ) ; if ( matchAuthor && matchAuthor ?. length > 0 ) { const authorLogin = matchAuthor [ 0 ] ; const user = await getAuthorDetails ( vcsConnector , authorLogin ) ; if ( user ) { return defaultMetadata . replace ( authorLogin , user ) ; } } return defaultMetadata ; } async function getAuthorDetails ( vcsConnector , author ) { if ( typeof author === 'object' ) { return replaceDoubleToSingleQuotes ( JSON . stringify ( author ) ) ; } try { JSON . parse ( author ) ; return replaceDoubleToSingleQuotes ( author ) ; } catch { const user = await vcsConnector . getUserByLogin ( author ) ; if ( user ) { return replaceDoubleToSingleQuotes ( JSON . stringify ( user ) ) ; } return null ; } } export { updateAuthorMetadataString , getAuthorDetails , } ;