From cb6c0a2bb54d7ac47d76586cbfe98347a8b79d49 Mon Sep 17 00:00:00 2001 From: per1234 Date: Mon, 1 Feb 2021 20:40:02 -0800 Subject: [PATCH] Use curl to get PR diff This approach allows the diff to be written directly to a file, rather than needing to sanitize the contents of the output from the octokit/request-action before writing it to the file via the shell. --- .github/workflows/manage-prs.yml | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/.github/workflows/manage-prs.yml b/.github/workflows/manage-prs.yml index f95d1319..029c5e32 100644 --- a/.github/workflows/manage-prs.yml +++ b/.github/workflows/manage-prs.yml @@ -48,20 +48,16 @@ jobs: echo "::set-output name=filename::diff.txt" - name: Get PR diff - id: get-diff - uses: octokit/request-action@v2.x env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - mediaType: | - format: diff - route: GET /repos/{owner}/{repo}/pulls/{pull_number} - owner: ${{ github.repository_owner }} - repo: ${{ github.event.repository.name }} - pull_number: ${{ github.event.pull_request.number }}${{ github.event.issue.number }} - - - name: Write diff to file - run: printf -- '%b' ${{ steps.get-diff.outputs.data }} > "${{ steps.configuration.outputs.path }}/${{ steps.configuration.outputs.filename }}" + run: | + # It's necessary to reference both pull_request.number and issue.number because only one of the two are defined depending on whether the workflow is triggered by PR or comment event. + curl \ + --fail \ + --output "${{ steps.configuration.outputs.path }}/${{ steps.configuration.outputs.filename }}" \ + --header "Authorization: token $GITHUB_TOKEN" \ + --header "Accept: application/vnd.github.v3.diff" \ + https://api.github.com/repos/${{ github.repository_owner }}/${{ github.event.repository.name }}/pulls/${{ github.event.pull_request.number }}${{ github.event.issue.number }} - name: Upload diff file to workflow artifact uses: actions/upload-artifact@v2