fix(ci): grant issues:write to pr-labeler workflow#20
fix(ci): grant issues:write to pr-labeler workflow#20Aleksei Sviridkin (lexfrei) wants to merge 1 commit into
Conversation
addLabels and removeLabel call the issues API endpoint
(POST /repos/.../issues/{number}/labels) even when the target is a
pull request. Without 'issues: write' the workflow token cannot
mutate labels and the call returns HTTP 403 'Resource not accessible
by integration'.
The previous 'pull-requests: write' grant covers the PR conversation
surface — comments, reviewers, merge state — but not labels, which
GitHub treats as an issues resource. Add the missing scope and
document the reasoning inline so a future reader does not retry the
same mistake.
Assisted-By: Claude <noreply@anthropic.com>
Signed-off-by: Aleksei Sviridkin <f@lex.la>
|
Note Gemini is unable to generate a review for this pull request due to the file types involved not being currently supported. |
📝 WalkthroughWalkthroughGitHub Actions workflow permissions for the pr-labeler are documented by expanding the ChangesPR Labeler Permissions Documentation
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~2 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
.github/workflows/pr-labeler.yaml (1)
15-16: ⚡ Quick winDrop
pull-requests: writefrom.github/workflows/pr-labeler.yaml(least privilege).The workflow only adds/removes labels via
github.rest.issues.removeLabel/github.rest.issues.addLabels(Issues API). Thepull-requests: writepermission (and the accompanying “edit PR conversation” comment) doesn’t match the current implementation; keepissues: writeinstead.🤖 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/pr-labeler.yaml around lines 15 - 16, Remove the unnecessary "pull-requests: write" permission entry from the workflow and keep only "issues: write"; specifically delete the "pull-requests: write" permission token so the workflow aligns with the APIs actually used (github.rest.issues.removeLabel and github.rest.issues.addLabels) and does not grant edit-PR permissions that the code never uses.
🤖 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.
Nitpick comments:
In @.github/workflows/pr-labeler.yaml:
- Around line 15-16: Remove the unnecessary "pull-requests: write" permission
entry from the workflow and keep only "issues: write"; specifically delete the
"pull-requests: write" permission token so the workflow aligns with the APIs
actually used (github.rest.issues.removeLabel and github.rest.issues.addLabels)
and does not grant edit-PR permissions that the code never uses.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: c6ca444c-d01e-442c-b078-1aff892c1106
📒 Files selected for processing (1)
.github/workflows/pr-labeler.yaml
What this PR does
Adds
issues: writeto thepr-labelerworkflow's permissions block. Without it,github.rest.issues.addLabelsandremoveLabelreturn HTTP 403Resource not accessible by integrationeven though the workflow already declarespull-requests: write.Why
Labels live behind the issues API (
POST /repos/{owner}/{repo}/issues/{number}/labels). GitHub treats a pull request as a kind of issue for label operations, so mutating labels on a PR — adding or removing — requires theissuesscope, regardless of whether the target is a PR or a standalone issue.pull-requests: writecovers the PR conversation surface: comments, reviewers, merge state. It does not cover labels. The previous configuration worked on earlier PRs by coincidence — labelers that produce zero changes (add.length === 0and no labels to remove) skip the API call entirely and report success. The first PR for which the labeler computed a non-emptyaddset surfaced the gap.Repro
PR #18 was the first cozystack-ui PR after #16 (label scheme adoption) and #17 (script tolerance fix) to actually demand labels (
kind/feature+area/console) fromaddLabels. The workflow run at https://github.com/cozystack/cozystack-ui/actions/runs/26458860707 fails ongithub.rest.issues.addLabelswith the 403 above. Diff between #17 (passed) and #18 (failed): #17's labeler invocation went throughremoveLabelfor a stale label that no longer existed and returned 404 (caught by the existing try/catch) — itsaddset ended up empty, so noaddLabelscall ever fired. #18'saddset is non-empty, and the call hits the missing permission.Verification
This PR cannot self-check through its own labeler run: the workflow uses
pull_request_targetand checks out the labeler script and YAML frombase.sha, which is unfixed main. The labeler run against this PR will run with the old (broken) permissions block.The actual verification path is the next PR opened after this one merges to main. Its labeler invocation will pick up the fixed workflow and should successfully apply labels for any non-empty
addset. A backfill run against PR #18 once this lands should also flip its label workflow from failure to success.Summary by CodeRabbit