diff --git a/.github/workflows/link-comment.yml b/.github/workflows/link-comment.yml new file mode 100644 index 00000000000..3d22e425418 --- /dev/null +++ b/.github/workflows/link-comment.yml @@ -0,0 +1,40 @@ +name: Update PR Description + +on: + pull_request: + types: [opened, synchronize] + +jobs: + update-description: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Update PR description + uses: actions/github-script@v6 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + const prNumber = context.payload.pull_request.number; + const owner = context.payload.pull_request.head.repo.owner.login; + const repo = context.payload.pull_request.head.repo.name; + const commit = context.payload.pull_request.head.sha; + const link = `https://raw.githack.com/${owner}/${repo}/${commit}/kitchen-sink.html`; + + const { data: pullRequest } = await github.rest.pulls.get({ + owner: context.repo.owner, + repo: context.repo.repo, + pull_number: prNumber, + }); + + if (!pullRequest.body.includes(link)) { + const updatedBody = `${pullRequest.body}\n\n[View the changes](${link})`; + + await github.rest.pulls.update({ + owner: context.repo.owner, + repo: context.repo.repo, + pull_number: prNumber, + body: updatedBody, + }); + }