import Git from "./Git" ; import child_process = require ( "child_process" ) ; export default class GitTags { constructor ( private git , private sfdx_package ) { } param sfdx_package async listTagsOnBranch ( ) { let tags = await this . git . tag ( [ `-l` , `${ this . sfdx_package }_v*` , `--sort=version:refname` , `--merged` ] ) ; if ( tags . length > 0 ) return this . filterTagsAgainstBranch ( tags ) ; else return tags ; } private async filterTagsAgainstBranch ( tags ) { let commits = await this . git . log ( [ `--pretty=format:%H` , `--first-parent` ] ) ; let gitShowRefTagsBuffer = child_process . execSync ( `git show-ref --tags -d | grep "${ this . sfdx_package }_v*"` , { stdio : 'pipe' } ) ; let gitShowRefTags = gitShowRefTagsBuffer . toString ( ) ; let refTags = gitShowRefTags . split ( "\n" ) ; refTags . pop ( ) ; let refTagsPointingToBranch = refTags . filter ( ( refTag ) => commits . includes ( refTag . substr ( 0 , 40 ) ) ) ; refTagsPointingToBranch = refTagsPointingToBranch . map ( ( refTagPointingToBranch ) => refTagPointingToBranch . match ( /(?:refs\/tags\/)(.*)(?:\^{})$/ ) [ 1 ] ) ; let tagsPointingToBranch = tags . filter ( ( tag ) => refTagsPointingToBranch . includes ( tag ) ) ; return tagsPointingToBranch ; } }