@@ -6024,6 +6024,28 @@ function uncovered(file, options) {
6024
6024
. join ( ", " ) ;
6025
6025
}
6026
6026
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
+
6027
6049
/**
6028
6050
* Github comment for monorepo
6029
6051
* @param {Array<{packageName, lcovPath}> } lcovArrayForMonorepo
@@ -6035,6 +6057,7 @@ function commentForMonorepo(
6035
6057
lcovBaseArrayForMonorepo ,
6036
6058
options ,
6037
6059
) {
6060
+ const { base } = options ;
6038
6061
const html = lcovArrayForMonorepo . map ( lcovObj => {
6039
6062
const baseLcov = lcovBaseArrayForMonorepo . find (
6040
6063
el => el . packageName === lcovObj . packageName ,
@@ -6046,9 +6069,14 @@ function commentForMonorepo(
6046
6069
const plus = pdiff > 0 ? "+" : "" ;
6047
6070
const arrow = pdiff === 0 ? "" : pdiff < 0 ? "▾" : "▴" ;
6048
6071
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
+ }
6052
6080
6053
6081
return `${ table (
6054
6082
tbody (
@@ -6060,14 +6088,13 @@ function commentForMonorepo(
6060
6088
) ,
6061
6089
) } \n\n ${ details (
6062
6090
summary ( "Coverage Report" ) ,
6063
- tabulate ( lcovObj . lcov , options ) ,
6091
+ tabulate ( report , options ) ,
6064
6092
) } <br/>`;
6065
6093
} ) ;
6066
6094
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 ( "" ) ) ;
6071
6098
}
6072
6099
6073
6100
/**
@@ -6076,21 +6103,31 @@ function commentForMonorepo(
6076
6103
* @param {* } options
6077
6104
*/
6078
6105
function comment ( lcov , before , options ) {
6106
+ const { appName, base } = options ;
6079
6107
const pbefore = before ? percentage ( before ) : 0 ;
6080
6108
const pafter = before ? percentage ( lcov ) : 0 ;
6081
6109
const pdiff = pafter - pbefore ;
6082
6110
const plus = pdiff > 0 ? "+" : "" ;
6083
6111
const arrow = pdiff === 0 ? "" : pdiff < 0 ? "▾" : "▴" ;
6084
6112
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 ) ) ;
6086
6125
6087
6126
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 ) ,
6092
6129
"\n\n" ,
6093
- details ( summary ( "Coverage Report" ) , tabulate ( lcov , options ) ) ,
6130
+ details ( summary ( "Coverage Report" ) , tabulate ( report , options ) ) ,
6094
6131
) ;
6095
6132
}
6096
6133
@@ -6135,11 +6172,10 @@ function diffForMonorepo(
6135
6172
// Every comment written by our action will have this hidden
6136
6173
// header on top, and will be used to identify which comments
6137
6174
// to update/delete etc
6138
- const hiddenHeader = `<!-- monorepo-jest-reporter-action -->` ;
6139
6175
6140
- const appendHiddenHeaderToComment = body => hiddenHeader + body ;
6176
+ const appendHiddenHeaderToComment = ( body , hiddenHeader ) => hiddenHeader + body ;
6141
6177
6142
- const listComments = async ( { client, context, prNumber, commentHeader } ) => {
6178
+ const listComments = async ( { client, context, prNumber, commentHeader, hiddenHeader } ) => {
6143
6179
const { data : existingComments } = await client . issues . listComments ( {
6144
6180
...context . repo ,
6145
6181
issue_number : prNumber ,
@@ -6148,18 +6184,18 @@ const listComments = async ({ client, context, prNumber, commentHeader }) => {
6148
6184
return existingComments . filter ( ( { body } ) => body . startsWith ( hiddenHeader ) ) ;
6149
6185
} ;
6150
6186
6151
- const insertComment = async ( { client, context, prNumber, body } ) =>
6187
+ const insertComment = async ( { client, context, prNumber, body } , hiddenHeader ) =>
6152
6188
client . issues . createComment ( {
6153
6189
...context . repo ,
6154
6190
issue_number : prNumber ,
6155
- body : appendHiddenHeaderToComment ( body ) ,
6191
+ body : appendHiddenHeaderToComment ( body , hiddenHeader ) ,
6156
6192
} ) ;
6157
6193
6158
- const updateComment = async ( { client, context, body, commentId } ) =>
6194
+ const updateComment = async ( { client, context, body, commentId } , hiddenHeader ) =>
6159
6195
client . issues . updateComment ( {
6160
6196
...context . repo ,
6161
6197
comment_id : commentId ,
6162
- body : appendHiddenHeaderToComment ( body ) ,
6198
+ body : appendHiddenHeaderToComment ( body , hiddenHeader ) ,
6163
6199
} ) ;
6164
6200
6165
6201
const deleteComments = async ( { client, context, comments } ) =>
@@ -6172,11 +6208,12 @@ const deleteComments = async ({ client, context, comments }) =>
6172
6208
) ,
6173
6209
) ;
6174
6210
6175
- const upsertComment = async ( { client, context, prNumber, body } ) => {
6211
+ const upsertComment = async ( { client, context, prNumber, body, hiddenHeader } ) => {
6176
6212
const existingComments = await listComments ( {
6177
6213
client,
6178
6214
context,
6179
6215
prNumber,
6216
+ hiddenHeader,
6180
6217
} ) ;
6181
6218
const last = existingComments . pop ( ) ;
6182
6219
@@ -6192,13 +6229,13 @@ const upsertComment = async ({ client, context, prNumber, body }) => {
6192
6229
context,
6193
6230
body,
6194
6231
commentId : last . id ,
6195
- } )
6232
+ } , hiddenHeader )
6196
6233
: insertComment ( {
6197
6234
client,
6198
6235
context,
6199
6236
prNumber,
6200
6237
body,
6201
- } ) ;
6238
+ } , hiddenHeader ) ;
6202
6239
} ;
6203
6240
6204
6241
var github$2 = {
@@ -6256,6 +6293,7 @@ async function main() {
6256
6293
const token = core$1 . getInput ( "github-token" ) ;
6257
6294
const lcovFile = core$1 . getInput ( "lcov-file" ) || "./coverage/lcov.info" ;
6258
6295
const baseFile = core$1 . getInput ( "lcov-base" ) ;
6296
+ const appName = core$1 . getInput ( "app-name" ) ;
6259
6297
// Add base path for monorepo
6260
6298
const monorepoBasePath = core$1 . getInput ( "monorepo-base-path" ) ;
6261
6299
@@ -6309,6 +6347,7 @@ async function main() {
6309
6347
prefix : `${ process . env . GITHUB_WORKSPACE } /` ,
6310
6348
head : context . payload . pull_request . head . ref ,
6311
6349
base : context . payload . pull_request . base . ref ,
6350
+ appName,
6312
6351
} ;
6313
6352
6314
6353
const lcov = ! monorepoBasePath && ( await parse$1 ( raw ) ) ;
@@ -6327,6 +6366,7 @@ async function main() {
6327
6366
lcovBaseArrayForMonorepo ,
6328
6367
options ,
6329
6368
) ,
6369
+ hiddenHeader : appName ? `<!-- ${ appName } -code-coverage-assistant -->` : `<!-- monorepo-code-coverage-assistant -->`
6330
6370
} ) ;
6331
6371
}
6332
6372
0 commit comments