ci: try update existing report first

This commit is contained in:
Tung Du 2022-07-22 17:10:58 +07:00
parent 615ff35fac
commit 60bf1e286c
1 changed files with 45 additions and 14 deletions

View File

@ -82,11 +82,27 @@ const runner = async () => {
}
);
await octokit.rest.issues.createComment( {
const currentComments = await octokit.rest.issues.listComments( {
owner,
repo,
issue_number: payload.pull_request.number,
body:
} );
let reportCommentId;
if (
Array.isArray( currentComments.data ) &&
currentComments.data.length > 0
) {
const comment = currentComments.data.find( ( comment ) =>
comment.body.includes( 'Script Dependencies Report' )
);
if ( comment ) {
reportCommentId = comment.id;
}
}
const commentBody =
'# Script Dependencies Report' +
'\n\n' +
'The `compare-assets` action has detected some changed script dependencies between this branch and ' +
@ -98,8 +114,23 @@ const runner = async () => {
'\n' +
reportContent +
'\n\n' +
'__This comment was automatically generated by the `./github/compare-assets` action.__',
'__This comment was automatically generated by the `./github/compare-assets` action.__';
if ( reportCommentId ) {
await octokit.rest.issues.updateComment( {
owner,
repo,
comment_id: reportCommentId,
body: commentBody,
} );
} else {
await octokit.rest.issues.createComment( {
owner,
repo,
issue_number: payload.pull_request.number,
body: commentBody,
} );
}
} catch ( error ) {
setFailed( error.message );
}