Skip to content

Commit 7174c1d

Browse files
oalanicolasclaude
andcommitted
fix(ci): use pull_request_target for fork PR labeling (#479)
Switch trigger from pull_request to pull_request_target so fork PRs get a write-capable GITHUB_TOKEN. Replace git-diff squad detection with GitHub API (pulls.listFiles) since pull_request_target does not check out fork commits. Remove unnecessary checkout step. Closes #479 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent ff711c1 commit 7174c1d

1 file changed

Lines changed: 15 additions & 19 deletions

File tree

.github/workflows/pr-labeling.yml

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: PR Labeling
22
# Story 6.1 - Added concurrency
33

44
on:
5-
pull_request:
5+
pull_request_target:
66
types: [opened, synchronize]
77

88
concurrency:
@@ -16,34 +16,30 @@ jobs:
1616
contents: read
1717
pull-requests: write
1818
steps:
19-
- name: Checkout code
20-
uses: actions/checkout@v4
21-
2219
- name: Label PR based on files changed
2320
uses: actions/labeler@v4
2421
with:
2522
repo-token: "${{ secrets.GITHUB_TOKEN }}"
2623
configuration-path: .github/labeler.yml
2724
sync-labels: true
2825

29-
- name: Check for squad changes
30-
id: check-squad
31-
run: |
32-
if git diff --name-only origin/${{ github.base_ref }}...HEAD | grep -q "^squads/"; then
33-
echo "has_squad=true" >> $GITHUB_OUTPUT
34-
else
35-
echo "has_squad=false" >> $GITHUB_OUTPUT
36-
fi
37-
38-
- name: Add needs-po-review label for squad PRs
39-
if: steps.check-squad.outputs.has_squad == 'true'
26+
- name: Check for squad changes and add label
4027
uses: actions/github-script@v7
4128
with:
4229
script: |
43-
github.rest.issues.addLabels({
44-
issue_number: context.issue.number,
30+
const { data: files } = await github.rest.pulls.listFiles({
4531
owner: context.repo.owner,
4632
repo: context.repo.repo,
47-
labels: ['needs-po-review']
48-
})
33+
pull_number: context.payload.pull_request.number,
34+
per_page: 100
35+
});
36+
const hasSquadChanges = files.some(f => f.filename.startsWith('squads/'));
37+
if (hasSquadChanges) {
38+
await github.rest.issues.addLabels({
39+
issue_number: context.payload.pull_request.number,
40+
owner: context.repo.owner,
41+
repo: context.repo.repo,
42+
labels: ['needs-po-review']
43+
});
44+
}
4945

0 commit comments

Comments
 (0)