|
| 1 | +#!/usr/bin/env bash |
| 2 | +# migrate-skill-labels.sh — One-time relabeling of existing open issues |
| 3 | +# |
| 4 | +# Renames bare difficulty labels (beginner, intermediate, advanced) to their |
| 5 | +# new "skill: *" equivalents. Run with DRY_RUN=true (default) to preview. |
| 6 | +# |
| 7 | +# Usage: |
| 8 | +# DRY_RUN=true bash .github/scripts/migrate-skill-labels.sh # preview |
| 9 | +# DRY_RUN=false bash .github/scripts/migrate-skill-labels.sh # execute |
| 10 | +# |
| 11 | +# NOTE: Requires bash 4+ for associative arrays (declare -A). |
| 12 | +# GitHub Actions runners use bash 5. macOS ships bash 3.2 by default — |
| 13 | +# use 'brew install bash' or rewrite LABEL_MAP as parallel arrays if |
| 14 | +# running locally on an unmodified Mac. |
| 15 | +# |
| 16 | +# IMPORTANT: Disable label-triggered workflows (bot-coderabbit-plan-trigger, |
| 17 | +# bot-advanced-check) BEFORE running this script to avoid webhook spam. |
| 18 | +set -euo pipefail |
| 19 | + |
| 20 | +if (( BASH_VERSINFO[0] < 4 )); then |
| 21 | + echo "ERROR: bash 4+ required (found $BASH_VERSION). See script header for details." |
| 22 | + exit 1 |
| 23 | +fi |
| 24 | + |
| 25 | +DRY_RUN="${DRY_RUN:-true}" |
| 26 | +REPO="${REPO:-$(gh repo view --json nameWithOwner -q .nameWithOwner)}" |
| 27 | + |
| 28 | +echo "Migration script for skill labels" |
| 29 | +echo " Repo: $REPO" |
| 30 | +echo " Dry run: $DRY_RUN" |
| 31 | +echo "" |
| 32 | + |
| 33 | +declare -A LABEL_MAP=( |
| 34 | + ["beginner"]="skill: beginner" |
| 35 | + ["intermediate"]="skill: intermediate" |
| 36 | + ["advanced"]="skill: advanced" |
| 37 | +) |
| 38 | + |
| 39 | +# Ensure target labels exist (no-op if already present). |
| 40 | +if [[ "$DRY_RUN" != "true" ]]; then |
| 41 | + echo "Ensuring target labels exist..." |
| 42 | + for new_label in "${LABEL_MAP[@]}"; do |
| 43 | + gh label create "$new_label" --repo "$REPO" --force 2>/dev/null || true |
| 44 | + done |
| 45 | + echo "" |
| 46 | +fi |
| 47 | + |
| 48 | +failures=0 |
| 49 | + |
| 50 | +for old_label in "${!LABEL_MAP[@]}"; do |
| 51 | + new_label="${LABEL_MAP[$old_label]}" |
| 52 | + echo "=== Migrating '$old_label' → '$new_label' ===" |
| 53 | + |
| 54 | + if ! issues=$(gh issue list --repo "$REPO" --label "$old_label" --state open --limit 1000 --search "is:issue" --json number -q '.[].number' 2>&1); then |
| 55 | + echo " ❌ ERROR: gh issue list failed for '$old_label': $issues" |
| 56 | + failures=$((failures + 1)) |
| 57 | + continue |
| 58 | + fi |
| 59 | + |
| 60 | + if [[ -z "$issues" ]]; then |
| 61 | + echo " Found 0 open issue(s) with label '$old_label'" |
| 62 | + continue |
| 63 | + fi |
| 64 | + |
| 65 | + count=$(echo "$issues" | wc -l) |
| 66 | + echo " Found $count open issue(s) with label '$old_label'" |
| 67 | + |
| 68 | + for num in $issues; do |
| 69 | + echo " Issue #$num" |
| 70 | + if [[ "$DRY_RUN" == "true" ]]; then |
| 71 | + echo " [dry-run] Would add '$new_label' and remove '$old_label'" |
| 72 | + else |
| 73 | + if ! gh issue edit "$num" --repo "$REPO" --add-label "$new_label" --remove-label "$old_label"; then |
| 74 | + echo " ❌ Failed to migrate issue #$num" |
| 75 | + failures=$((failures + 1)) |
| 76 | + else |
| 77 | + echo " ✅ Migrated" |
| 78 | + fi |
| 79 | + fi |
| 80 | + done |
| 81 | +done |
| 82 | + |
| 83 | +if (( failures > 0 )); then |
| 84 | + echo "" |
| 85 | + echo "⚠️ $failures error(s) occurred during migration. Review output above." |
| 86 | + exit 1 |
| 87 | +fi |
| 88 | +echo "" |
| 89 | +echo "✅ Migration complete." |
0 commit comments