Skip to content

ci: give the auto-labeler permission to label pull requests - #398

Merged
adamgell merged 1 commit into
mainfrom
claude/fix-labeler-pr-permissions
Jul 31, 2026
Merged

adamgell merged 1 commit into
mainfrom
claude/fix-labeler-pr-permissions

Conversation

@adamgell

Copy link
Copy Markdown
Owner

The auto-labeler added in #383 has never successfully labelled a pull request. All three pull_request_target runs to date failed:

POST /repos/adamgell/cmtraceopen/issues/<n>/labels
403 Resource not accessible by integration

The script itself works — the failing run for #397 got as far as
{"labels":["enhancement","intune","parser","device","feature"]} and then could not write them.

Cause. Labelling a pull request requires pull-requests: write, even though the REST path lives under /issues. The workflow declared only issues: write. An explicit permissions: block replaces the repository default rather than adding to it, and this repo has default_workflow_permissions: read, so the token ended up with no pull-request scope at all. The issues: opened trigger was unaffected, which is why the gap was not obvious.

Fix. Add pull-requests: write. That is the minimum needed; issue labelling keeps working through the existing issues: write.

Evidence:

$ gh run list --workflow=label-new-items.yml
failure  pull_request_target  feat(intune): discover and parse the Device Inventory Agent
failure  pull_request_target  feat(sccm): assess pure server intake coverage
failure  pull_request_target  feat(intune): deterministic Company Portal Windows package-s

$ gh api repos/:owner/:repo/actions/permissions/workflow
{"default_workflow_permissions":"read","can_approve_pull_request_reviews":false}

This PR is itself the test: if it labels correctly on open, the fix is confirmed — though note it will run with the base branch workflow, so the real confirmation is the next PR opened after this merges.

The workflow added in #383 has never succeeded on a pull request. All three
pull_request_target runs so far failed with:

  POST /repos/adamgell/cmtraceopen/issues/<n>/labels
  403 Resource not accessible by integration

The script computes the labels correctly — the failing run for #397 had
body '{"labels":["enhancement","intune","parser","device","feature"]}' — and
then cannot write them.

Cause: labelling a pull request requires `pull-requests: write`, even though
the REST path is under /issues. The workflow declared only `issues: write`,
and because an explicit `permissions:` block replaces the repository default
rather than adding to it, and this repo's default_workflow_permissions is
`read`, the token had no pull-request scope at all. The issues: opened trigger
was unaffected.

Adding `pull-requests: write` is the minimum needed; issue labelling keeps
working through the existing `issues: write`.

Verified: `gh run list --workflow=label-new-items.yml` shows failure on all
three pull_request_target runs to date (#397, and the two before it), and
`gh api repos/:owner/:repo/actions/permissions/workflow` reports
default_workflow_permissions=read.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings July 31, 2026 15:43
@coderabbitai

coderabbitai Bot commented Jul 31, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@adamgell, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 1 minute

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 4d940edb-be3b-42bf-96ff-1c55ec6df48e

📥 Commits

Reviewing files that changed from the base of the PR and between 03e55c3 and b0e5281.

📒 Files selected for processing (1)
  • .github/workflows/label-new-items.yml

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

Copilot AI 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.

Pull request overview

Fixes the GitHub Actions auto-labeling workflow so it can successfully apply labels to pull requests triggered via pull_request_target, aligning the workflow token permissions with GitHub’s requirement that PR labeling needs pull-requests: write even when using the /issues/{n}/labels REST endpoint.

Changes:

  • Adds pull-requests: write to the workflow permissions: block (keeping existing issues: write).
  • Documents why the additional permission is required and why the explicit permissions: block must include it (repo defaults are read-only).

@adamgell
adamgell merged commit 9280121 into main Jul 31, 2026
17 of 18 checks passed
@adamgell
adamgell deleted the claude/fix-labeler-pr-permissions branch September 25, 2026 13:40
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.

2 participants