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,24 +82,55 @@ const runner = async () => {
}
);
await octokit.rest.issues.createComment( {
const currentComments = await octokit.rest.issues.listComments( {
owner,
repo,
issue_number: payload.pull_request.number,
body:
'# Script Dependencies Report' +
'\n\n' +
'The `compare-assets` action has detected some changed script dependencies between this branch and ' +
'trunk. Please review and confirm the following are correct before merging.' +
'\n\n' +
'| Script Handle | Added | Removed | |' +
'\n' +
'| ------------- | ------| ------- | -- |' +
'\n' +
reportContent +
'\n\n' +
'__This comment was automatically generated by the `./github/compare-assets` action.__',
} );
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 ' +
'trunk. Please review and confirm the following are correct before merging.' +
'\n\n' +
'| Script Handle | Added | Removed | |' +
'\n' +
'| ------------- | ------| ------- | -- |' +
'\n' +
reportContent +
'\n\n' +
'__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 );
}