Skip to content

Commit cb6c0a2

Browse files
committed
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.
1 parent da261b4 commit cb6c0a2

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

.github/workflows/manage-prs.yml

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,20 +48,16 @@ jobs:
4848
echo "::set-output name=filename::diff.txt"
4949
5050
- name: Get PR diff
51-
id: get-diff
52-
uses: octokit/request-action@v2.x
5351
env:
5452
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
55-
with:
56-
mediaType: |
57-
format: diff
58-
route: GET /repos/{owner}/{repo}/pulls/{pull_number}
59-
owner: ${{ github.repository_owner }}
60-
repo: ${{ github.event.repository.name }}
61-
pull_number: ${{ github.event.pull_request.number }}${{ github.event.issue.number }}
62-
63-
- name: Write diff to file
64-
run: printf -- '%b' ${{ steps.get-diff.outputs.data }} > "${{ steps.configuration.outputs.path }}/${{ steps.configuration.outputs.filename }}"
53+
run: |
54+
# 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.
55+
curl \
56+
--fail \
57+
--output "${{ steps.configuration.outputs.path }}/${{ steps.configuration.outputs.filename }}" \
58+
--header "Authorization: token $GITHUB_TOKEN" \
59+
--header "Accept: application/vnd.github.v3.diff" \
60+
https://api.github.com/repos/${{ github.repository_owner }}/${{ github.event.repository.name }}/pulls/${{ github.event.pull_request.number }}${{ github.event.issue.number }}
6561
6662
- name: Upload diff file to workflow artifact
6763
uses: actions/upload-artifact@v2

0 commit comments

Comments
 (0)