#!/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