From b53f4937d7e807c7e045304a1a37b41a3246ccd6 Mon Sep 17 00:00:00 2001 From: Thomas Cristina de Carvalho Date: Thu, 16 Nov 2023 13:45:15 -0500 Subject: [PATCH] Update --- .github/workflows/push-to-external-repo.yml | 32 +++++++++++++++++---- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/.github/workflows/push-to-external-repo.yml b/.github/workflows/push-to-external-repo.yml index 3c4f4fd..0765be2 100644 --- a/.github/workflows/push-to-external-repo.yml +++ b/.github/workflows/push-to-external-repo.yml @@ -36,13 +36,35 @@ jobs: publish_branch: ${{ steps.branch.outputs.branch }} allow_empty_commit: true - - name: Generate Preview URL - id: preview_url + - name: Generate pull request comment + id: pr_comment run: | - preview_url="https://headless-clone-git-${{ steps.branch.outputs.branch }}-thomaskn1.vercel.app" - echo "preview_url=${preview_url}" >> $GITHUB_OUTPUT + if [ "${{ github.event_name }}" == "pull_request" ]; then + preview_url="https://headless-clone-git-${{ steps.branch.outputs.branch }}-thomaskn1.vercel.app" + echo "body=A preview URL is being deployed to test this PR. It should be live in a short moment: ${preview_url}" >> $GITHUB_OUTPUT + + - name: Check Existing Comments + id: check-comments + uses: actions/github-script@v7 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + const existingComments = await github.issues.listComments({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo + }); + + const marker = ${{ steps.pr_comment.outputs.body }} + const existingComment = existingComments.data.find(comment => comment.body.includes(marker)); + console.log(existingComment ? 'Existing comment found' : 'No existing comment found'); + + // Set an output to pass information to subsequent steps + console.log(`echo "existingCommentFound=${existingComment ? 'true' : 'false'}" >> $GITHUB_OUTPUT`); + console.log(`echo "existingCommentId=${existingComment ? existingComment.id : ''}" >> $GITHUB_OUTPUT`); - name: Comment on Pull Request + if: steps.check-comments.outputs.existingCommentFound != 'true' uses: actions/github-script@v7 with: github-token: ${{ secrets.GITHUB_TOKEN }} @@ -51,5 +73,5 @@ jobs: issue_number: context.issue.number, owner: context.repo.owner, repo: context.repo.repo, - body: `A preview URL is being deployed to test this PR. It should be live in a short moment: ${{ steps.preview_url.outputs.preview_url }}` + body: `${{ steps.pr_comment.outputs.body }}` });