workflow to add raw.githack link to pull requests #3
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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: Set up GitHub token | |
| run: echo "GH_TOKEN=${{ secrets.GH_TOKEN }}" >> $GITHUB_ENV | |
| - name: Update PR description | |
| uses: actions/github-script@v6 | |
| with: | |
| github-token: ${{ secrets.GH_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, | |
| }); | |
| } |