import { Release } from "./ReleaseChangelogInterfaces" ; import { Changelog as PackageChangelog } from "@dxatscale/sfpowerscripts.core/lib/changelog/interfaces/GenericChangelogInterfaces" ; import ReadPackageChangelog from "./ReadPackageChangelog" ; export default class CommitUpdater { constructor ( private latestRelease , private artifactsToLatestCommitId , private packagesToChangelogFilePaths , private readPackageChangelog ) { } returns update ( ) { for ( let artifact of this . latestRelease [ "artifacts" ] ) { let packageChangelog = this . readPackageChangelog ( this . packagesToChangelogFilePaths [ artifact . name ] ) ; artifact [ "latestCommitId" ] = packageChangelog [ "commits" ] [ 0 ] [ "commitId" ] ; let indexOfLatestCommitId ; if ( this . artifactsToLatestCommitId ?. [ artifact . name ] ) { indexOfLatestCommitId = packageChangelog [ "commits" ] . findIndex ( ( commit ) => commit [ "commitId" ] === this . artifactsToLatestCommitId [ artifact . name ] ) ; if ( indexOfLatestCommitId === - 1 ) { console . log ( `Cannot find commit Id ${ this . artifactsToLatestCommitId [ artifact . name ] } in ${ artifact . name } changelog` ) ; console . log ( "Assuming that there are no changes..." ) ; artifact [ "commits" ] = [ ] ; continue ; } } if ( indexOfLatestCommitId > 0 ) { artifact [ "commits" ] = packageChangelog [ "commits" ] . slice ( 0 , indexOfLatestCommitId ) ; } else if ( indexOfLatestCommitId === 0 ) { artifact [ "commits" ] = [ ] ; continue ; } else if ( indexOfLatestCommitId === undefined ) { artifact [ "commits" ] = packageChangelog [ "commits" ] ; } } } }