|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +set -euo pipefail |
| 4 | + |
| 5 | +CATEGORY="${1:-}" |
| 6 | +ORG="ironcore-dev" |
| 7 | +MAX_JOBS="${MAX_JOBS:-5}" # Can override with env: MAX_JOBS=10 ./script.sh all |
| 8 | + |
| 9 | +# Define categories and labels |
| 10 | +CATEGORIES="metal-automation networking storage compute iaas operatingsystem gardener-extension" |
| 11 | +LABELS="area/metal-automation area/networking area/storage area/compute area/iaas area/operatingsystem area/gardener-extension" |
| 12 | + |
| 13 | +metal_automation_repos="metal-operator cloud-provider-metal cluster-api-provider-ironcore-metal ironcore-image FeDHCP boot-operator ipam metal-token-rotate metal-load-balancer-controller os-images maintenance-operator firmware-operator" |
| 14 | +networking_repos="metalnet dpservice ironcore-net ebpf-nat64 metalbond" |
| 15 | +storage_repos="ceph-provider ironcore-csi-driver" |
| 16 | +compute_repos="libvirt-provider cloud-hypervisor-provider" |
| 17 | +iaas_repos="ironcore openapi-extractor controller-utils cloud-provider-ironcore vgopath kubectl-ironcore ironcore-in-a-box provider-utils ironcore-csi-driver" |
| 18 | +operatingsystem_repos="FeOS feos-demo feos-provider" |
| 19 | +gardener_extension_repos="gardener-extension-provider-ironcore machine-controller-manager-provider-ironcore-metal gardener-extension-provider-ironcore-metal machine-controller-manager-provider-ironcore machine-controller-manager gardener-extension-os-gardenlinux" |
| 20 | + |
| 21 | +run_limited_parallel() { |
| 22 | + local max_jobs=$1 |
| 23 | + shift |
| 24 | + local cmds=("$@") |
| 25 | + local pids=() |
| 26 | + |
| 27 | + for cmd in "${cmds[@]}"; do |
| 28 | + eval "$cmd" & |
| 29 | + pids+=($!) |
| 30 | + |
| 31 | + while (( $(jobs -r | wc -l) >= max_jobs )); do |
| 32 | + sleep 0.5 |
| 33 | + done |
| 34 | + done |
| 35 | + |
| 36 | + wait "${pids[@]}" |
| 37 | +} |
| 38 | + |
| 39 | +process_category() { |
| 40 | + local category="$1" |
| 41 | + local label |
| 42 | + local repos_var |
| 43 | + local repos |
| 44 | + local cmds=() |
| 45 | + |
| 46 | + # Find label |
| 47 | + i=1 |
| 48 | + for cat in $CATEGORIES; do |
| 49 | + if [[ "$cat" == "$category" ]]; then |
| 50 | + label=$(echo "$LABELS" | cut -d' ' -f"$i") |
| 51 | + break |
| 52 | + fi |
| 53 | + i=$((i+1)) |
| 54 | + done |
| 55 | + |
| 56 | + if [[ -z "${label:-}" ]]; then |
| 57 | + echo "❌ Unknown category '$category'" |
| 58 | + return |
| 59 | + fi |
| 60 | + |
| 61 | + repos_var="${category//-/_}_repos" |
| 62 | + repos="${!repos_var}" |
| 63 | + |
| 64 | + echo "✅ Category: $category" |
| 65 | + echo "🏷️ Label to apply: $label" |
| 66 | + echo "📦 Repos: $repos" |
| 67 | + echo |
| 68 | + |
| 69 | + for repo in $repos; do |
| 70 | + full_repo="$ORG/$repo" |
| 71 | + cmds+=("process_repo '$full_repo' '$label'") |
| 72 | + done |
| 73 | + |
| 74 | + run_limited_parallel "$MAX_JOBS" "${cmds[@]}" |
| 75 | +} |
| 76 | + |
| 77 | +process_repo() { |
| 78 | + local full_repo="$1" |
| 79 | + local label="$2" |
| 80 | + |
| 81 | + echo "🔍 Processing repo: $full_repo" |
| 82 | + |
| 83 | + ISSUES=$(gh issue list -R "$full_repo" --state all --limit 1500 --json number,labels \ |
| 84 | + --jq '.[] | [.number, (.labels | map(.name) | join(","))] | @tsv' || true) |
| 85 | + |
| 86 | + if [[ -z "$ISSUES" ]]; then |
| 87 | + echo " ⚠️ No issues found in $full_repo" |
| 88 | + return |
| 89 | + fi |
| 90 | + |
| 91 | + while IFS=$'\t' read -r issue_number existing_labels; do |
| 92 | + if [[ ",$existing_labels," == *",$label,"* ]]; then |
| 93 | + echo " ⚠️ Issue #$issue_number already has label '$label', skipping." |
| 94 | + else |
| 95 | + echo " ➕ Adding label '$label' to issue #$issue_number" |
| 96 | + gh issue edit "$issue_number" -R "$full_repo" --add-label "$label" || echo " ❌ Failed to label #$issue_number" |
| 97 | + fi |
| 98 | + done <<< "$ISSUES" |
| 99 | +} |
| 100 | + |
| 101 | +# Handle "all" case |
| 102 | +if [[ "$CATEGORY" == "all" ]]; then |
| 103 | + for cat in $CATEGORIES; do |
| 104 | + process_category "$cat" |
| 105 | + done |
| 106 | +else |
| 107 | + process_category "$CATEGORY" |
| 108 | +fi |
| 109 | + |
| 110 | +echo "🎉 Labeling complete." |
0 commit comments