Skip to content

Commit 99d0320

Browse files
Merge pull request #3581 from MicrosoftDocs/revert/pr-labeler-autogen-warning
Fix pr-labeler for fork PRs (pull_request_target)
2 parents 8b0021e + 202c7c0 commit 99d0320

1 file changed

Lines changed: 11 additions & 5 deletions

File tree

.github/workflows/pr-labeler.yml

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: "PR Labeler"
22

33
on:
4-
pull_request:
4+
pull_request_target:
55
types: [opened, synchronize]
66

77
jobs:
@@ -14,16 +14,21 @@ jobs:
1414
pull-requests: write
1515

1616
steps:
17-
- name: Checkout code
17+
- name: Checkout PR head
1818
uses: actions/checkout@v4
1919
with:
20+
# Fetch the PR head so we can diff against the base
21+
ref: ${{ github.event.pull_request.head.sha }}
2022
fetch-depth: 0
2123

24+
- name: Fetch base branch
25+
run: git fetch origin ${{ github.event.pull_request.base.ref }}
26+
2227
- name: Get changed files
2328
id: changed
2429
run: |
2530
# Get the list of changed files in the PR
26-
git diff --name-only origin/${{ github.base_ref }}...HEAD > changed_files.txt
31+
git diff --name-only origin/${{ github.event.pull_request.base.ref }}...${{ github.event.pull_request.head.sha }} > changed_files.txt
2732
echo "Changed files:"
2833
cat changed_files.txt
2934
@@ -74,7 +79,7 @@ jobs:
7479
7580
// Get the full diff
7681
const diff = execSync(
77-
`git diff origin/${process.env.BASE_REF}...HEAD`,
82+
`git diff origin/${process.env.BASE_REF}...${process.env.HEAD_SHA}`,
7883
{ encoding: 'utf8', maxBuffer: 10 * 1024 * 1024 }
7984
);
8085
@@ -251,4 +256,5 @@ jobs:
251256
}
252257
}
253258
env:
254-
BASE_REF: ${{ github.base_ref }}
259+
BASE_REF: ${{ github.event.pull_request.base.ref }}
260+
HEAD_SHA: ${{ github.event.pull_request.head.sha }}

0 commit comments

Comments
 (0)