Skip to content

chore: use pull_request_target for auto-labeler on fork PRs - #488

Merged
shenxianpeng merged 1 commit into
mainfrom
fix/use-pull-request-target-for-fork-prs
Jul 30, 2026
Merged

chore: use pull_request_target for auto-labeler on fork PRs#488
shenxianpeng merged 1 commit into
mainfrom
fix/use-pull-request-target-for-fork-prs

Conversation

@shenxianpeng

@shenxianpeng shenxianpeng commented Jul 30, 2026

Copy link
Copy Markdown
Member

Summary

When a PR is opened from a fork repository (e.g. #487 by @XEDAB), the pull_request event's GITHUB_TOKEN has read-only permissions, causing the autolabeler to fail with:

Resource not accessible by integration

Changing to pull_request_target runs the workflow in the context of the base repository, giving the token write permissions needed to add labels.

Why this is safe

The autolabeler (release-drafter/release-drafter/autolabeler) only:

  • Reads PR metadata (title, branch name, changed files)
  • Matches against the release-drafter config
  • Adds labels to the PR

It does not checkout any code from the fork, so there is no security risk from using pull_request_target.

Related

Summary by CodeRabbit

  • Chores
    • Updated the pull request auto-labeling workflow trigger.
    • Existing labeling behavior remains unchanged.

When a PR is opened from a fork repository, the GITHUB_TOKEN in
pull_request events only has read permissions, preventing the
autolabeler from adding labels. Using pull_request_target runs
the workflow in the context of the base repository with write
permissions, which is safe since the autolabeler only reads PR
metadata and adds labels without checking out any code.

Fixes auto-labeler failing on PR #487 from a fork.
@shenxianpeng
shenxianpeng requested a review from a team as a code owner July 30, 2026 16:00
@netlify

netlify Bot commented Jul 30, 2026

Copy link
Copy Markdown

Deploy Preview for commit-check ready!

Name Link
🔨 Latest commit 54854b4
🔍 Latest deploy log https://app.netlify.com/projects/commit-check/deploys/6a6b75032870f300082d73c8
😎 Deploy Preview https://deploy-preview-488--commit-check.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@coderabbitai

coderabbitai Bot commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The pull request labeler workflow trigger changes from pull_request to pull_request_target, and its adjacent comment is updated. The labeling job remains unchanged.

Changes

Labeler workflow

Layer / File(s) Summary
Update labeler trigger
.github/workflows/labeler.yml
The workflow trigger changes to pull_request_target, and the adjacent comment is updated accordingly.

Estimated code review effort: 1 (Trivial) | ~2 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: switching the auto-labeler workflow to pull_request_target for forked PRs.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/use-pull-request-target-for-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.

@shenxianpeng shenxianpeng changed the title fix: use pull_request_target for auto-labeler on fork PRs chore: use pull_request_target for auto-labeler on fork PRs Jul 30, 2026
@sonarqubecloud

Copy link
Copy Markdown

@shenxianpeng
shenxianpeng merged commit 18d7cee into main Jul 30, 2026
9 of 11 checks passed
@shenxianpeng
shenxianpeng deleted the fix/use-pull-request-target-for-fork-prs branch July 30, 2026 16:01

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

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 current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In @.github/workflows/labeler.yml:
- Around line 4-5: Pin the privileged reusable workflow referenced by the
pull_request_target workflow to an audited, full-length immutable commit SHA
instead of the mutable main branch. Update the pr-labeler.yml invocation while
preserving the existing pull-requests write permission, and ensure the workflow
does not check out or execute code from the forked pull request.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 6c5543a2-46cd-4ff4-aa5f-70735bd17d28

📥 Commits

Reviewing files that changed from the base of the PR and between cb0c44f and 54854b4.

📒 Files selected for processing (1)
  • .github/workflows/labeler.yml

Comment on lines +4 to +5
# pull_request_target event is required for auto-labeler on fork PRs
pull_request_target:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔒 Security & Privacy | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== workflow file =="
cat -n .github/workflows/labeler.yml

echo
echo "== referenced reusable workflow metadata/contents if present =="
if [ -f .github/commit-check/.github/.github/workflows/pr-labeler.yml ]; then
  wc -l .github/commit-check/.github/.github/workflows/pr-labeler.yml
  cat -n .github/commit-check/.github/.github/workflows/pr-labeler.yml
else
  echo "referenced file not present in tree"
fi

echo
echo "== search for pr-labeler workflow usage/checkouts =="
rg -n "pr-labeler\.yml|pull_request_target|pull-requests: write|actions/checkout|checkout|\${{\s*github\.event\.pull_request|github\.event\.pull_request" .github -S || true

Repository: commit-check/commit-check

Length of output: 1105


🌐 Web query:

commit-check .github workflows pr-labeler.yml main

💡 Result:

The term "commit-check" in a GitHub Actions workflow typically refers to the use of the Commit Check tool [1][2], a policy engine used to validate Git commit metadata such as commit messages, branch names, and author information [1][3][4]. While users may name their workflow files anything (e.g., pr-labeler.yml) [5], the specific action provided by the Commit Check project is commonly implemented in a dedicated workflow file like.github/workflows/commit-check.yml [3][6]. To integrate Commit Check into your workflow, you can add the following step to your GitHub Actions file [3][4]: - uses: commit-check/commit-check-action@v2 with: message: true branch: true # Optional configurations author-name: false author-email: false job-summary: true pr-comments: ${{ github.event_name == 'pull_request' }} Key requirements for this action include: 1. Using actions/checkout@v5 with fetch-depth: 0 to ensure the full history is available for validation [3][4][6]. 2. Optionally providing a cchk.toml file in your repository root to customize policies [2][6]. If you are encountering a workflow named pr-labeler.yml that includes a commit check, it is likely a custom implementation where the developer has combined automated PR labeling with a commit validation step (often using actions/github-script or custom bash scripts) to enforce project standards [7][8][9]. Unlike the dedicated Commit Check action, these custom implementations often use regex patterns or API calls to validate commit titles directly within the PR workflow [7][8].

Citations:


🌐 Web query:

site:github.com/commit-check/.github .github/workflows/pr-labeler.yml

💡 Result:

The file path.github/workflows/pr-labeler.yml is a common convention for a GitHub Actions workflow file designed to automatically label pull requests. While the specific file name is user-defined, it typically leverages the official actions/labeler GitHub Action to categorize pull requests based on the files they modify. To implement this functionality, you generally need two components: 1. A workflow file (e.g.,.github/workflows/pr-labeler.yml) that triggers on pull request events. 2. A configuration file (often located at.github/labeler.yml) that defines the rules for which files should trigger which labels. Example configuration for.github/workflows/pr-labeler.yml: name: Pull Request Labeler on: pull_request_target: types: [opened, synchronize, reopened] jobs: label: runs-on: ubuntu-latest permissions: contents: read pull-requests: write steps: - uses: actions/labeler@v5 with: repo-token: ${{ secrets.GITHUB_TOKEN }} The corresponding.github/labeler.yml file would map patterns to labels, such as: documentation: - docs/ - README.md frontend: - src/ui/ The provided search results did not contain specific implementation details for this file path within the referenced repositories.

Citations:


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== git diff stat and any workflow-related diff context =="
git diff --stat || true
git diff -- .github/workflows/labeler.yml .github/commit-check/.github/.github/workflows/pr-labeler.yml || true

echo
echo "== workflow references to pull_request_target/reusable workflow/permissions =="
rg -n "pull_request_target|pull-requests:\s*write|uses:\s*commit-check/.github/.github/workflows/pr-labeler.yml|actions/github-script|actions/checkout|\$\{\{\s*github\.event\.github\.event_name|github\.event\." .github/workflows/labeler.yml .github/commit-check/.github/.github/workflows/pr-labeler.yml 2>/dev/null || true

Repository: commit-check/commit-check

Length of output: 621


Pin the privileged reusable workflow to an immutable commit SHA.

pull_request_target grants pull-requests: write to the reusable workflow at @main, so that mutable branch can receive write access if changed. Pin pr-labeler.yml to an audited full-length commit SHA and ensure it does not check out or execute fork code.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @.github/workflows/labeler.yml around lines 4 - 5, Pin the privileged
reusable workflow referenced by the pull_request_target workflow to an audited,
full-length immutable commit SHA instead of the mutable main branch. Update the
pr-labeler.yml invocation while preserving the existing pull-requests write
permission, and ensure the workflow does not check out or execute code from the
forked pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant