feat: functional monster script (anti-pattern warning)

This commit is contained in:
michael 2025-06-04 18:27:00 +02:00
parent 56ed910884
commit b5eb30caa0
3 changed files with 498 additions and 119 deletions

View file

@ -1,13 +1,13 @@
#!/bin/bash
# scripts/update_script_labels.sh
# Auto-updates all scripts with current label definitions from registry
# COMPLETE VERSION with all integration fixes
# FINAL FIXED VERSION with corrected all_templates logic
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(dirname "$SCRIPT_DIR")"
REGISTRY_FILE="$PROJECT_ROOT/config/labels.registry"
REGISTRY_FILE="$PROJECT_ROOT/configs/labels.registry"
# Colors for logging
GREEN='\033[0;32m'
@ -45,16 +45,16 @@ bug:d73a4a:error:bug_template,status_updates
question:d876e3:discussion:question_template
# === COMPONENT CATEGORIES ===
gateway:0052cc:gateway_core:architecture,performance,service_templates
performance:fbca04:optimization:performance_template,architecture
gateway:0052cc:gateway_core:architecture_template,performance_template,service_templates
performance:fbca04:optimization:performance_template,architecture_template
architecture:d4c5f9:design:architecture_template,gateway
security:28a745:security_review:security_template,gateway
configuration:f9d71c:config_management:deployment,architecture
security:28a745:security_review:security_template,architecture_template
configuration:f9d71c:config_management:deployment_template,architecture_template
# === SERVICE-SPECIFIC LABELS ===
service-formular2mail:1d76db:formular2mail:service_templates,integration
service-sagjan:1d76db:sagjan:service_templates,integration
service-newsletter:ff6b6b:newsletter:service_templates,integration
service-formular2mail:1d76db:formular2mail:formular2mail_integration
service-sagjan:1d76db:sagjan:sagjan_integration
service-newsletter:ff6b6b:newsletter:newsletter_integration
# === WORKFLOW STATE LABELS ===
work-in-progress:fbca04:active:status_updates
@ -65,22 +65,21 @@ ready-for-deployment:28a745:deploy_ready:status_updates
# === INTEGRATION LABELS ===
hugo-integration:ff7518:frontend:hugo_templates,integration
api-contract:5319e7:api_design:api_templates,service_templates
breaking-change:d73a4a:breaking:api_templates,architecture
breaking-change:d73a4a:breaking:api_templates,architecture_template
# === PRIORITY LABELS ===
high-priority:d73a4a:urgent:all_templates
low-priority:0e8a16:nice_to_have:all_templates
# === META LABELS ===
low-tech:6f42c1:low_tech_principle:all_templates
digital-sovereignty:6f42c1:digital_sovereignty:all_templates
good-first-issue:7057ff:beginner_friendly:all_templates
help-wanted:159818:community_help:all_templates
low-tech:6f42c1:low_tech_principle:architecture_template,performance_template,security_template
digital-sovereignty:6f42c1:digital_sovereignty:architecture_template,performance_template,security_template
good-first-issue:7057ff:beginner_friendly:manual_assignment
help-wanted:159818:community_help:manual_assignment
# === DEPLOYMENT LABELS ===
deployment:ff7518:deployment:deployment_template
testing:f9d71c:testing:testing_template,integration
documentation:0366d6:docs:documentation_template
EOF
log_success "Created label registry: $REGISTRY_FILE"
@ -151,7 +150,7 @@ is_label_valid_for_context() {
EOF
}
# Generate template-to-labels mapping
# Generate template-to-labels mapping - FIXED VERSION
generate_template_mappings() {
cat << 'EOF'
@ -160,19 +159,51 @@ generate_template_mappings() {
declare -A TEMPLATE_LABELS=(
EOF
# Generate mappings based on usage contexts
for template in "service_templates" "architecture" "performance_template" "bug_template" "security_template" "hugo_templates" "api_templates" "deployment_template"; do
# FIXED: Consistent template names with corrected all_templates logic
declare -A template_mappings=(
["service"]="service_templates"
["architecture"]="architecture_template"
["performance"]="performance_template"
["bug"]="bug_template"
["security"]="security_template"
["hugo"]="hugo_templates"
["api"]="api_templates"
["deployment"]="deployment_template"
)
for template_name in "${!template_mappings[@]}"; do
local template_usage="${template_mappings[$template_name]}"
local labels=()
# FIXED: First add all_templates labels to every template
for label in "${!LABEL_USAGES[@]}"; do
local usage="${LABEL_USAGES[$label]}"
if [[ "$usage" == *"$template"* ]] || [[ "$usage" == "all_templates" ]]; then
# EXCLUDE service-specific labels from all templates
if [[ "$label" == service-* ]]; then
continue
fi
# Skip manual assignment labels
if [[ "$usage" == "manual_assignment" ]]; then
continue
fi
# FIXED: Add all_templates labels to every template first
if [[ "$usage" == "all_templates" ]]; then
labels+=("$label")
continue
fi
# Add template-specific labels
if [[ "$usage" == *"$template_usage"* ]]; then
labels+=("$label")
fi
done
if [[ ${#labels[@]} -gt 0 ]]; then
local label_list=$(IFS=','; echo "${labels[*]}")
echo " [\"${template%_*}\"]=\"$label_list\""
echo " [\"$template_name\"]=\"$label_list\""
fi
done
@ -309,15 +340,15 @@ add_label_to_registry() {
local name="$1"
local color="${2:-ff6b6b}"
local context="${3:-auto_generated}"
local usage="${4:-all_templates}"
local usage="${4:-manual_assignment}"
# Skip if called during auto-update to prevent loops
if [[ "${FURT_AUTO_UPDATE:-}" == "true" ]]; then
return 0
log_info "Auto-update mode: Adding $name to registry (skipping rebuild)"
else
log_info "Adding new label to registry: $name"
fi
log_info "Adding new label to registry: $name"
# Ensure registry exists
create_registry_if_missing
@ -329,7 +360,7 @@ add_label_to_registry() {
# Add to appropriate section (determine by context)
local section_marker="# === CORE WORKFLOW LABELS ==="
if [[ "$context" == *"service"* ]]; then
if [[ "$context" == *"service"* ]] || [[ "$name" == service-* ]]; then
section_marker="# === SERVICE-SPECIFIC LABELS ==="
elif [[ "$context" == *"workflow"* ]]; then
section_marker="# === WORKFLOW STATE LABELS ==="
@ -362,20 +393,25 @@ show_registry_status() {
echo "📊 Label Registry Status"
echo "========================"
echo "Registry file: $REGISTRY_FILE"
echo "Total labels: $(grep -c "^[^#]" "$REGISTRY_FILE" 2>/dev/null || echo 0)"
echo ""
echo "Labels by category:"
local current_section=""
while IFS= read -r line; do
if [[ "$line" =~ ^#\ ===.*===\ $ ]]; then
current_section=$(echo "$line" | sed 's/# === \(.*\) ===/\1/')
echo " $current_section:"
elif [[ "$line" =~ ^[^#]+: ]] && [[ -n "$current_section" ]]; then
local label_name=$(echo "$line" | cut -d: -f1)
echo " - $label_name"
fi
done < "$REGISTRY_FILE"
if [[ -f "$REGISTRY_FILE" ]]; then
echo "Total labels: $(grep -c "^[^#]" "$REGISTRY_FILE" 2>/dev/null || echo 0)"
echo ""
echo "Labels by category:"
local current_section=""
while IFS= read -r line; do
if [[ "$line" =~ ^#\ ===.*===\ $ ]]; then
current_section=$(echo "$line" | sed 's/# === \(.*\) ===/\1/')
echo " $current_section:"
elif [[ "$line" =~ ^[^#]+: ]] && [[ -n "$current_section" ]]; then
local label_name=$(echo "$line" | cut -d: -f1)
echo " - $label_name"
fi
done < "$REGISTRY_FILE"
else
echo "Registry file not found!"
fi
}
# Main function
@ -405,7 +441,7 @@ main() {
local name="$2"
local color="${3:-ff6b6b}"
local context="${4:-auto_generated}"
local usage="${5:-all_templates}"
local usage="${5:-manual_assignment}"
if [[ -z "$name" ]]; then
log_error "Usage: $0 add <name> [color] [context] [usage]"
@ -413,8 +449,12 @@ main() {
fi
add_label_to_registry "$name" "$color" "$context" "$usage"
parse_registry
main update
# Only update scripts if not in auto-update mode
if [[ "${FURT_AUTO_UPDATE:-}" != "true" ]]; then
parse_registry
main update
fi
;;
status)