From de57482b57ad89fc4ac6cca22e084beb085723f7 Mon Sep 17 00:00:00 2001 From: JayaShakthi97 Date: Wed, 20 Mar 2024 20:14:08 +0530 Subject: [PATCH] Update changeset checker --- .github/workflows/check-changeset.yml | 35 ++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/.github/workflows/check-changeset.yml b/.github/workflows/check-changeset.yml index a3fc8c9570f..b3e6d90ab34 100644 --- a/.github/workflows/check-changeset.yml +++ b/.github/workflows/check-changeset.yml @@ -60,13 +60,40 @@ jobs: - name: Extract PR Number Artifact run: unzip pr-number.zip - - name: Get Authenticated User Info + - name: 💬 Remove Existing Changeset Comment uses: actions/github-script@v3.1.0 with: - github-token: ${{ secrets.GITHUB_TOKEN }} + github-token: ${{ env.GH_TOKEN }} script: | - const userInfo = await github.users.getAuthenticated(); - console.log("Username:", userInfo.data.login); + const fs = require('fs'); + const PR_NUMBER = Number(fs.readFileSync('./PR_NUMBER', 'utf8').trim()); + const REPO_OWNER = context.repo.owner; + const REPO_NAME = context.repo.repo; + + // Fetch all comments on the pull request. + const comments = await github.issues.listComments({ + owner: REPO_OWNER, + repo: REPO_NAME, + issue_number: PR_NUMBER, + }); + + console.log("COMMENTS_URL: https://api.github.com/repos/" + REPO_NAME + "/issues/" + PR_NUMBER + "/comments"); + + for (const comment of comments.data) { + console.log("COMMENT_OWNER: " + comment.user.login); + + // Identify the changeset comment by its heading. + if (comment.body.includes("🦋 Changeset detected") || comment.body.includes("⚠️ No Changeset found")) { + console.log("COMMENT_ID_TO_DELETE: " + comment.id); + + // Remove the changeset comment using the comment ID. + await github.issues.deleteComment({ + owner: REPO_OWNER, + repo: REPO_NAME, + comment_id: comment.id, + }); + } + } - name: 💬 Add Changeset Comment uses: actions/github-script@v3.1.0