1- import { details , summary , b , fragment , table , tbody , tr , th , p } from "./html" ;
1+ import { b , details , fragment , p , summary , table , tbody , th , tr } from "./html" ;
22import { percentage } from "./lcov" ;
33import { tabulate } from "./tabulate" ;
44
@@ -35,7 +35,6 @@ const comparer = (otherArray) => (current) =>
3535 ) . length === 0 ;
3636
3737const renderLcov = ( lcov , base , appTitle , options ) => {
38- const maxLines = options . maxLines || 15 ;
3938 const pbefore = base ? percentage ( base ) : 0 ;
4039 const pafter = base ? percentage ( lcov ) : 0 ;
4140 const pdiff = pafter - pbefore ;
@@ -71,7 +70,7 @@ const renderLcov = (lcov, base, appTitle, options) => {
7170 }
7271 return [
7372 table ( tbody ( tr ( ...row ) ) ) ,
74- report . length > maxLines
73+ report . length > options . maxLines
7574 ? p ( "Coverage Report too long to display" )
7675 : details ( summary ( "Coverage Report" ) , tabulate ( report , options ) ) ,
7776 "<br/>" ,
@@ -81,10 +80,10 @@ const renderLcov = (lcov, base, appTitle, options) => {
8180/**
8281 * Github comment for monorepo
8382 * @param {Array<{packageName, lcovPath}> } lcovArrayForMonorepo
84- * @param {{ Array<{packageName, lcovBasePath}>} } lcovBaseArrayForMonorepo
83+ * @param {Array<{packageName, lcovPath}> } lcovBaseArrayForMonorepo
8584 * @param {* } options
8685 */
87- const commentForMonorepo = (
86+ const renderCommentArray = (
8887 lcovArrayForMonorepo ,
8988 lcovBaseArrayForMonorepo ,
9089 options ,
@@ -110,32 +109,65 @@ const commentForMonorepo = (
110109
111110/**
112111 * Github comment for single repo
113- * @param {raw lcov } lcov
112+ * @param {raw } lcov
113+ * @param {raw } baseLcov
114+ * @param {string } appTitle
114115 * @param {* } options
115116 */
116- const comment = ( lcov , before , options ) => {
117- const { appName, base } = options ;
117+ const renderCommentLine = ( lcov , baseLcov , appTitle , options ) => {
118+ const inner = renderLcov ( lcov , baseLcov , appTitle , options ) ;
119+ const { base } = options ;
118120 const title = `Coverage after merging into ${ b ( base ) } <p></p>` ;
119- return fragment ( title , renderLcov ( lcov , before , appName , options ) ) ;
121+ return fragment ( title , inner ) ;
120122} ;
121123
122- /**
123- * Diff in coverage percentage for single repo
124- * @param {raw lcov } lcov
125- * @param {raw base lcov } before
126- * @param {* } options
127- */
128- export const diff = ( lcov , before , options ) => comment ( lcov , before , options ) ;
129-
130- /**
131- * Diff in coverage percentage for monorepo
132- * @param {Array<{packageName, lcovPath}> } lcovArrayForMonorepo
133- * @param {{Array<{packageName, lcovBasePath}>} } lcovBaseArrayForMonorepo
134- * @param {* } options
135- */
136- export const diffForMonorepo = (
137- lcovArrayForMonorepo ,
138- lcovBaseArrayForMonorepo ,
124+ export const comments = async ( {
125+ rootLcov,
126+ rootBaseLcov,
127+ lcovArray,
128+ lcovBaseArray,
139129 options,
140- ) =>
141- commentForMonorepo ( lcovArrayForMonorepo , lcovBaseArrayForMonorepo , options ) ;
130+ upsert,
131+ } ) => {
132+ const renderOptions = {
133+ maxLines : options . maxLines ,
134+ prefix : options . prefix ,
135+ repository : options . repository ,
136+ commit : options . pullRequest . head . sha ,
137+ head : options . pullRequest . head . ref ,
138+ base : options . pullRequest . base . ref ,
139+ } ;
140+ // Comments
141+ if ( lcovArray . length > 0 ) {
142+ if ( options . multipleComment ) {
143+ for ( const lcovObj of lcovArray ) {
144+ const baseLcov = lcovBaseArray . find (
145+ ( el ) => el . packageName === lcovObj . packageName ,
146+ ) ;
147+ const body = renderCommentLine (
148+ lcovObj . lcov ,
149+ baseLcov && baseLcov . lcov ,
150+ lcovObj . packageName ,
151+ renderOptions ,
152+ ) ;
153+ await upsert ( `m-${ lcovObj . packageName } ` , body ) ;
154+ }
155+ } else {
156+ const body = renderCommentArray (
157+ lcovArray ,
158+ lcovBaseArray ,
159+ renderOptions ,
160+ ) ;
161+ await upsert ( "single-comment" , body ) ;
162+ }
163+ }
164+ if ( rootLcov ) {
165+ const body = renderCommentLine (
166+ rootLcov ,
167+ rootBaseLcov ,
168+ "root" ,
169+ renderOptions ,
170+ ) ;
171+ await upsert ( `root-comment` , body ) ;
172+ }
173+ } ;
0 commit comments