Skip to content

Commit a7ef80e

Browse files
committed
Get PR diff from GitHub API
This avoids the need to checkout the PR head ref.
1 parent f5928a6 commit a7ef80e

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

.github/workflows/manage-prs.yml

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,19 +47,21 @@ jobs:
4747
echo "::set-output name=path::${{ runner.temp }}"
4848
echo "::set-output name=filename::diff.txt"
4949
50-
- name: Checkout local repository
51-
uses: actions/checkout@v2
52-
53-
- name: Checkout PR branch
54-
run: |
55-
# https://docs.github.com/en/free-pro-team@latest/github/collaborating-with-issues-and-pull-requests/checking-out-pull-requests-locally
56-
# 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.
57-
git fetch origin pull/${{ github.event.pull_request.number }}${{ github.event.issue.number }}/head:pr-branch
58-
git checkout pr-branch
50+
- name: Get PR diff
51+
id: get-diff
52+
uses: octokit/request-action@v2.x
53+
env:
54+
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 }}
5962

60-
- name: Generate diff file
61-
run: |
62-
git diff --unified=0 --ignore-blank-lines --ignore-space-at-eol --output="${{ steps.configuration.outputs.path }}/${{ steps.configuration.outputs.filename }}" ${{ github.sha }}
63+
- name: Write diff to file
64+
run: printf -- '%b' ${{ steps.get-diff.outputs.data }} > "${{ steps.configuration.outputs.path }}/${{ steps.configuration.outputs.filename }}"
6365

6466
- name: Upload diff file to workflow artifact
6567
uses: actions/upload-artifact@v2

0 commit comments

Comments
 (0)