archive: move all generation-1 scripts to archive

- create_issue.sh: 800+ lines monster (functional but unmaintainable)
- update_script_labels.sh: 15KB auto-update system (too complex)
- get_issues.sh: 7KB grown over time (needs simplification)
- update_issue.sh: 5KB functional (part of old system)

Preparing clean slate for low-tech generation-2 system
This commit is contained in:
michael 2025-06-04 18:29:48 +02:00
parent b5eb30caa0
commit 78b70cf06b
4 changed files with 0 additions and 0 deletions

View file

@ -0,0 +1,779 @@
#!/bin/bash
# scripts/create_issue.sh - Furt API Gateway Issue Creator
# DEBUG VERSION with path fixes and diagnostic output
set -euo pipefail
# Standard environment setup
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(dirname "$SCRIPT_DIR")"
if [ -f "$PROJECT_ROOT/.env" ]; then
export $(cat "$PROJECT_ROOT/.env" | grep -v '^#' | xargs)
fi
# Colors
GREEN='\033[0;32m'
BLUE='\033[0;34m'
RED='\033[0;31m'
YELLOW='\033[1;33m'
CYAN='\033[0;36m'
NC='\033[0m'
log_info() { echo -e "${BLUE}[INFO]${NC} $1"; }
log_success() { echo -e "${GREEN}[SUCCESS]${NC} $1"; }
log_error() { echo -e "${RED}[ERROR]${NC} $1"; }
log_warning() { echo -e "${YELLOW}[WARNING]${NC} $1"; }
log_debug() {
if [[ "${DEBUG:-}" == "1" ]]; then
echo -e "${CYAN}[DEBUG]${NC} $1" >&2;
fi
}
# Track new labels for auto-update (FIXED: Safe initialization)
declare -A NEW_LABELS_CREATED=()
# === LABEL DEFINITIONS START ===
# This section is auto-maintained by update_script_labels.sh
# DO NOT EDIT MANUALLY - Changes will be overwritten
declare -A LABEL_DEFINITIONS=(
["hugo-integration"]="color:ff7518;context:frontend;usage:hugo_templates,integration"
["service-newsletter"]="color:ff6b6b;context:newsletter;usage:newsletter_integration"
["service-analytics"]="color:1d76db;context:service_integration;usage:service_specific"
["ready-for-deployment"]="color:28a745;context:deploy_ready;usage:status_updates"
["service-clean-test4"]="color:1d76db;context:service_integration;usage:service_specific"
["service-completely-absolut-new7"]="color:1d76db;context:service_integration;usage:service_specific"
["service-completely-absolut-new9"]="color:1d76db;context:service_integration;usage:service_specific"
["service-completely-absolut-new8"]="color:1d76db;context:service_integration;usage:service_specific"
["performance"]="color:fbca04;context:optimization;usage:performance_template,architecture_template"
["bug"]="color:d73a4a;context:error;usage:bug_template,status_updates"
["question"]="color:d876e3;context:discussion;usage:question_template"
["service-formular2mail"]="color:1d76db;context:formular2mail;usage:formular2mail_integration"
["good-first-issue"]="color:7057ff;context:beginner_friendly;usage:manual_assignment"
["service-completely-absolut-new10"]="color:1d76db;context:service_integration;usage:service_specific"
["service-completely-absolut-new11"]="color:1d76db;context:service_integration;usage:service_specific"
["breaking-change"]="color:d73a4a;context:breaking;usage:api_templates,architecture_template"
["service-request"]="color:7057ff;context:new_service;usage:service_templates,status_updates"
["service-debug-test"]="color:1d76db;context:service_integration;usage:service_specific"
["low-priority"]="color:0e8a16;context:nice_to_have;usage:all_templates"
["blocked"]="color:d73a4a;context:blocked;usage:status_updates"
["low-tech"]="color:6f42c1;context:low_tech_principle;usage:architecture_template,performance_template,security_template"
["deployment"]="color:ff7518;context:deployment;usage:deployment_template"
["gateway"]="color:0052cc;context:gateway_core;usage:architecture_template,performance_template,service_templates"
["service-sagjan"]="color:1d76db;context:sagjan;usage:sagjan_integration"
["work-in-progress"]="color:fbca04;context:active;usage:status_updates"
["service-debug-check-final2"]="color:1d76db;context:service_integration;usage:service_specific"
["digital-sovereignty"]="color:6f42c1;context:digital_sovereignty;usage:architecture_template,performance_template,security_template"
["security"]="color:28a745;context:security_review;usage:security_template,architecture_template"
["architecture"]="color:d4c5f9;context:design;usage:architecture_template,gateway"
["configuration"]="color:f9d71c;context:config_management;usage:deployment_template,architecture_template"
["needs-review"]="color:0e8a16;context:review;usage:status_updates"
["help-wanted"]="color:159818;context:community_help;usage:manual_assignment"
["service-whatever-you-want"]="color:1d76db;context:service_integration;usage:service_specific"
["api-contract"]="color:5319e7;context:api_design;usage:api_templates,service_templates"
["enhancement"]="color:84b6eb;context:improvement;usage:all_templates"
["high-priority"]="color:d73a4a;context:urgent;usage:all_templates"
["testing"]="color:f9d71c;context:testing;usage:testing_template,integration"
["test-all-templates"]="color:ff0000;context:test;usage:all_templates"
)
# Extract label info
get_label_color() { echo "${LABEL_DEFINITIONS[$1]}" | cut -d';' -f1 | cut -d':' -f2; }
get_label_context() { echo "${LABEL_DEFINITIONS[$1]}" | cut -d';' -f2 | cut -d':' -f2; }
get_label_usage() { echo "${LABEL_DEFINITIONS[$1]}" | cut -d';' -f3 | cut -d':' -f2; }
# Check if label is valid for context
is_label_valid_for_context() {
local label="$1"
local context="$2"
local usage=$(get_label_usage "$label")
[[ "$usage" == *"$context"* ]] || [[ "$usage" == "all_templates" ]]
}
# === LABEL DEFINITIONS END ===
# === TEMPLATE LABEL MAPPINGS START ===
# Auto-generated template to label mappings
declare -A TEMPLATE_LABELS=(
["performance"]="performance,low-priority,low-tech,gateway,digital-sovereignty,enhancement,high-priority,test-all-templates"
["bug"]="bug,low-priority,enhancement,high-priority,test-all-templates"
["api"]="breaking-change,low-priority,api-contract,enhancement,high-priority,test-all-templates"
["service"]="low-priority,gateway,api-contract,enhancement,high-priority,test-all-templates"
["deployment"]="low-priority,deployment,configuration,enhancement,high-priority,test-all-templates"
["security"]="low-priority,low-tech,digital-sovereignty,security,enhancement,high-priority,test-all-templates"
["architecture"]="performance,breaking-change,low-priority,low-tech,gateway,digital-sovereignty,security,architecture,configuration,enhancement,high-priority,test-all-templates"
["hugo"]="hugo-integration,low-priority,enhancement,high-priority,test-all-templates"
)
# === TEMPLATE LABEL MAPPINGS END ===
# Load existing labels from repository
declare -A LABEL_IDS
load_existing_labels() {
if [[ -z "${GITEA_URL:-}" ]] || [[ -z "${GITEA_TOKEN:-}" ]]; then
log_error "GITEA_URL and GITEA_TOKEN must be set"
exit 1
fi
log_info "Loading existing labels from repository..."
local response=$(curl -s "$GITEA_URL/api/v1/repos/$REPO_OWNER/$REPO_NAME/labels" \
-H "Authorization: token $GITEA_TOKEN")
if [[ $? -ne 0 ]]; then
log_error "Failed to fetch labels from repository"
exit 1
fi
while IFS= read -r line; do
local name=$(echo "$line" | jq -r '.name')
local id=$(echo "$line" | jq -r '.id')
LABEL_IDS["$name"]="$id"
done < <(echo "$response" | jq -c '.[]')
log_info "Loaded ${#LABEL_IDS[@]} existing labels"
}
# FIXED: Silent version of ensure_label_exists (no stdout pollution!)
ensure_label_exists_silent() {
local name="$1"
local color="${2:-ff6b6b}"
local description="${3:-Auto-generated label}"
local usage="${4:-manual_assignment}" # ADDED: usage parameter
log_debug "Checking label: $name"
if [[ -n "${LABEL_IDS[$name]:-}" ]]; then
log_debug "Label $name already exists (ID: ${LABEL_IDS[$name]})"
return 0
fi
log_debug "Creating new label: $name with color $color"
# Create label (redirect output to prevent stdout mixing)
local response=$(curl -s -w "\n%{http_code}" -X POST \
"$GITEA_URL/api/v1/repos/$REPO_OWNER/$REPO_NAME/labels" \
-H "Authorization: token $GITEA_TOKEN" \
-H "Content-Type: application/json" \
-d "{
\"name\": \"$name\",
\"color\": \"$color\",
\"description\": \"$description\"
}" 2>/dev/null)
local http_code=$(echo "$response" | tail -n1)
local response_body=$(echo "$response" | head -n -1)
if [[ "$http_code" == "201" ]]; then
local new_id=$(echo "$response_body" | jq -r '.id')
LABEL_IDS["$name"]="$new_id"
# FIXED: Track for auto-update with correct usage
NEW_LABELS_CREATED["$name"]="$color:auto_generated:$usage"
log_debug "Successfully created label $name (ID: $new_id)"
log_debug "Added to NEW_LABELS_CREATED: $name -> ${NEW_LABELS_CREATED[$name]}"
return 0
else
log_debug "Failed to create label $name (HTTP: $http_code)"
log_debug "Response: $response_body"
return 1
fi
}
# Process labels for template (updates global arrays, no output)
process_labels_for_template() {
local template="$1"
shift
local additional_labels=("$@")
log_debug "Processing labels for template: $template"
log_debug "Additional labels: ${additional_labels[*]}"
# Get template labels
local template_labels_string="${TEMPLATE_LABELS[$template]:-}"
local all_labels=()
# Add template labels
if [[ -n "$template_labels_string" ]]; then
IFS=',' read -ra template_labels <<< "$template_labels_string"
all_labels+=("${template_labels[@]}")
log_debug "Template labels: ${template_labels[*]}"
fi
# Add additional labels
all_labels+=("${additional_labels[@]}")
log_debug "All labels to process: ${all_labels[*]}"
# Process all labels and ensure they exist
for label in "${all_labels[@]}"; do
log_debug "Processing label: $label"
# Process both known and unknown labels
if [[ -n "${LABEL_DEFINITIONS[$label]:-}" ]]; then
log_debug "Known label: $label"
# Known label - use defined color and context
local color=$(get_label_color "$label")
local context=$(get_label_context "$label")
ensure_label_exists_silent "$label" "$color" "Furt: $context"
else
log_debug "Unknown label: $label - creating with smart defaults"
# Unknown label - auto-create with smart defaults
local default_color="ff6b6b"
local default_context="auto_generated"
# Smart defaults based on label pattern
if [[ "$label" == service-* ]]; then
default_color="1d76db"
default_context="service_integration"
default_usage="service_specific" # FIXED: Not all_templates!
log_debug "Service label detected - using blue color and service_specific usage"
elif [[ "$label" == *-priority ]]; then
default_color="d73a4a"
default_context="priority_level"
default_usage="priority_management"
log_debug "Priority label detected - using red color"
elif [[ "$label" == hugo-* ]]; then
default_color="ff7518"
default_context="frontend_integration"
default_usage="hugo_integration"
log_debug "Hugo label detected - using orange color"
else
default_usage="manual_assignment"
fi
ensure_label_exists_silent "$label" "$default_color" "Furt: $default_context"
# FIXED: Track with correct usage
if [[ -n "${LABEL_IDS[$label]:-}" ]] && [[ -n "${NEW_LABELS_CREATED[$label]:-}" ]]; then
NEW_LABELS_CREATED["$label"]="$default_color:$default_context:$default_usage"
log_debug "Updated NEW_LABELS_CREATED with correct usage: $label -> $default_color:$default_context:$default_usage"
fi
fi
# Debug: Check if this label was newly created
if [[ -n "${LABEL_IDS[$label]:-}" ]]; then
if [[ -n "${NEW_LABELS_CREATED[$label]:-}" ]]; then
log_debug " → Label $label was newly created and tracked"
else
log_debug " → Label $label already existed"
fi
else
log_warning "Failed to process label: $label"
fi
done
# Debug: Check NEW_LABELS_CREATED at end of processing
log_debug "NEW_LABELS_CREATED after processing: ${#NEW_LABELS_CREATED[@]} entries"
if [[ "${#NEW_LABELS_CREATED[@]}" -gt 0 ]] 2>/dev/null; then
for label_name in "${!NEW_LABELS_CREATED[@]}"; do
log_debug " - $label_name: ${NEW_LABELS_CREATED[$label_name]}"
done
else
log_debug " (no entries in NEW_LABELS_CREATED array)"
fi
}
# Build JSON from already processed labels (pure function, no side effects)
build_labels_json_from_processed() {
local template="$1"
shift
local additional_labels=("$@")
log_debug "Building JSON from processed labels"
# Get template labels
local template_labels_string="${TEMPLATE_LABELS[$template]:-}"
local all_labels=()
# Add template labels
if [[ -n "$template_labels_string" ]]; then
IFS=',' read -ra template_labels <<< "$template_labels_string"
all_labels+=("${template_labels[@]}")
fi
# Add additional labels
all_labels+=("${additional_labels[@]}")
# Collect IDs from already processed labels
local label_ids=()
for label in "${all_labels[@]}"; do
if [[ -n "${LABEL_IDS[$label]:-}" ]]; then
label_ids+=("${LABEL_IDS[$label]}")
log_debug "Added ID ${LABEL_IDS[$label]} for $label to JSON"
else
log_warning "No ID found for label: $label"
fi
done
log_debug "Final label IDs for JSON: ${label_ids[*]}"
# Build JSON array (clean output only!)
if [[ ${#label_ids[@]} -gt 0 ]]; then
printf '[%s]' "$(IFS=','; echo "${label_ids[*]}")"
else
echo "[]"
fi
}
# DEPRECATED: Old build_labels_json function (kept for compatibility)
build_labels_json() {
local template="$1"
shift
local additional_labels=("$@")
log_debug "Building labels for template: $template"
log_debug "Additional labels: ${additional_labels[*]}"
# Get template labels
local template_labels_string="${TEMPLATE_LABELS[$template]:-}"
local all_labels=()
# Add template labels
if [[ -n "$template_labels_string" ]]; then
IFS=',' read -ra template_labels <<< "$template_labels_string"
all_labels+=("${template_labels[@]}")
log_debug "Template labels: ${template_labels[*]}"
fi
# Add additional labels
all_labels+=("${additional_labels[@]}")
log_debug "All labels to process: ${all_labels[*]}"
# FIXED: Ensure all labels exist and collect IDs (handles unknown labels!)
local label_ids=()
for label in "${all_labels[@]}"; do
log_debug "Processing label: $label"
# Process both known and unknown labels
if [[ -n "${LABEL_DEFINITIONS[$label]:-}" ]]; then
log_debug "Known label: $label"
# Known label - use defined color and context
local color=$(get_label_color "$label")
local context=$(get_label_context "$label")
ensure_label_exists_silent "$label" "$color" "Furt: $context"
else
log_debug "Unknown label: $label - creating with smart defaults"
# FIXED: Unknown label - auto-create with smart defaults
local default_color="ff6b6b"
local default_context="auto_generated"
# Smart defaults based on label pattern
if [[ "$label" == service-* ]]; then
default_color="1d76db"
default_context="service_integration"
log_debug "Service label detected - using blue color"
elif [[ "$label" == *-priority ]]; then
default_color="d73a4a"
default_context="priority_level"
log_debug "Priority label detected - using red color"
elif [[ "$label" == hugo-* ]]; then
default_color="ff7518"
default_context="frontend_integration"
log_debug "Hugo label detected - using orange color"
fi
ensure_label_exists_silent "$label" "$default_color" "Furt: $default_context"
fi
# Collect ID if label was created/exists
if [[ -n "${LABEL_IDS[$label]:-}" ]]; then
label_ids+=("${LABEL_IDS[$label]}")
log_debug "Added label ID: ${LABEL_IDS[$label]} for $label"
# Debug: Check if this label was newly created
if [[ -n "${NEW_LABELS_CREATED[$label]:-}" ]]; then
log_debug " → This label was newly created and tracked"
else
log_debug " → This label already existed"
fi
else
log_warning "Failed to get ID for label: $label"
fi
done
log_debug "Final label IDs: ${label_ids[*]}"
# Debug: Check NEW_LABELS_CREATED at end of function
log_debug "NEW_LABELS_CREATED at end of build_labels_json: ${#NEW_LABELS_CREATED[@]} entries"
if [[ "${#NEW_LABELS_CREATED[@]}" -gt 0 ]] 2>/dev/null; then
for label_name in "${!NEW_LABELS_CREATED[@]}"; do
log_debug " - $label_name: ${NEW_LABELS_CREATED[$label_name]}"
done
else
log_debug " (no entries in NEW_LABELS_CREATED array)"
fi
# Build JSON array (clean output only!)
if [[ ${#label_ids[@]} -gt 0 ]]; then
printf '[%s]' "$(IFS=','; echo "${label_ids[*]}")"
else
echo "[]"
fi
}
# Show which labels are being used (AFTER JSON building to avoid stdout pollution)
show_labels_used() {
local template="$1"
shift
local additional_labels=("$@")
log_info "Labels used for this issue:"
# Show template labels
local template_labels_string="${TEMPLATE_LABELS[$template]:-}"
if [[ -n "$template_labels_string" ]]; then
IFS=',' read -ra template_labels <<< "$template_labels_string"
for label in "${template_labels[@]}"; do
if [[ -n "${LABEL_IDS[$label]:-}" ]]; then
log_info "$label (ID: ${LABEL_IDS[$label]})"
fi
done
fi
# Show additional labels (these may have been newly created)
for label in "${additional_labels[@]}"; do
if [[ -n "${LABEL_IDS[$label]:-}" ]]; then
if [[ -n "${NEW_LABELS_CREATED[$label]:-}" ]]; then
log_info "$label (ID: ${LABEL_IDS[$label]}) [NEW!]"
else
log_info "$label (ID: ${LABEL_IDS[$label]})"
fi
else
log_warning "$label (failed to create)"
fi
done
}
# FIXED: AUTO-UPDATE with safe array handling and correct path
auto_update_scripts_if_needed() {
# FIXED: Safe check for empty associative array
local new_labels_count=0
if [[ "${#NEW_LABELS_CREATED[@]}" -gt 0 ]] 2>/dev/null; then
new_labels_count=${#NEW_LABELS_CREATED[@]}
fi
log_debug "Auto-update check: $new_labels_count new labels created"
# Debug: Show what's in NEW_LABELS_CREATED
if [[ $new_labels_count -gt 0 ]]; then
log_debug "NEW_LABELS_CREATED contents:"
for label_name in "${!NEW_LABELS_CREATED[@]}"; do
log_debug " - $label_name: ${NEW_LABELS_CREATED[$label_name]}"
done
else
log_debug "NEW_LABELS_CREATED is empty or unset"
# Debug: Try to list what's in the array anyway
if [[ "${#NEW_LABELS_CREATED[@]}" -gt 0 ]] 2>/dev/null; then
for key in "${!NEW_LABELS_CREATED[@]}"; do
log_debug " Found key: $key"
done
else
log_debug " Array iteration failed - truly empty"
fi
fi
if [[ $new_labels_count -eq 0 ]]; then
log_debug "No new labels created - skipping auto-update"
return 0 # No new labels, no update needed
fi
log_info "🔄 Auto-updating scripts with $new_labels_count new labels..."
# Check if update script exists
local update_script="$SCRIPT_DIR/update_script_labels.sh"
if [[ ! -f "$update_script" ]]; then
log_warning "Update script not found: $update_script"
log_warning "Skipping auto-update"
return 0
fi
if [[ ! -x "$update_script" ]]; then
log_warning "Update script not executable: $update_script"
log_warning "Making executable..."
chmod +x "$update_script"
fi
# Add new labels to registry
for label_name in "${!NEW_LABELS_CREATED[@]}"; do
local label_info="${NEW_LABELS_CREATED[$label_name]}"
local color=$(echo "$label_info" | cut -d':' -f1)
local context=$(echo "$label_info" | cut -d':' -f2)
local usage=$(echo "$label_info" | cut -d':' -f3)
log_info "Adding '$label_name' to registry..."
# Add to registry (suppressing output to avoid noise)
FURT_AUTO_UPDATE=true "$update_script" add "$label_name" "$color" "$context" "$usage" >/dev/null 2>&1 || {
log_warning "Failed to add $label_name to registry"
}
done
# Update all scripts with new labels
log_info "Synchronizing all scripts..."
"$update_script" update >/dev/null 2>&1 || {
log_warning "Failed to update scripts"
return 0
}
log_success "✅ All scripts automatically synchronized with new labels!"
# Show what was added
echo ""
echo "🆕 New labels created and synchronized:"
for label_name in "${!NEW_LABELS_CREATED[@]}"; do
echo " - $label_name (ID: ${LABEL_IDS[$label_name]})"
done
echo ""
}
# Create issue templates
create_service_issue() {
local service_name="${1:-newsletter}"
log_debug "Creating service issue for: $service_name"
local title="[SERVICE] $service_name für Furt Gateway"
local body="# Service-Request: $service_name
## 🏷️ Service-Details
**Name:** $service_name
**Port:** TBD
**Zweck:** [Service-Beschreibung]
## 📝 Funktionsanforderungen
- [ ] [Anforderung 1]
- [ ] [Anforderung 2]
- [ ] [Anforderung 3]
## 🔗 Gateway-Integration
- [ ] **Routing:** \`/v1/$service_name/*\`
- [ ] **Auth:** API-Key required
- [ ] **Rate-Limiting:** TBD req/min
- [ ] **Health-Check:** \`/health\`
## 🎯 Hugo-Integration
- [ ] **Shortcode:** \`{{< furt-$service_name >}}\`
- [ ] **JavaScript-Client**
- [ ] **CSS-Styling**
## ⚡ Priorität
🔥 **Hoch** - benötigt für Website-Launch"
# Process labels first, then build JSON
local service_label="service-$service_name"
log_debug "Service label to add: $service_label"
# First: Process all labels (this updates global arrays)
process_labels_for_template "service" "$service_label"
# Then: Build JSON from already-processed labels (pure function, no side effects)
local labels_json=$(build_labels_json_from_processed "service" "$service_label")
# Show which labels are being used (AFTER processing when labels are actually created)
show_labels_used "service" "$service_label"
create_issue "$title" "$body" "$labels_json"
}
create_architecture_issue() {
local topic="${1:-middleware-optimization}"
local title="[ARCH] Gateway $topic"
local body="# Architektur-Diskussion: $topic
## 🎯 Architektur-Thema
[Beschreibung des Architektur-Themas]
## 📊 Aktuelle Situation
- [Status Quo 1]
- [Status Quo 2]
## 💡 Vorgeschlagene Änderung
- [Vorschlag 1]
- [Vorschlag 2]
## 🔄 Alternativen
1. **Option A:** [Beschreibung]
2. **Option B:** [Beschreibung]
## 📈 Betroffene Bereiche
- [ ] Gateway-Performance
- [ ] Service-Integration
- [ ] Security
- [ ] Configuration-Management"
# Process labels first, then build JSON
process_labels_for_template "architecture"
local labels_json=$(build_labels_json_from_processed "architecture")
create_issue "$title" "$body" "$labels_json"
}
# Generic template creator
create_generic_issue() {
local template="$1"
local component="${2:-gateway}"
local description="[Beschreibung hinzufügen]"
# Safe parameter handling for $3
if [[ $# -ge 3 ]] && [[ -n "${3:-}" ]]; then
description="$3"
fi
log_debug "Creating $template issue for: $component"
local title_prefix
case "$template" in
api) title_prefix="[API]" ;;
security) title_prefix="[SEC]" ;;
hugo) title_prefix="[HUGO]" ;;
deployment) title_prefix="[DEPLOY]" ;;
bug) title_prefix="[BUG]" ;;
*) title_prefix="[${template^^}]" ;;
esac
local title="$title_prefix $component $(echo ${template^} | sed 's/api/API Contract/')"
local body="# ${template^}: $component
## 📝 ${template^}-Details
**Komponente:** $component
**Beschreibung:** $description
## 🎯 Anforderungen
- [ ] [Anforderung 1]
- [ ] [Anforderung 2]
- [ ] [Anforderung 3]
## ✅ Definition of Done
- [ ] [DoD Kriterium 1]
- [ ] [DoD Kriterium 2]
- [ ] [DoD Kriterium 3]"
# Process labels first, then build JSON
process_labels_for_template "$template"
local labels_json=$(build_labels_json_from_processed "$template")
show_labels_used "$template"
create_issue "$title" "$body" "$labels_json"
}
# Show usage information
show_usage() {
echo "🎯 Furt API-Gateway Issue Creator (Debug Version)"
echo ""
echo "Usage: $0 [TEMPLATE] [OPTIONS]"
echo ""
echo "📋 Available Templates:"
echo " service [name] New service for gateway (default: newsletter)"
echo " architecture [topic] Gateway architecture discussion (default: middleware-optimization)"
echo " performance [comp] Performance optimization (default: gateway)"
echo " api [service] API contract update (default: formular2mail)"
echo " security [comp] Security review/issue (default: gateway)"
echo " bug [comp] [desc] Bug report (default: gateway)"
echo " hugo [feature] Hugo integration (default: shortcode)"
echo " deployment [comp] Deployment issue (default: gateway)"
echo " custom Custom issue (interactive)"
echo ""
echo "🚀 Examples:"
echo " $0 service newsletter # Create newsletter service request"
echo " $0 architecture rate-limiting # Discuss rate limiting architecture"
echo " $0 performance gateway # Gateway performance optimization"
echo " $0 custom # Interactive custom issue"
echo ""
echo "🔧 Debug Mode:"
echo " Set DEBUG=1 for verbose debug output"
}
# Generic issue creation
create_issue() {
local title="$1"
local body="$2"
local labels_json="$3"
log_info "Creating issue: $title"
log_debug "Labels JSON: $labels_json"
local response=$(curl -s -w "\n%{http_code}" -X POST \
"$GITEA_URL/api/v1/repos/$REPO_OWNER/$REPO_NAME/issues" \
-H "Authorization: token $GITEA_TOKEN" \
-H "Content-Type: application/json" \
-d "{
\"title\": $(echo "$title" | jq -R .),
\"body\": $(echo "$body" | jq -R -s .),
\"labels\": $labels_json
}")
local http_code=$(echo "$response" | tail -n1)
local response_body=$(echo "$response" | head -n -1)
if [[ "$http_code" == "201" ]]; then
local issue_number=$(echo "$response_body" | jq -r '.number')
local issue_url=$(echo "$response_body" | jq -r '.html_url')
log_success "Issue #$issue_number created!"
echo "🔗 $issue_url"
else
log_error "Failed to create issue (HTTP: $http_code)"
log_error "Response: $response_body"
exit 1
fi
}
# Main function
main() {
local template="${1:-help}"
# Enable debug if requested
if [[ "${DEBUG:-}" == "1" ]]; then
log_info "Debug mode enabled"
fi
if [[ "$template" == "help" ]] || [[ "$template" == "--help" ]] || [[ "$template" == "-h" ]]; then
show_usage
exit 0
fi
# Load existing labels
load_existing_labels
case "$template" in
service)
create_service_issue "${2:-newsletter}"
;;
architecture)
create_architecture_issue "${2:-middleware-optimization}"
;;
performance)
local component="${2:-gateway}"
local title="[PERF] $component Performance-Optimierung"
local body="# Performance-Optimierung: $component"
process_labels_for_template "performance"
local labels_json=$(build_labels_json_from_processed "performance")
create_issue "$title" "$body" "$labels_json"
;;
api|security|hugo|deployment|bug)
if [[ $# -ge 3 ]]; then
create_generic_issue "$template" "${2:-gateway}" "$3"
else
create_generic_issue "$template" "${2:-gateway}"
fi
;;
*)
log_error "Unknown template: $template"
show_usage
exit 1
;;
esac
# FIXED: AUTO-UPDATE: Automatically sync scripts if new labels were created
auto_update_scripts_if_needed
}
# Run if executed directly
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
main "$@"
fi

250
scripts/archive/get_issues_v1.sh Executable file
View file

@ -0,0 +1,250 @@
#!/bin/bash
# Load environment
if [ -f .env ]; then
export $(cat .env | grep -v '^#' | xargs)
else
echo "❌ .env file not found!"
echo "📋 Copy .env.example to .env and configure it first"
exit 1
fi
# Validate required variables
if [ -z "$GITEA_URL" ] || [ -z "$REPO_OWNER" ] || [ -z "$REPO_NAME" ] || [ -z "$GITEA_TOKEN" ]; then
echo "❌ Missing required environment variables in .env"
exit 1
fi
# Colors
GREEN='\033[0;32m'
BLUE='\033[0;34m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
NC='\033[0m'
log_info() { echo -e "${BLUE}[INFO]${NC} $1"; }
log_success() { echo -e "${GREEN}[SUCCESS]${NC} $1"; }
log_warning() { echo -e "${YELLOW}[WARNING]${NC} $1"; }
# Get all issues with nice formatting
get_all_issues() {
log_info "Fetching all issues..."
echo ""
response=$(curl -s "$GITEA_URL/api/v1/repos/$REPO_OWNER/$REPO_NAME/issues" \
-H "Authorization: token $GITEA_TOKEN")
if [ $? -ne 0 ]; then
echo "❌ Error fetching issues"
return 1
fi
echo "$response" | jq -r '.[] |
"🎯 #\(.number) \(.title)",
" 📊 State: \(.state) | 🏷️ Labels: \(.labels | map(.name) | join(", ") // "none")",
" 🔗 \(.html_url)",
""'
}
# Get issues by label
get_issues_by_label() {
local label="$1"
log_info "Fetching issues with label: $label"
echo ""
response=$(curl -s "$GITEA_URL/api/v1/repos/$REPO_OWNER/$REPO_NAME/issues?labels=$label" \
-H "Authorization: token $GITEA_TOKEN")
echo "$response" | jq -r '.[] |
"🎯 #\(.number) \(.title)",
" 📊 \(.state) | 🔗 \(.html_url)",
""'
}
# Get issue details
get_issue_details() {
local issue_number="$1"
log_info "Fetching details for issue #$issue_number"
echo ""
response=$(curl -s "$GITEA_URL/api/v1/repos/$REPO_OWNER/$REPO_NAME/issues/$issue_number" \
-H "Authorization: token $GITEA_TOKEN")
echo "$response" | jq -r '
"🎯 Issue #\(.number): \(.title)",
"📊 State: \(.state)",
"👤 Assignees: \(.assignees | map(.login) | join(", ") // "none")",
"🏷️ Labels: \(.labels | map(.name) | join(", ") // "none")",
"📅 Created: \(.created_at)",
"🔗 URL: \(.html_url)",
"",
"📝 Body:",
"\(.body // "No description")",
""'
}
# Close issue
close_issue() {
local issue_number="$1"
log_info "Closing issue #$issue_number"
response=$(curl -s -w "\n%{http_code}" -X PATCH \
"$GITEA_URL/api/v1/repos/$REPO_OWNER/$REPO_NAME/issues/$issue_number" \
-H "Authorization: token $GITEA_TOKEN" \
-H "Content-Type: application/json" \
-d '{"state": "closed"}')
http_code=$(echo "$response" | tail -n1)
if [ "$http_code" = "201" ]; then
log_success "Issue #$issue_number closed"
else
echo "❌ Failed to close issue (HTTP: $http_code)"
fi
}
# Get pipeline status (issues grouped by Kanban columns for Furt)
get_pipeline_status() {
log_info "Furt API Gateway - Pipeline Status Overview"
echo ""
echo "🔧 SERVICE REQUESTS:"
get_issues_by_label "service-request" | head -10
echo "🏗️ ARCHITECTURE DISCUSSIONS:"
get_issues_by_label "architecture"
echo "🚀 PERFORMANCE OPTIMIZATIONS:"
get_issues_by_label "performance"
echo "🔒 SECURITY REVIEWS:"
get_issues_by_label "security"
echo "🐛 BUGS:"
get_issues_by_label "bug"
echo "🌐 HUGO INTEGRATIONS:"
get_issues_by_label "hugo-integration"
echo "📋 WORK IN PROGRESS:"
get_issues_by_label "enhancement" | head -5
}
# Issue statistics
get_stats() {
log_info "Furt API Gateway - Issue Statistics"
echo ""
all_issues=$(curl -s "$GITEA_URL/api/v1/repos/$REPO_OWNER/$REPO_NAME/issues" \
-H "Authorization: token $GITEA_TOKEN")
total=$(echo "$all_issues" | jq length)
open=$(echo "$all_issues" | jq '[.[] | select(.state == "open")] | length')
closed=$(echo "$all_issues" | jq '[.[] | select(.state == "closed")] | length')
echo "📊 Total Issues: $total"
echo "✅ Open: $open"
echo "🔒 Closed: $closed"
echo ""
echo "🏷️ Furt Labels:"
echo "$all_issues" | jq -r '[.[] | .labels[].name] | group_by(.) | map({label: .[0], count: length}) | sort_by(.count) | reverse | limit(10; .[]) | " \(.label): \(.count)"'
}
case "${1:-help}" in
"all"|"")
get_all_issues
;;
"gateway")
get_issues_by_label "gateway"
;;
"service-request")
get_issues_by_label "service-request"
;;
"service-formular2mail")
get_issues_by_label "service-formular2mail"
;;
"service-sagjan")
get_issues_by_label "service-sagjan"
;;
"architecture")
get_issues_by_label "architecture"
;;
"performance")
get_issues_by_label "performance"
;;
"security")
get_issues_by_label "security"
;;
"bug")
get_issues_by_label "bug"
;;
"enhancement")
get_issues_by_label "enhancement"
;;
"hugo")
get_issues_by_label "hugo-integration"
;;
"deployment")
get_issues_by_label "deployment"
;;
"testing")
get_issues_by_label "testing"
;;
"documentation")
get_issues_by_label "documentation"
;;
"pipeline")
get_pipeline_status
;;
"stats")
get_stats
;;
"close")
if [ -z "$2" ]; then
echo "Usage: $0 close ISSUE_NUMBER"
exit 1
fi
close_issue "$2"
;;
[0-9]*)
get_issue_details "$1"
;;
*)
echo "🎯 Furt API Gateway - Issues Manager"
echo ""
echo "Usage: $0 [COMMAND] [OPTIONS]"
echo ""
echo "📋 List Commands:"
echo " all List all issues (default)"
echo " gateway Gateway core issues"
echo " service-request New service requests"
echo " service-formular2mail Formular2mail service issues"
echo " service-sagjan Sagjan service issues"
echo " architecture Architecture discussions"
echo " performance Performance optimizations"
echo " security Security reviews"
echo " bug Bug reports"
echo " enhancement New features"
echo " hugo Hugo integration issues"
echo " deployment Deployment issues"
echo " testing Testing issues"
echo " documentation Documentation updates"
echo ""
echo "📊 Analysis Commands:"
echo " pipeline Kanban pipeline status"
echo " stats Issue statistics"
echo ""
echo "⚙️ Management Commands:"
echo " close NUM Close issue #NUM"
echo " NUM Show details for issue #NUM"
echo ""
echo "🚀 Examples:"
echo " $0 # List all issues"
echo " $0 pipeline # Show pipeline status"
echo " $0 service-request # Show service requests"
echo " $0 gateway # Show gateway issues"
echo " $0 5 # Show issue #5 details"
echo " $0 close 3 # Close issue #3"
;;
esac

View file

@ -0,0 +1,156 @@
#!/bin/bash
# Load environment
if [ -f .env ]; then
export $(cat .env | grep -v '^#' | xargs)
else
echo "❌ .env file not found!"
exit 1
fi
# Colors
GREEN='\033[0;32m'
BLUE='\033[0;34m'
RED='\033[0;31m'
NC='\033[0m'
log_info() { echo -e "${BLUE}[INFO]${NC} $1"; }
log_success() { echo -e "${GREEN}[SUCCESS]${NC} $1"; }
log_error() { echo -e "${RED}[ERROR]${NC} $1"; }
# Get all labels with IDs
declare -A LABEL_IDS
get_labels() {
response=$(curl -s "$GITEA_URL/api/v1/repos/$REPO_OWNER/$REPO_NAME/labels" \
-H "Authorization: token $GITEA_TOKEN")
while IFS= read -r line; do
name=$(echo "$line" | jq -r '.name')
id=$(echo "$line" | jq -r '.id')
LABEL_IDS["$name"]="$id"
done < <(echo "$response" | jq -c '.[]')
}
# Add comment to issue
add_comment() {
local issue_number="$1"
local comment="$2"
# Use jq for proper JSON escaping
local json_payload=$(jq -n --arg body "$comment" '{body: $body}')
response=$(curl -s -w "\n%{http_code}" -X POST \
"$GITEA_URL/api/v1/repos/$REPO_OWNER/$REPO_NAME/issues/$issue_number/comments" \
-H "Authorization: token $GITEA_TOKEN" \
-H "Content-Type: application/json" \
-d "$json_payload")
http_code=$(echo "$response" | tail -n1)
if [ "$http_code" = "201" ]; then
log_success "Comment added to issue #$issue_number"
else
log_error "Failed to add comment (HTTP: $http_code)"
fi
}
# Update issue labels - FIXED VERSION
update_labels() {
local issue_number="$1"
local labels_string="$2"
get_labels
# Convert to ID array
local valid_label_ids=()
IFS=',' read -ra LABEL_ARRAY <<< "$labels_string"
for label in "${LABEL_ARRAY[@]}"; do
label=$(echo "$label" | xargs)
if [ -n "${LABEL_IDS[$label]}" ]; then
valid_label_ids+=("${LABEL_IDS[$label]}")
else
log_error "Label '$label' not found!"
return 1
fi
done
# Build ID array JSON
local labels_json="["
for i in "${!valid_label_ids[@]}"; do
if [ $i -gt 0 ]; then
labels_json="${labels_json},"
fi
labels_json="${labels_json}${valid_label_ids[$i]}"
done
labels_json="${labels_json}]"
response=$(curl -s -w "\n%{http_code}" -X PUT \
"$GITEA_URL/api/v1/repos/$REPO_OWNER/$REPO_NAME/issues/$issue_number/labels" \
-H "Authorization: token $GITEA_TOKEN" \
-H "Content-Type: application/json" \
-d "$labels_json")
http_code=$(echo "$response" | tail -n1)
if [ "$http_code" = "200" ]; then
log_success "Labels updated for issue #$issue_number"
else
log_error "Failed to update labels (HTTP: $http_code)"
fi
}
case "${1:-help}" in
"comment")
if [ -z "$2" ] || [ -z "$3" ]; then
echo "Usage: $0 comment ISSUE_NUMBER \"COMMENT_TEXT\""
exit 1
fi
add_comment "$2" "$3"
;;
"labels")
if [ -z "$2" ] || [ -z "$3" ]; then
echo "Usage: $0 labels ISSUE_NUMBER \"label1,label2,label3\""
exit 1
fi
update_labels "$2" "$3"
;;
"progress")
if [ -z "$2" ]; then
echo "Usage: $0 progress ISSUE_NUMBER"
exit 1
fi
add_comment "$2" "📊 **Progress Update:** Arbeit an dieser Analyse läuft. Erste Quellen werden gesammelt und Framework-Relevanz geprüft."
update_labels "$2" "work-in-progress"
;;
"review")
if [ -z "$2" ]; then
echo "Usage: $0 review ISSUE_NUMBER"
exit 1
fi
add_comment "$2" "👀 **Ready for Review:** Erste Analyse abgeschlossen. Bitte um Peer-Review der Quellen und Framework-Integration."
update_labels "$2" "needs-review"
;;
"fact-check")
if [ -z "$2" ]; then
echo "Usage: $0 fact-check ISSUE_NUMBER"
exit 1
fi
add_comment "$2" "🔍 **Fact-Check Required:** Kritische Behauptungen gefunden die zusätzliche Quellen-Verifikation benötigen."
update_labels "$2" "fact-check-needed"
;;
*)
echo "🔧 Issue Update Tool (FIXED VERSION)"
echo ""
echo "Usage: $0 COMMAND ISSUE_NUMBER [OPTIONS]"
echo ""
echo "Commands:"
echo " comment NUM \"TEXT\" Add comment to issue"
echo " labels NUM \"l1,l2\" Update issue labels (using IDs)"
echo " progress NUM Mark as work-in-progress"
echo " review NUM Mark as ready for review"
echo " fact-check NUM Mark as needing fact-check"
echo ""
echo "Examples:"
echo " $0 comment 5 \"Erste Quellen gefunden\""
echo " $0 labels 3 \"regional-case,work-in-progress\""
echo " $0 progress 7"
;;
esac

View file

@ -0,0 +1,491 @@
#!/bin/bash
# scripts/update_script_labels.sh
# Auto-updates all scripts with current label definitions from registry
# 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/configs/labels.registry"
# Colors for logging
GREEN='\033[0;32m'
BLUE='\033[0;34m'
RED='\033[0;31m'
YELLOW='\033[1;33m'
NC='\033[0m'
log_info() { echo -e "${BLUE}[INFO]${NC} $1"; }
log_success() { echo -e "${GREEN}[SUCCESS]${NC} $1"; }
log_error() { echo -e "${RED}[ERROR]${NC} $1"; }
log_warning() { echo -e "${YELLOW}[WARNING]${NC} $1"; }
# Parse label registry into associative arrays
declare -A LABEL_COLORS
declare -A LABEL_CONTEXTS
declare -A LABEL_USAGES
# Create registry file if it doesn't exist
create_registry_if_missing() {
if [[ ! -f "$REGISTRY_FILE" ]]; then
log_info "Creating label registry file..."
mkdir -p "$(dirname "$REGISTRY_FILE")"
cat > "$REGISTRY_FILE" << 'EOF'
# Central Label Registry for Furt API Gateway Project
# Format: name:color:context:usage_contexts
# This file is the single source of truth for all labels
# === CORE WORKFLOW LABELS ===
service-request:7057ff:new_service:service_templates,status_updates
enhancement:84b6eb:improvement:all_templates
bug:d73a4a:error:bug_template,status_updates
question:d876e3:discussion:question_template
# === COMPONENT CATEGORIES ===
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,architecture_template
configuration:f9d71c:config_management:deployment_template,architecture_template
# === SERVICE-SPECIFIC LABELS ===
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
needs-review:0e8a16:review:status_updates
blocked:d73a4a:blocked:status_updates
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_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: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
EOF
log_success "Created label registry: $REGISTRY_FILE"
fi
}
parse_registry() {
create_registry_if_missing
log_info "Parsing label registry..."
while IFS= read -r line; do
# Skip comments and empty lines
[[ "$line" =~ ^#.*$ ]] && continue
[[ -z "$line" ]] && continue
# Parse format: name:color:context:usage_contexts
if [[ "$line" =~ ^([^:]+):([^:]+):([^:]+):(.+)$ ]]; then
local name="${BASH_REMATCH[1]}"
local color="${BASH_REMATCH[2]}"
local context="${BASH_REMATCH[3]}"
local usage="${BASH_REMATCH[4]}"
LABEL_COLORS["$name"]="$color"
LABEL_CONTEXTS["$name"]="$context"
LABEL_USAGES["$name"]="$usage"
log_info "Loaded label: $name ($context)"
fi
done < "$REGISTRY_FILE"
log_success "Loaded ${#LABEL_COLORS[@]} labels from registry"
}
# Generate label definitions section for scripts
generate_label_definitions() {
cat << 'EOF'
# === LABEL DEFINITIONS START ===
# This section is auto-maintained by update_script_labels.sh
# DO NOT EDIT MANUALLY - Changes will be overwritten
declare -A LABEL_DEFINITIONS=(
EOF
for label in "${!LABEL_COLORS[@]}"; do
local color="${LABEL_COLORS[$label]}"
local context="${LABEL_CONTEXTS[$label]}"
local usage="${LABEL_USAGES[$label]}"
echo " [\"$label\"]=\"color:$color;context:$context;usage:$usage\""
done
cat << 'EOF'
)
# Extract label info
get_label_color() { echo "${LABEL_DEFINITIONS[$1]}" | cut -d';' -f1 | cut -d':' -f2; }
get_label_context() { echo "${LABEL_DEFINITIONS[$1]}" | cut -d';' -f2 | cut -d':' -f2; }
get_label_usage() { echo "${LABEL_DEFINITIONS[$1]}" | cut -d';' -f3 | cut -d':' -f2; }
# Check if label is valid for context
is_label_valid_for_context() {
local label="$1"
local context="$2"
local usage=$(get_label_usage "$label")
[[ "$usage" == *"$context"* ]] || [[ "$usage" == "all_templates" ]]
}
# === LABEL DEFINITIONS END ===
EOF
}
# Generate template-to-labels mapping - FIXED VERSION
generate_template_mappings() {
cat << 'EOF'
# === TEMPLATE LABEL MAPPINGS START ===
# Auto-generated template to label mappings
declare -A TEMPLATE_LABELS=(
EOF
# 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]}"
# 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_name\"]=\"$label_list\""
fi
done
cat << 'EOF'
)
# === TEMPLATE LABEL MAPPINGS END ===
EOF
}
# Generate filter options for get_issues.sh
generate_filter_options() {
cat << 'EOF'
# === FILTER OPTIONS START ===
# Auto-generated filter options for get_issues.sh
show_filter_help() {
echo "📋 Available filters:"
EOF
# Group labels by context for better help display
declare -A context_labels
for label in "${!LABEL_CONTEXTS[@]}"; do
local context="${LABEL_CONTEXTS[$label]}"
if [[ -z "${context_labels[$context]}" ]]; then
context_labels[$context]="$label"
else
context_labels[$context]="${context_labels[$context]},$label"
fi
done
for context in "${!context_labels[@]}"; do
echo " echo \" $context: ${context_labels[$context]}\""
done
cat << 'EOF'
}
# Filter case statement
handle_filter() {
local filter="$1"
case "$filter" in
EOF
for label in "${!LABEL_COLORS[@]}"; do
echo " $label) filter_by_label \"$label\" ;;"
done
cat << 'EOF'
pipeline) show_pipeline_overview ;;
stats) show_statistics ;;
all) show_all_issues ;;
*)
log_error "Unknown filter: $filter"
show_filter_help
exit 1
;;
esac
}
# === FILTER OPTIONS END ===
EOF
}
# Update a single script file
update_script_file() {
local script_file="$1"
if [[ ! -f "$script_file" ]]; then
log_warning "Script not found: $script_file"
return 1
fi
log_info "Updating $script_file..."
# Create backup
cp "$script_file" "${script_file}.backup"
# Check if script has label definition sections
if ! grep -q "# === LABEL DEFINITIONS START ===" "$script_file"; then
log_warning "$script_file has no label definitions section - skipping"
return 0
fi
# Find section boundaries
local start_line=$(grep -n "# === LABEL DEFINITIONS START ===" "$script_file" | cut -d: -f1)
local end_line=$(grep -n "# === LABEL DEFINITIONS END ===" "$script_file" | cut -d: -f1)
if [[ -z "$start_line" ]] || [[ -z "$end_line" ]]; then
log_error "Malformed label definition section in $script_file"
return 1
fi
# Generate new content
local new_definitions=$(generate_label_definitions)
# Handle template mappings if present
if grep -q "# === TEMPLATE LABEL MAPPINGS START ===" "$script_file"; then
new_definitions+="\n$(generate_template_mappings)"
fi
# Handle filter options if present (for get_issues.sh)
if grep -q "# === FILTER OPTIONS START ===" "$script_file"; then
new_definitions+="\n$(generate_filter_options)"
fi
# Create temporary file with updated content
local temp_file=$(mktemp)
# Copy everything before label definitions
sed -n "1,$((start_line-1))p" "$script_file" > "$temp_file"
# Add new definitions
echo -e "$new_definitions" >> "$temp_file"
# Copy everything after label definitions (find new end line)
if grep -q "# === TEMPLATE LABEL MAPPINGS END ===" "$script_file"; then
local actual_end_line=$(grep -n "# === TEMPLATE LABEL MAPPINGS END ===" "$script_file" | cut -d: -f1)
elif grep -q "# === FILTER OPTIONS END ===" "$script_file"; then
local actual_end_line=$(grep -n "# === FILTER OPTIONS END ===" "$script_file" | cut -d: -f1)
else
local actual_end_line="$end_line"
fi
sed -n "$((actual_end_line+1)),\$p" "$script_file" >> "$temp_file"
# Replace original file
mv "$temp_file" "$script_file"
chmod +x "$script_file"
log_success "Updated $script_file"
}
# Add new label to registry
add_label_to_registry() {
local name="$1"
local color="${2:-ff6b6b}"
local context="${3:-auto_generated}"
local usage="${4:-manual_assignment}"
# Skip if called during auto-update to prevent loops
if [[ "${FURT_AUTO_UPDATE:-}" == "true" ]]; then
log_info "Auto-update mode: Adding $name to registry (skipping rebuild)"
else
log_info "Adding new label to registry: $name"
fi
# Ensure registry exists
create_registry_if_missing
# Check if label already exists
if grep -q "^$name:" "$REGISTRY_FILE"; then
log_warning "Label $name already exists in registry"
return 0
fi
# Add to appropriate section (determine by context)
local section_marker="# === CORE WORKFLOW LABELS ==="
if [[ "$context" == *"service"* ]] || [[ "$name" == service-* ]]; then
section_marker="# === SERVICE-SPECIFIC LABELS ==="
elif [[ "$context" == *"workflow"* ]]; then
section_marker="# === WORKFLOW STATE LABELS ==="
elif [[ "$context" == *"component"* ]]; then
section_marker="# === COMPONENT CATEGORIES ==="
fi
# Create backup
cp "$REGISTRY_FILE" "${REGISTRY_FILE}.backup"
# Find section and add label
local temp_file=$(mktemp)
local added=false
while IFS= read -r line; do
echo "$line" >> "$temp_file"
if [[ "$line" == "$section_marker" ]] && [[ "$added" == false ]]; then
echo "$name:$color:$context:$usage" >> "$temp_file"
added=true
log_success "Added label $name to registry"
fi
done < "$REGISTRY_FILE"
mv "$temp_file" "$REGISTRY_FILE"
}
# Show current registry status
show_registry_status() {
echo "📊 Label Registry Status"
echo "========================"
echo "Registry file: $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
main() {
local command="${1:-update}"
case "$command" in
update)
log_info "Starting label synchronization..."
parse_registry
# Update all script files
local scripts=(
"$PROJECT_ROOT/scripts/create_issue.sh"
"$PROJECT_ROOT/scripts/get_issues.sh"
"$PROJECT_ROOT/scripts/update_issue.sh"
)
for script in "${scripts[@]}"; do
update_script_file "$script"
done
log_success "All scripts synchronized with label registry!"
;;
add)
local name="$2"
local color="${3:-ff6b6b}"
local context="${4:-auto_generated}"
local usage="${5:-manual_assignment}"
if [[ -z "$name" ]]; then
log_error "Usage: $0 add <name> [color] [context] [usage]"
exit 1
fi
add_label_to_registry "$name" "$color" "$context" "$usage"
# Only update scripts if not in auto-update mode
if [[ "${FURT_AUTO_UPDATE:-}" != "true" ]]; then
parse_registry
main update
fi
;;
status)
show_registry_status
;;
help)
echo "Usage: $0 [command] [options]"
echo ""
echo "Commands:"
echo " update Update all scripts with current registry"
echo " add <name> Add new label to registry and update scripts"
echo " status Show registry status"
echo " help Show this help"
echo ""
echo "Examples:"
echo " $0 update"
echo " $0 add newsletter ff6b6b newsletter_service service_templates"
echo " $0 status"
;;
*)
log_error "Unknown command: $command"
main help
exit 1
;;
esac
}
# Run if executed directly
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
main "$@"
fi