ci: try update existing report first
This commit is contained in:
parent
615ff35fac
commit
60bf1e286c
|
@ -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 );
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue