@@ -19,29 +19,30 @@ async function run() {
1919 await genhtml ( coverageFiles , tmpPath ) ;
2020
2121 const coverageFile = await mergeCoverages ( coverageFiles , tmpPath ) ;
22- const summary = await summarize ( coverageFile ) ;
2322 const totalCoverage = lcovTotal ( coverageFile ) ;
2423 const minimumCoverage = core . getInput ( 'minimum-coverage' ) ;
2524 const gitHubToken = core . getInput ( 'github-token' ) . trim ( ) ;
2625 const errorMessage = `The code coverage is too low. Expected at least ${ minimumCoverage } .` ;
2726 const isFailure = totalCoverage < minimumCoverage ;
2827
2928 if ( gitHubToken !== '' && github . context . eventName === 'pull_request' ) {
29+ const octokit = await github . getOctokit ( gitHubToken ) ;
30+ const summary = await summarize ( coverageFile ) ;
31+ const details = await detail ( coverageFile , octokit ) ;
3032 const sha = github . context . payload . pull_request . head . sha ;
3133 const shaShort = sha . substr ( 0 , 7 ) ;
32- let body = `### [LCOV](https://github.com/marketplace/actions/report-lcov) of commit [<code>${ shaShort } </code>](${ github . context . payload . pull_request . number } /commits/${ sha } ) during [${ github . context . workflow } #${ github . context . runNumber } ](../actions/runs/${ github . context . runId } )\n<pre>${ summary } </pre>` ;
34+ let body = `### [LCOV](https://github.com/marketplace/actions/report-lcov) of commit [<code>${ shaShort } </code>](${ github . context . payload . pull_request . number } /commits/${ sha } ) during [${ github . context . workflow } #${ github . context . runNumber } ](../actions/runs/${ github . context . runId } )\n<pre>${ summary } \n\nFiles changed coverage rate: ${ details } </pre>` ;
3335
3436 if ( isFailure ) {
3537 body += `\n:no_entry: ${ errorMessage } ` ;
3638 }
3739
38- await github . getOctokit ( gitHubToken )
39- . issues . createComment ( {
40- owner : github . context . repo . owner ,
41- repo : github . context . repo . repo ,
42- issue_number : github . context . payload . pull_request . number ,
43- body : body ,
44- } ) ;
40+ await octokit . issues . createComment ( {
41+ owner : github . context . repo . owner ,
42+ repo : github . context . repo . repo ,
43+ issue_number : github . context . payload . pull_request . number ,
44+ body : body ,
45+ } ) ;
4546 }
4647
4748 if ( isFailure ) {
@@ -108,7 +109,6 @@ async function summarize(coverageFile) {
108109 } ;
109110
110111 await exec . exec ( 'lcov' , [
111- coverageFile ,
112112 '--summary' ,
113113 coverageFile ,
114114 ] , options ) ;
@@ -122,4 +122,59 @@ async function summarize(coverageFile) {
122122 return lines . join ( '\n' ) ;
123123}
124124
125+ async function detail ( coverageFile , octokit ) {
126+ let output = '' ;
127+
128+ const options = { } ;
129+ options . listeners = {
130+ stdout : ( data ) => {
131+ output += data . toString ( ) ;
132+ } ,
133+ stderr : ( data ) => {
134+ output += data . toString ( ) ;
135+ }
136+ } ;
137+
138+ await exec . exec ( 'lcov' , [
139+ '--list' ,
140+ coverageFile ,
141+ '--list-full-path' ,
142+ ] , options ) ;
143+
144+ let lines = output
145+ . trim ( )
146+ . split ( / \r ? \n / )
147+
148+ lines . shift ( ) ; // Removes "Reading tracefile..."
149+ lines . pop ( ) ; // Removes "Total..."
150+ lines . pop ( ) ; // Removes "========"
151+
152+ const listFilesOptions = octokit
153+ . pulls . listFiles . endpoint . merge ( {
154+ owner : github . context . repo . owner ,
155+ repo : github . context . repo . repo ,
156+ pull_number : github . context . payload . pull_request . number ,
157+ } ) ;
158+ const listFilesResponse = await octokit . paginate ( listFilesOptions ) ;
159+ const changedFiles = listFilesResponse . map ( file => file . filename ) ;
160+
161+ lines = lines . filter ( ( line , index ) => {
162+ if ( index <= 2 ) return true ; // Include header
163+
164+ for ( const changedFile of changedFiles ) {
165+ console . log ( `${ line } === ${ changedFile } ` ) ;
166+
167+ if ( line . startsWith ( changedFile ) ) return true ;
168+ }
169+
170+ return false ;
171+ } ) ;
172+
173+ if ( lines . length === 3 ) { // Only the header remains
174+ return ' n/a' ;
175+ }
176+
177+ return '\n ' + lines . join ( '\n ' ) ;
178+ }
179+
125180run ( ) ;
0 commit comments