Skip to content

fix(ci): use pull_request_target for fork PR labeling#585

Merged
Pedrovaleriolopez merged 4 commits intomainfrom
fix/479-pr-labeling-fork-prs
Mar 11, 2026
Merged

fix(ci): use pull_request_target for fork PR labeling#585
Pedrovaleriolopez merged 4 commits intomainfrom
fix/479-pr-labeling-fork-prs

Conversation

@oalanicolas
Copy link
Collaborator

@oalanicolas oalanicolas commented Mar 11, 2026

Summary

  • Switch pr-labeling.yml trigger from pull_request to pull_request_target so the workflow runs with the base repository's write-capable GITHUB_TOKEN
  • Replace git diff squad-change detection with GitHub API (pulls.listFiles with pagination) since pull_request_target doesn't check out fork commits
  • Remove unnecessary actions/checkout step (both labeler and squad check now use API only)

Root cause

The SynkraAI org enforces default_workflow_permissions: read and blocks repos from overriding to write. This means the permissions: pull-requests: write block in the workflow has no effect under pull_request trigger — the token stays read-only.

pull_request_target runs in the base repository context with elevated permissions, bypassing this restriction. This fixes labeling for all PRs (same-repo and fork).

Closes #479

Test plan

  • After merge, open a new PR and verify labels are applied
  • Open a PR touching squads/ and verify needs-po-review label is added
  • Verify no Resource not accessible by integration errors in workflow logs

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Chores
    • Streamlined automated PR-labeling workflow: consolidated multiple steps into a single check that detects squad-related file changes and automatically applies the needs-po-review label.
    • Simplified trigger to run in the PR-target context and removed redundant intermediate steps.
    • Updated the labeler reference to a fixed revision for more predictable behavior.

@vercel
Copy link

vercel bot commented Mar 11, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
aios-core Ready Ready Preview, Comment Mar 11, 2026 0:55am

Request Review

@coderabbitai
Copy link

coderabbitai bot commented Mar 11, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: ec67d2ae-1cf0-4e31-9527-415ff9ad614d

📥 Commits

Reviewing files that changed from the base of the PR and between ea9ba99 and 347f991.

📒 Files selected for processing (1)
  • .github/workflows/pr-labeling.yml

Walkthrough

Changed the PR labeling workflow to run on pull_request_target, removed checkout/git-diff steps, and consolidated squad-change detection and label application into a single actions/github-script step that paginates pulls.listFiles, checks filename/previous_filename for squads/ prefixes, and adds the needs-po-review label.

Changes

Cohort / File(s) Summary
GitHub Actions Workflow
.github/workflows/pr-labeling.yml
Trigger switched to pull_request_target; removed actions/checkout and separate squad-check steps; added one actions/github-script step that paginates pulls.listFiles (per_page: 100), inspects filename and previous_filename for squads/ changes, and applies the needs-po-review label. Also pinned the labeler action to a specific commit.

Sequence Diagram(s)

sequenceDiagram
    participant Contributor as Contributor (fork)
    participant GitHub as GitHub Events
    participant Workflow as PR Labeling Workflow (base repo)
    participant GitHubAPI as GitHub REST API
    participant Labeler as actions/labeler (pinned)

    Contributor->>GitHub: Open PR
    GitHub->>Workflow: trigger pull_request_target
    Workflow->>GitHubAPI: paginate pulls.listFiles (per_page=100)
    GitHubAPI-->>Workflow: file list (filename, previous_filename)
    alt any file path starts with "squads/"
        Workflow->>GitHubAPI: add label "needs-po-review" to PR
    end
    Workflow->>Labeler: run labeler action (pinned commit) for other labels
    Labeler-->>Workflow: labeling results
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related issues

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: switching the CI workflow trigger from pull_request to pull_request_target for fork PR labeling.
Linked Issues check ✅ Passed The PR fully addresses all coding requirements from issue #479: switching to pull_request_target, replacing git-based detection with GitHub API (pulls.listFiles with pagination), removing checkout steps, and pinning action versions to immutable SHAs.
Out of Scope Changes check ✅ Passed All changes are directly scoped to fixing the PR labeling workflow for fork PRs; no unrelated modifications are present in the changeset.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/479-pr-labeling-fork-prs

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Contributor

github-actions bot commented Mar 11, 2026

📊 Coverage Report

Coverage report not available

📈 Full coverage report available in Codecov


Generated by PR Automation (Story 6.1)

