Skip to content

Commit 602b149

Browse files
oalanicolasclaude
andauthored
fix(ci): use pull_request_target for fork PR labeling (#585)
* 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> * fix(ci): paginate listFiles to handle PRs with 100+ changed files Use github.paginate() instead of a single API call to ensure squad detection works even for large PRs. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix(ci): detect squad file renames via previous_filename Address CodeRabbit review: also check previous_filename for renames moving files out of squads/, preventing policy bypass. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix(ci): pin actions to SHA refs for pull_request_target security Pin actions/labeler and actions/github-script to immutable commit SHAs to prevent supply-chain attacks in the write-token context. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 7a3ea8a commit 602b149

File tree

1 file changed

+20
-21
lines changed

1 file changed

+20
-21
lines changed

.github/workflows/pr-labeling.yml

Lines changed: 20 additions & 21 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,33 @@ 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
23-
uses: actions/labeler@v4
20+
uses: actions/labeler@ac9175f8a1f3625fd0d4fb234536d26811351594 # 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'
40-
uses: actions/github-script@v7
26+
- name: Check for squad changes and add label
27+
uses: actions/github-script@f28e40c7f34bde8b3046d885e986cb6290c5673b # v7
4128
with:
4229
script: |
43-
github.rest.issues.addLabels({
44-
issue_number: context.issue.number,
30+
const files = await github.paginate(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 =>
37+
f.filename.startsWith('squads/') ||
38+
f.previous_filename?.startsWith('squads/')
39+
);
40+
if (hasSquadChanges) {
41+
await github.rest.issues.addLabels({
42+
issue_number: context.payload.pull_request.number,
43+
owner: context.repo.owner,
44+
repo: context.repo.repo,
45+
labels: ['needs-po-review']
46+
});
47+
}
4948

0 commit comments

Comments
 (0)