-
Notifications
You must be signed in to change notification settings - Fork 259
fix(ci): grant Claude Code workflow write access to open PRs #1087
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
| # Limit automated issue triage to labels on the issue that triggered the workflow. | ||
| set -euo pipefail | ||
|
|
||
| issue_number=$(jq -r '.issue.number // empty' "${GITHUB_EVENT_PATH:?GITHUB_EVENT_PATH not set}") | ||
| if ! [[ "$issue_number" =~ ^[0-9]+$ ]]; then | ||
| echo "Error: no issue number in event payload" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| labels=() | ||
| while [[ $# -gt 0 ]]; do | ||
| case "$1" in | ||
| --add-label) | ||
| if [[ $# -lt 2 ]]; then | ||
| echo "Error: --add-label requires a label" >&2 | ||
| exit 1 | ||
| fi | ||
| labels+=("$2") | ||
| shift 2 | ||
| ;; | ||
| *) | ||
| echo "Error: only --add-label is accepted" >&2 | ||
| exit 1 | ||
| ;; | ||
| esac | ||
| done | ||
|
|
||
| if [[ ${#labels[@]} -eq 0 ]]; then | ||
| echo "Error: at least one label is required" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| valid_labels=$(gh label list --limit 500 --json name --jq '.[].name') | ||
| filtered_labels=() | ||
| for label in "${labels[@]}"; do | ||
| if grep -qxF "$label" <<<"$valid_labels"; then | ||
| filtered_labels+=("$label") | ||
| else | ||
| echo "Ignoring unknown label: $label" >&2 | ||
| fi | ||
| done | ||
|
|
||
| if [[ ${#filtered_labels[@]} -eq 0 ]]; then | ||
| exit 0 | ||
| fi | ||
|
|
||
| repository=${GITHUB_REPOSITORY:?GITHUB_REPOSITORY not set} | ||
| labels_url="repos/$repository/issues/$issue_number/labels" | ||
| api_args=(--method POST "$labels_url") | ||
| for label in "${filtered_labels[@]}"; do | ||
| api_args+=(-f "labels[]=$label") | ||
| done | ||
|
|
||
| gh api "${api_args[@]}" --silent | ||
| echo "Added: ${filtered_labels[*]}" |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When this job runs for
pull_request_target, it still checks outgithub.event.pull_request.head.shainto the workspace before starting Claude, so raising the job token tocontents: writegives a PR-head checkout the base-repo write context and OAuth-backed Claude session. Anthropic's action security docs warn not to check out an untrusted ref into the workspace root forpull_request_target(https://raw.githubusercontent.com/anthropics/claude-code-action/main/docs/security.md); this is reachable for any collaborator PR whose body contains@claudeor a compromised collaborator branch. Keep the root checkout on the base ref, or put the PR head in a subdirectory via--add-dir, before enabling write permissions.Useful? React with 👍 / 👎.