@@ -6024,6 +6024,28 @@ function uncovered(file, options) {
60246024 . join ( ", " ) ;
60256025}
60266026
6027+ /**
6028+ * Compares two arrays of objects and returns with unique lines update
6029+ * @param {number } pdiff value from diff percentage
6030+ * @returns {string } emoji string for negative/positive pdiff
6031+ */
6032+ const renderEmoji = pdiff => {
6033+ if ( pdiff . toFixed ( 2 ) < 0 ) return "❌" ;
6034+ return "✅" ;
6035+ } ;
6036+
6037+ /**
6038+ * Compares two arrays of objects and returns with unique lines update
6039+ * @param {Array } otherArray
6040+ * @returns {Function } function with filtering non original lines
6041+ */
6042+ const comparer = otherArray => current =>
6043+ otherArray . filter (
6044+ other =>
6045+ other . lines . found === current . lines . found &&
6046+ other . lines . hit === current . lines . hit ,
6047+ ) . length === 0 ;
6048+
60276049/**
60286050 * Github comment for monorepo
60296051 * @param {Array<{packageName, lcovPath}> } lcovArrayForMonorepo
@@ -6035,6 +6057,7 @@ function commentForMonorepo(
60356057 lcovBaseArrayForMonorepo ,
60366058 options ,
60376059) {
6060+ const { base } = options ;
60386061 const html = lcovArrayForMonorepo . map ( lcovObj => {
60396062 const baseLcov = lcovBaseArrayForMonorepo . find (
60406063 el => el . packageName === lcovObj . packageName ,
@@ -6046,9 +6069,14 @@ function commentForMonorepo(
60466069 const plus = pdiff > 0 ? "+" : "" ;
60476070 const arrow = pdiff === 0 ? "" : pdiff < 0 ? "▾" : "▴" ;
60486071
6049- const pdiffHtml = baseLcov
6050- ? th ( arrow , " " , plus , pdiff . toFixed ( 2 ) , "%" )
6051- : "" ;
6072+ const pdiffHtml = baseLcov ? th ( renderEmoji ( pdiff ) , " " , arrow , " " , plus , pdiff . toFixed ( 2 ) , "%" ) : "" ;
6073+ let report = lcovObj . lcov ;
6074+
6075+ if ( baseLcov ) {
6076+ const onlyInLcov = lcovObj . lcov . filter ( comparer ( baseLcov ) ) ;
6077+ const onlyInBefore = baseLcov . filter ( comparer ( lcovObj . lcov ) ) ;
6078+ report = onlyInBefore . concat ( onlyInLcov ) ;
6079+ }
60526080
60536081 return `${ table (
60546082 tbody (
@@ -6060,14 +6088,13 @@ function commentForMonorepo(
60606088 ) ,
60616089 ) } \n\n ${ details (
60626090 summary ( "Coverage Report" ) ,
6063- tabulate ( lcovObj . lcov , options ) ,
6091+ tabulate ( report , options ) ,
60646092 ) } <br/>`;
60656093 } ) ;
60666094
6067- return fragment (
6068- `Coverage after merging into ${ b ( options . base ) } <p></p>` ,
6069- html . join ( "" ) ,
6070- ) ;
6095+ const title = `Coverage after merging into ${ b ( base ) } <p></p>` ;
6096+
6097+ return fragment ( title , html . join ( "" ) ) ;
60716098}
60726099
60736100/**
@@ -6076,21 +6103,31 @@ function commentForMonorepo(
60766103 * @param {* } options
60776104 */
60786105function comment ( lcov , before , options ) {
6106+ const { appName, base } = options ;
60796107 const pbefore = before ? percentage ( before ) : 0 ;
60806108 const pafter = before ? percentage ( lcov ) : 0 ;
60816109 const pdiff = pafter - pbefore ;
60826110 const plus = pdiff > 0 ? "+" : "" ;
60836111 const arrow = pdiff === 0 ? "" : pdiff < 0 ? "▾" : "▴" ;
60846112
6085- const pdiffHtml = before ? th ( arrow , " " , plus , pdiff . toFixed ( 2 ) , "%" ) : "" ;
6113+ const pdiffHtml = before ? th ( renderEmoji ( pdiff ) , " " , arrow , " " , plus , pdiff . toFixed ( 2 ) , "%" ) : "" ;
6114+
6115+ let report = lcov ;
6116+
6117+ if ( before ) {
6118+ const onlyInLcov = lcov . filter ( comparer ( before ) ) ;
6119+ const onlyInBefore = before . filter ( comparer ( lcov ) ) ;
6120+ report = onlyInBefore . concat ( onlyInLcov ) ;
6121+ }
6122+
6123+ const title = `Coverage after merging into ${ b ( base ) } <p></p>` ;
6124+ const header = appName ? tbody ( tr ( th ( appName ) , th ( percentage ( lcov ) . toFixed ( 2 ) , '%' ) , pdiffHtml ) ) : tbody ( tr ( th ( percentage ( lcov ) . toFixed ( 2 ) , '%' ) , pdiffHtml ) ) ;
60866125
60876126 return fragment (
6088- `Coverage after merging ${ b ( options . head ) } into ${ b (
6089- options . base ,
6090- ) } <p></p>`,
6091- table ( tbody ( tr ( th ( percentage ( lcov ) . toFixed ( 2 ) , "%" ) , pdiffHtml ) ) ) ,
6127+ title ,
6128+ table ( header ) ,
60926129 "\n\n" ,
6093- details ( summary ( "Coverage Report" ) , tabulate ( lcov , options ) ) ,
6130+ details ( summary ( "Coverage Report" ) , tabulate ( report , options ) ) ,
60946131 ) ;
60956132}
60966133
@@ -6135,11 +6172,10 @@ function diffForMonorepo(
61356172// Every comment written by our action will have this hidden
61366173// header on top, and will be used to identify which comments
61376174// to update/delete etc
6138- const hiddenHeader = `<!-- monorepo-jest-reporter-action -->` ;
61396175
6140- const appendHiddenHeaderToComment = body => hiddenHeader + body ;
6176+ const appendHiddenHeaderToComment = ( body , hiddenHeader ) => hiddenHeader + body ;
61416177
6142- const listComments = async ( { client, context, prNumber, commentHeader } ) => {
6178+ const listComments = async ( { client, context, prNumber, commentHeader, hiddenHeader } ) => {
61436179 const { data : existingComments } = await client . issues . listComments ( {
61446180 ...context . repo ,
61456181 issue_number : prNumber ,
@@ -6148,18 +6184,18 @@ const listComments = async ({ client, context, prNumber, commentHeader }) => {
61486184 return existingComments . filter ( ( { body } ) => body . startsWith ( hiddenHeader ) ) ;
61496185} ;
61506186
6151- const insertComment = async ( { client, context, prNumber, body } ) =>
6187+ const insertComment = async ( { client, context, prNumber, body } , hiddenHeader ) =>
61526188 client . issues . createComment ( {
61536189 ...context . repo ,
61546190 issue_number : prNumber ,
6155- body : appendHiddenHeaderToComment ( body ) ,
6191+ body : appendHiddenHeaderToComment ( body , hiddenHeader ) ,
61566192 } ) ;
61576193
6158- const updateComment = async ( { client, context, body, commentId } ) =>
6194+ const updateComment = async ( { client, context, body, commentId } , hiddenHeader ) =>
61596195 client . issues . updateComment ( {
61606196 ...context . repo ,
61616197 comment_id : commentId ,
6162- body : appendHiddenHeaderToComment ( body ) ,
6198+ body : appendHiddenHeaderToComment ( body , hiddenHeader ) ,
61636199 } ) ;
61646200
61656201const deleteComments = async ( { client, context, comments } ) =>
@@ -6172,11 +6208,12 @@ const deleteComments = async ({ client, context, comments }) =>
61726208 ) ,
61736209 ) ;
61746210
6175- const upsertComment = async ( { client, context, prNumber, body } ) => {
6211+ const upsertComment = async ( { client, context, prNumber, body, hiddenHeader } ) => {
61766212 const existingComments = await listComments ( {
61776213 client,
61786214 context,
61796215 prNumber,
6216+ hiddenHeader,
61806217 } ) ;
61816218 const last = existingComments . pop ( ) ;
61826219
@@ -6192,13 +6229,13 @@ const upsertComment = async ({ client, context, prNumber, body }) => {
61926229 context,
61936230 body,
61946231 commentId : last . id ,
6195- } )
6232+ } , hiddenHeader )
61966233 : insertComment ( {
61976234 client,
61986235 context,
61996236 prNumber,
62006237 body,
6201- } ) ;
6238+ } , hiddenHeader ) ;
62026239} ;
62036240
62046241var github$2 = {
@@ -6256,6 +6293,7 @@ async function main() {
62566293 const token = core$1 . getInput ( "github-token" ) ;
62576294 const lcovFile = core$1 . getInput ( "lcov-file" ) || "./coverage/lcov.info" ;
62586295 const baseFile = core$1 . getInput ( "lcov-base" ) ;
6296+ const appName = core$1 . getInput ( "app-name" ) ;
62596297 // Add base path for monorepo
62606298 const monorepoBasePath = core$1 . getInput ( "monorepo-base-path" ) ;
62616299
@@ -6309,6 +6347,7 @@ async function main() {
63096347 prefix : `${ process . env . GITHUB_WORKSPACE } /` ,
63106348 head : context . payload . pull_request . head . ref ,
63116349 base : context . payload . pull_request . base . ref ,
6350+ appName,
63126351 } ;
63136352
63146353 const lcov = ! monorepoBasePath && ( await parse$1 ( raw ) ) ;
@@ -6327,6 +6366,7 @@ async function main() {
63276366 lcovBaseArrayForMonorepo ,
63286367 options ,
63296368 ) ,
6369+ hiddenHeader : appName ? `<!-- ${ appName } -code-coverage-assistant -->` : `<!-- monorepo-code-coverage-assistant -->`
63306370 } ) ;
63316371}
63326372
0 commit comments