spacehub

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

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