Skip to content

Commit

Permalink
github/workflows: Update existing comments for code_size_comment.
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
dlech authored and dpgeorge committed Dec 19, 2022
1 parent 1290329 commit 3b28532
Showing 1 changed file with 37 additions and 7 deletions.
44 changes: 37 additions & 7 deletions .github/workflows/code_size_comment.yml
Expand Up @@ -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,
});
}

0 comments on commit 3b28532

Please sign in to comment.