@@ -9,6 +9,10 @@ const path = require('path');
99
1010const events = [ 'pull_request' , 'pull_request_target' ] ;
1111
12+ function commentIdentifier ( workflowName ) {
13+ return `### [LCOV](https://github.com/marketplace/actions/report-lcov) of commit`
14+ }
15+
1216async function run ( ) {
1317 try {
1418 await exec . exec ( 'sudo apt-get install -y lcov' ) ;
@@ -18,6 +22,7 @@ async function run() {
1822 const globber = await glob . create ( coverageFilesPattern ) ;
1923 const coverageFiles = await globber . glob ( ) ;
2024 const title = core . getInput ( 'title' ) ;
25+ const updateComment = core . getInput ( 'update-comment' ) ;
2126
2227 await genhtml ( coverageFiles , tmpPath ) ;
2328
@@ -40,6 +45,33 @@ async function run() {
4045 body += `\n:no_entry: ${ errorMessage } ` ;
4146 }
4247
48+ const updateGitHubComment = commentId =>
49+ octokit . issues . updateComment ( {
50+ repo : github . context . repo . repo ,
51+ owner : github . context . repo . owner ,
52+ comment_id : commentId ,
53+ body,
54+ } )
55+
56+ if ( updateComment == "true" ) {
57+ const issueComments = await octokit . issues . listComments ( {
58+ repo : github . context . repo . repo ,
59+ owner : github . context . repo . owner ,
60+ issue_number : github . context . payload . pull_request . number ,
61+ } )
62+
63+ const existingComment = issueComments . data . find ( comment =>
64+ comment . body . includes ( commentIdentifier ( process . env . GITHUB_WORKFLOW ) ) ,
65+ )
66+
67+ if ( existingComment ) {
68+ console . log ( 'Update Comment ID: ' + existingComment . id ) ;
69+ await updateGitHubComment ( existingComment . id ) ;
70+ return
71+ }
72+ console . log ( 'Comment does not exist, create a new one' ) ;
73+ }
74+
4375 core . debug ( "Creating a comment in the PR." )
4476 await octokit . issues . createComment ( {
4577 owner : github . context . repo . owner ,
0 commit comments