surshar / claude-code
Claude Code is an agentic coding tool that lives in your terminal, understands your codebase, and helps you code faster by executing routine tasks, explaining complex code, and handling git workflows - all through natural language commands.
Built by Anthropic · github.com/anthropics
| 1 | #!/usr/bin/env bash |
| 2 | # |
| 3 | # Edits labels on a GitHub issue. |
| 4 | # Usage: ./edit-issue-labels.sh --add-label bug --add-label needs-triage --remove-label untriaged |
| 5 | # |
| 6 | # The issue number is read from the workflow event payload. |
| 7 | # |
| 8 | |
| 9 | set -euo pipefail |
| 10 | |
| 11 | # Read from event payload so the issue number is bound to the triggering event. |
| 12 | # Falls back to workflow_dispatch inputs for manual runs. |
| 13 | ISSUE=$(jq -r '.issue.number // .inputs.issue_number // empty' "${GITHUB_EVENT_PATH:?GITHUB_EVENT_PATH not set}") |
| 14 | if ! [[ "$ISSUE" =~ ^[0-9]+$ ]]; then |
| 15 | echo "Error: no issue number in event payload" >&2 |
| 16 | exit 1 |
| 17 | fi |
| 18 | |
| 19 | ADD_LABELS=() |
| 20 | REMOVE_LABELS=() |
| 21 | |
| 22 | # Parse arguments |
| 23 | while [[ $# -gt 0 ]]; do |
| 24 | case $1 in |
| 25 | --add-label) |
| 26 | ADD_LABELS+=("$2") |
| 27 | shift 2 |
| 28 | ;; |
| 29 | --remove-label) |
| 30 | REMOVE_LABELS+=("$2") |
| 31 | shift 2 |
| 32 | ;; |
| 33 | *) |
| 34 | echo "Error: unknown argument (only --add-label and --remove-label are accepted)" >&2 |
| 35 | exit 1 |
| 36 | ;; |
| 37 | esac |
| 38 | done |
| 39 | |
| 40 | if [[ ${#ADD_LABELS[@]} -eq 0 && ${#REMOVE_LABELS[@]} -eq 0 ]]; then |
| 41 | exit 1 |
| 42 | fi |
| 43 | |
| 44 | # Fetch valid labels from the repo |
| 45 | VALID_LABELS=$(gh label list --limit 500 --json name --jq '.[].name') |
| 46 | |
| 47 | # Filter to only labels that exist in the repo |
| 48 | FILTERED_ADD=() |
| 49 | for label in "${ADD_LABELS[@]}"; do |
| 50 | if echo "$VALID_LABELS" | grep -qxF "$label"; then |
| 51 | FILTERED_ADD+=("$label") |
| 52 | fi |
| 53 | done |
| 54 | |
| 55 | FILTERED_REMOVE=() |
| 56 | for label in "${REMOVE_LABELS[@]}"; do |
| 57 | if echo "$VALID_LABELS" | grep -qxF "$label"; then |
| 58 | FILTERED_REMOVE+=("$label") |
| 59 | fi |
| 60 | done |
| 61 | |
| 62 | if [[ ${#FILTERED_ADD[@]} -eq 0 && ${#FILTERED_REMOVE[@]} -eq 0 ]]; then |
| 63 | exit 0 |
| 64 | fi |
| 65 | |
| 66 | # Build gh command arguments |
| 67 | GH_ARGS=("issue" "edit" "$ISSUE") |
| 68 | |
| 69 | for label in "${FILTERED_ADD[@]}"; do |
| 70 | GH_ARGS+=("--add-label" "$label") |
| 71 | done |
| 72 | |
| 73 | for label in "${FILTERED_REMOVE[@]}"; do |
| 74 | GH_ARGS+=("--remove-label" "$label") |
| 75 | done |
| 76 | |
| 77 | gh "${GH_ARGS[@]}" |
| 78 | |
| 79 | if [[ ${#FILTERED_ADD[@]} -gt 0 ]]; then |
| 80 | echo "Added: ${FILTERED_ADD[*]}" |
| 81 | fi |
| 82 | if [[ ${#FILTERED_REMOVE[@]} -gt 0 ]]; then |
| 83 | echo "Removed: ${FILTERED_REMOVE[*]}" |
| 84 | fi |