From 463fddefaeb176f16bd1489acaba26194d7f0b09 Mon Sep 17 00:00:00 2001 From: 1ilsang <1ilsang@naver.com> Date: Sat, 8 Jun 2024 00:20:44 +0900 Subject: [PATCH] update comment --- .github/actions/netlify-preview/action.yml | 26 +++++++++++++++++----- 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/.github/actions/netlify-preview/action.yml b/.github/actions/netlify-preview/action.yml index 41d2c237..40441233 100644 --- a/.github/actions/netlify-preview/action.yml +++ b/.github/actions/netlify-preview/action.yml @@ -36,6 +36,7 @@ runs: echo "NETLIFY_PREVIEW_URL=$NETLIFY_PREVIEW_URL" >> "$GITHUB_OUTPUT" - name: Comment URL Preview on PR + # https://octokit.github.io/rest.js/v20 uses: actions/github-script@v7 env: NETLIFY_PREVIEW_URL: ${{ steps.url-preview.outputs.NETLIFY_PREVIEW_URL }} @@ -49,13 +50,26 @@ runs: commit_sha: process.env.HEAD_COMMIT, }); const issueNumber = result.data[0]?.number; + const commentId = false; + + console.log(result.data[0]); + if (issueNumber) { - await github.rest.issues.createComment({ - issue_number: issueNumber, - owner: context.repo.owner, - repo: context.repo.repo, - body: `Preview URL: ${process.env.NETLIFY_PREVIEW_URL}` - }); + if (commentId) { + await github.rest.issues.updateComment({ + owner: context.repo.owner, + repo: context.repo.repo, + comment_id: commentId, + body: `Preview URL: ${process.env.NETLIFY_PREVIEW_URL}` + }); + } else { + await github.rest.issues.createComment({ + issue_number: issueNumber, + owner: context.repo.owner, + repo: context.repo.repo, + body: `Preview URL: ${process.env.NETLIFY_PREVIEW_URL}` + }); + } } else { console.log('No PR found for commit ' + process.env.HEAD_COMMIT); }