coderabbitai[bot]
coderabbitai bot previously requested changes Mar 11, 2026
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In @.github/workflows/pr-labeling.yml:
- Around line 30-36: The current hasSquadChanges check only inspects f.filename
and misses renames out of squads/, so update the predicate used when
constructing hasSquadChanges (after calling github.paginate on pulls.listFiles
into files) to also inspect f.previous_filename safely; for example, change the
files.some(...) to return true if either f.filename or f.previous_filename
startsWith('squads/'), handling undefined values (e.g., via null-coalescing or
explicit checks) so moves from squads/ are detected.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: f45deba2-a19a-46f5-ad0a-c3e4c8691357

📥 Commits

Reviewing files that changed from the base of the PR and between ff711c1 and 8a19ac5.

📒 Files selected for processing (1)
  • .github/workflows/pr-labeling.yml

oalanicolas and others added 3 commits March 11, 2026 09:42
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>
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>
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>
@oalanicolas oalanicolas force-pushed the fix/479-pr-labeling-fork-prs branch from 0702e7a to ea9ba99 Compare March 11, 2026 12:42
@oalanicolas oalanicolas dismissed coderabbitai[bot]’s stale review March 11, 2026 12:46

CodeRabbit feedback addressed in commit ea9ba92 (previous_filename check added)

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In @.github/workflows/pr-labeling.yml:
- Around line 20-27: Replace the movable tags for the two GitHub Actions with
the provided immutable commit SHAs: change the usage of actions/labeler@v4 to
actions/labeler@ac9175f8a1f3625fd0d4fb234536d26811351594 and change
actions/github-script@v7 to
actions/github-script@f28e40c7f34bde8b3046d885e986cb6290c5673b (leave the
existing inputs like repo-token and configuration-path unchanged); after
updating the refs, run CI or dependabot/renovate to manage future updates with
pinned SHAs.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 319cc916-6cc9-43ac-aea2-9fb1b2bbe52f

📥 Commits

Reviewing files that changed from the base of the PR and between 8a19ac5 and 0702e7a.

📒 Files selected for processing (1)
  • .github/workflows/pr-labeling.yml

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

♻️ Duplicate comments (1)
.github/workflows/pr-labeling.yml (1)

20-27: ⚠️ Potential issue | 🟠 Major

Pin action refs to immutable SHAs (prior feedback unaddressed).

Lines 20 and 27 still use movable major tags (@v4, @v7) in a pull_request_target workflow with pull-requests: write permissions. This creates a supply-chain security risk—an upstream compromise or tag retargeting could execute malicious code with write access to pull requests.

Pin both actions to their immutable commit SHAs:

🔒 Proposed fix
      - name: Label PR based on files changed
-       uses: actions/labeler@v4
+       uses: actions/labeler@8558fd74291d67161a8a78ce36a881fa63b766a9  # v4.3.0
        with:
          repo-token: "${{ secrets.GITHUB_TOKEN }}"
          configuration-path: .github/labeler.yml
          sync-labels: true

      - name: Check for squad changes and add label
-       uses: actions/github-script@v7
+       uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea  # v7.0.1
        with:

Use Dependabot or Renovate to automate future updates while maintaining immutable references.

,

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.github/workflows/pr-labeling.yml around lines 20 - 27, The workflow uses
movable tags actions/labeler@v4 and actions/github-script@v7 in a
pull_request_target context—replace those version tags with the corresponding
immutable commit SHAs (e.g., actions/labeler@<full-commit-sha> and
actions/github-script@<full-commit-sha>) so the workflow references a fixed
commit; update both occurrences in the file (the uses lines for actions/labeler
and actions/github-script), commit the changes, and add Dependabot or Renovate
to manage future pin updates automatically.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Duplicate comments:
In @.github/workflows/pr-labeling.yml:
- Around line 20-27: The workflow uses movable tags actions/labeler@v4 and
actions/github-script@v7 in a pull_request_target context—replace those version
tags with the corresponding immutable commit SHAs (e.g.,
actions/labeler@<full-commit-sha> and actions/github-script@<full-commit-sha>)
so the workflow references a fixed commit; update both occurrences in the file
(the uses lines for actions/labeler and actions/github-script), commit the
changes, and add Dependabot or Renovate to manage future pin updates
automatically.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 743a6229-a247-4dd3-bc20-6737fa1a58cf

📥 Commits

Reviewing files that changed from the base of the PR and between 0702e7a and ea9ba99.

📒 Files selected for processing (1)
  • .github/workflows/pr-labeling.yml

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>
@Pedrovaleriolopez Pedrovaleriolopez merged commit 602b149 into main Mar 11, 2026
27 checks passed
@Pedrovaleriolopez Pedrovaleriolopez deleted the fix/479-pr-labeling-fork-prs branch March 11, 2026 13:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(ci): pr-labeling workflow fails on fork PRs with 'Resource not accessible by integration'

2 participants