summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.github/workflows/code_size_comment.yml44
1 files changed, 37 insertions, 7 deletions
diff --git a/.github/workflows/code_size_comment.yml b/.github/workflows/code_size_comment.yml
index 6ef6e633d..8baf76a47 100644
--- a/.github/workflows/code_size_comment.yml
+++ b/.github/workflows/code_size_comment.yml
@@ -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,
+ });
+ }