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 --issue 123 --add-label bug --add-label needs-triage --remove-label untriaged |
| 5 | # |
| 6 | |
| 7 | set -euo pipefail |
| 8 | |
| 9 | ISSUE="" |
| 10 | ADD_LABELS=() |
| 11 | REMOVE_LABELS=() |
| 12 | |
| 13 | # Parse arguments |
| 14 | while [[ $# -gt 0 ]]; do |
| 15 | case $1 in |
| 16 | --issue) |
| 17 | ISSUE="$2" |
| 18 | shift 2 |
| 19 | ;; |
| 20 | --add-label) |
| 21 | ADD_LABELS+=("$2") |
| 22 | shift 2 |
| 23 | ;; |
| 24 | --remove-label) |
| 25 | REMOVE_LABELS+=("$2") |
| 26 | shift 2 |
| 27 | ;; |
| 28 | *) |
| 29 | exit 1 |
| 30 | ;; |
| 31 | esac |
| 32 | done |
| 33 | |
| 34 | # Validate issue number |
| 35 | if [[ -z "$ISSUE" ]]; then |
| 36 | exit 1 |
| 37 | fi |
| 38 | |
| 39 | if ! [[ "$ISSUE" =~ ^[0-9]+$ ]]; then |
| 40 | exit 1 |
| 41 | fi |
| 42 | |
| 43 | if [[ ${#ADD_LABELS[@]} -eq 0 && ${#REMOVE_LABELS[@]} -eq 0 ]]; then |
| 44 | exit 1 |
| 45 | fi |
| 46 | |
| 47 | # Fetch valid labels from the repo |
| 48 | VALID_LABELS=$(gh label list --limit 500 --json name --jq '.[].name') |
| 49 | |
| 50 | # Filter to only labels that exist in the repo |
| 51 | FILTERED_ADD=() |
| 52 | for label in "${ADD_LABELS[@]}"; do |
| 53 | if echo "$VALID_LABELS" | grep -qxF "$label"; then |
| 54 | FILTERED_ADD+=("$label") |
| 55 | fi |
| 56 | done |
| 57 | |
| 58 | FILTERED_REMOVE=() |
| 59 | for label in "${REMOVE_LABELS[@]}"; do |
| 60 | if echo "$VALID_LABELS" | grep -qxF "$label"; then |
| 61 | FILTERED_REMOVE+=("$label") |
| 62 | fi |
| 63 | done |
| 64 | |
| 65 | if [[ ${#FILTERED_ADD[@]} -eq 0 && ${#FILTERED_REMOVE[@]} -eq 0 ]]; then |
| 66 | exit 0 |
| 67 | fi |
| 68 | |
| 69 | # Build gh command arguments |
| 70 | GH_ARGS=("issue" "edit" "$ISSUE") |
| 71 | |
| 72 | for label in "${FILTERED_ADD[@]}"; do |
| 73 | GH_ARGS+=("--add-label" "$label") |
| 74 | done |
| 75 | |
| 76 | for label in "${FILTERED_REMOVE[@]}"; do |
| 77 | GH_ARGS+=("--remove-label" "$label") |
| 78 | done |
| 79 | |
| 80 | gh "${GH_ARGS[@]}" |
| 81 | |
| 82 | if [[ ${#FILTERED_ADD[@]} -gt 0 ]]; then |
| 83 | echo "Added: ${FILTERED_ADD[*]}" |
| 84 | fi |
| 85 | if [[ ${#FILTERED_REMOVE[@]} -gt 0 ]]; then |
| 86 | echo "Removed: ${FILTERED_REMOVE[*]}" |
| 87 | fi |