Skip to content

Commit 52d574b

Browse files
OhmSpectatoreriknordmark
authored andcommitted
github/actions: In codeowners workflow fetch PR head ref for forked repos.
This commit adjusts the GitHub Action workflow to properly handle pull requests from forked repositories. It removes the previous approach of calculating fetch-depth and directly fetching the PR merge ref. Instead, it now checks out the base ref with full history and then explicitly fetches and checks out the PR's head ref. This change ensures that the workflow has access to the correct set of changes, even when the PR is from a fork, and mitigates the potential issue with the 'bad object' error seen when trying to access the head commit of a forked repo. Signed-off-by: Nikolay Martyanov <[email protected]>
1 parent bbf677b commit 52d574b

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

.github/workflows/request_codeowners_review.yml

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,16 @@ jobs:
1111
permissions:
1212
pull-requests: write
1313
steps:
14-
- name: Calculate fetch-depth
15-
id: calc
16-
run: echo "depth=$(echo $((${{ github.event.pull_request.commits }} + 1)))" >> $GITHUB_OUTPUT
17-
18-
- name: Fetch the pull request head
19-
run: git fetch origin +refs/pull/${{ github.event.pull_request.number }}/merge
20-
2114
- name: Checkout code
2215
uses: actions/checkout@v4
2316
with:
24-
ref: ${{ github.event.pull_request.head.sha }}
25-
fetch-depth: ${{ steps.calc.outputs.depth }}
17+
ref: ${{ github.base_ref }}
18+
fetch-depth: 0
19+
20+
- name: Fetch the PR's head ref
21+
run: |
22+
git fetch origin ${{ github.event.pull_request.head.sha }}:${{ github.event.pull_request.head.ref }}
23+
git checkout ${{ github.event.pull_request.head.ref }}
2624
2725
- name: Auto request review
2826
env:
@@ -32,7 +30,7 @@ jobs:
3230
# Get changed files in this pull request
3331
echo "Checking base: ${{ github.event.pull_request.base.sha }}"
3432
echo "Checking head: ${{ github.event.pull_request.head.sha }}"
35-
for changed_file in $(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }}); do
33+
for changed_file in $(git diff --name-only ${{ github.event.pull_request.base.sha }}...HEAD); do
3634
echo "Checking $changed_file"
3735
while read -r line; do
3836
# Get pattern of the files owned

0 commit comments

Comments
 (0)