From efce2b1f5f97d54a6464a8760a7cc2500790c262 Mon Sep 17 00:00:00 2001 From: Alexis Montoison <35051714+amontoison@users.noreply.github.com> Date: Tue, 30 Apr 2024 14:38:37 -0400 Subject: [PATCH] Update CommentPR.yml --- .github/workflows/CommentPR.yml | 40 ++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/.github/workflows/CommentPR.yml b/.github/workflows/CommentPR.yml index 6b1d22a..043113f 100644 --- a/.github/workflows/CommentPR.yml +++ b/.github/workflows/CommentPR.yml @@ -13,8 +13,8 @@ jobs: upload: runs-on: ubuntu-latest if: > - ${{ github.event.workflow_run.event == 'pull_request' && - github.event.workflow_run.conclusion == 'success' }} + github.event.workflow_run.event == 'pull_request' && + github.event.workflow_run.conclusion == 'success' steps: - name: 'Download artifact' uses: actions/github-script@v3.1.0 @@ -39,16 +39,36 @@ jobs: - run: unzip pr.zip - name: 'Comment on PR' - uses: actions/github-script@v3 + uses: actions/github-script@v6 with: github-token: ${{ secrets.GITHUB_TOKEN }} script: | - var fs = require('fs'); - var issue_number = Number(fs.readFileSync('./NR')); - var msg = fs.readFileSync('./MSG', 'utf8'); - await github.issues.createComment({ + var fs = require('fs') + var issue_number = Number(fs.readFileSync('./NR')) + var msg = fs.readFileSync('./MSG', 'utf8') + + // Get the existing comments. + const {data: comments} = await github.rest.issues.listComments({ owner: context.repo.owner, repo: context.repo.repo, - issue_number: issue_number, - body: msg - }); + issue_number: issue_number + }) + + // Find any comment already made by the bot. + const botComment = comments.find(comment => comment.user.id === 41898282) + + if (botComment) { + await github.rest.issues.updateComment({ + owner: context.repo.owner, + repo: context.repo.repo, + comment_id: botComment.id, + body: msg + }) + } else { + await github.rest.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: issue_number, + body: msg + }) + }