github/workflows: Update existing comments for code_size_comment.

This modifies the automated code size comment to edit an existing comment
if one already exists instead of always creating a new comment.  This
reduces noise on pull requests that are repeatedly updated.

Signed-off-by: David Lechner <david@pybricks.com>
This commit is contained in:
David Lechner 2022-12-18 20:17:30 -06:00 committed by Damien George
parent 1290329415
commit 3b285326e3

View File

@ -62,14 +62,44 @@ jobs:
script: |
const fs = require('fs');
github.rest.issues.createComment({
issue_number: Number(fs.readFileSync('pr_number')),
owner: context.repo.owner,
repo: context.repo.repo,
body: `Code size report:
const prNumber = Number(fs.readFileSync('pr_number'));
const codeSizeReport = `Code size report:
\`\`\`
${fs.readFileSync('diff')}
\`\`\`
`,
`;
const comments = await github.paginate(
github.rest.issues.listComments,
{
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
}
);
comments.reverse();
const previousComment = comments.find(comment =>
comment.user.login === 'github-actions[bot]'
)
// if github-actions[bot] already made a comment, update it,
// otherwise create a new comment.
if (previousComment) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: previousComment.id,
body: codeSizeReport,
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
body: codeSizeReport,
});
}