#!/bin/bash # Drama Ling 問題建立工具 # 用途:快速建立和記錄問題 # 使用方法: ./create_issue.sh "問題標題" [優先級] [模組] SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" PROJECT_ROOT="$(dirname "$(dirname "$SCRIPT_DIR")")" ISSUES_FILE="$PROJECT_ROOT/docs/04_technical/issues-tracking.md" # 顏色定義 RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' BLUE='\033[0;34m' NC='\033[0m' # 顯示使用說明 show_help() { echo -e "${BLUE}問題建立工具使用說明:${NC}" echo "使用方法: $0 \"問題標題\" [優先級] [模組]" echo "" echo -e "${BLUE}優先級:${NC}" echo " critical - 🔴 Critical (嚴重)" echo " important - 🟡 Important (重要)" echo " normal - 🔵 Normal (一般)" echo " low - 🟢 Low (輕微)" echo "" echo -e "${BLUE}模組:${NC}" echo " auth - 認證系統" echo " learning - 學習內容" echo " ui - 使用者介面" echo " api - API 規格" echo " db - 資料庫" echo " docs - 文檔" echo "" echo -e "${BLUE}範例:${NC}" echo " $0 \"API endpoint naming conflict\" critical api" echo " $0 \"UI component specification unclear\" important ui" } # 獲取下一個問題編號 get_next_issue_number() { if [ ! -f "$ISSUES_FILE" ]; then echo "001" return fi # 從問題追蹤檔案中找到最大的問題編號 local max_num=$(grep -o "Issue #[0-9]*" "$ISSUES_FILE" | grep -o "[0-9]*" | sort -n | tail -1) if [ -z "$max_num" ]; then echo "001" else printf "%03d" $((10#$max_num + 1)) fi } # 轉換優先級格式 format_priority() { case $1 in critical|1) echo "🔴 Critical" ;; important|2) echo "🟡 Important" ;; normal|3) echo "🔵 Normal" ;; low|4) echo "🟢 Low" ;; *) echo "🔵 Normal" ;; esac } # 轉換模組格式 format_module() { case $1 in auth) echo "認證系統" ;; learning) echo "學習內容" ;; ui) echo "使用者介面" ;; api) echo "API 規格" ;; db) echo "資料庫" ;; docs) echo "文檔" ;; *) echo "一般" ;; esac } # 建立問題 create_issue() { local title="$1" local priority="$2" local module="$3" if [ -z "$title" ]; then echo -e "${RED}❌ 錯誤: 請提供問題標題${NC}" show_help exit 1 fi # 預設值 priority=${priority:-"normal"} module=${module:-"general"} local issue_number=$(get_next_issue_number) local formatted_priority=$(format_priority "$priority") local formatted_module=$(format_module "$module") local current_date=$(date +"%Y-%m-%d") # 建立問題內容 local issue_content=" --- ## Issue #${issue_number} - ${title} **優先級**: ${formatted_priority} **狀態**: Open **標籤**: \`type:spec\` \`module:${module}\` \`status:open\` **建立日期**: ${current_date} **負責人**: [待指派] **預計解決**: [待設定] ### 問題描述 [請詳細描述問題的內容、影響範圍和背景資訊] ### 相關文件 - 檔案: [檔案路徑:行號] ### 可能解決方案 1. 方案A: [待分析] - 優點: [待列出] - 缺點: [待列出] ### 決議 [待決定] ### 執行紀錄 - ${current_date}: 建立問題 " # 確保問題追蹤檔案存在 if [ ! -f "$ISSUES_FILE" ]; then echo -e "${YELLOW}⚠️ 問題追蹤檔案不存在,將建立新檔案${NC}" touch "$ISSUES_FILE" fi # 在問題追蹤看板區域之前添加新問題 if grep -q "## 📊 問題追蹤看板" "$ISSUES_FILE"; then # 找到看板區域,在其前面插入問題 awk '/## 📊 問題追蹤看板/ { print "'"${issue_content}"'"; print; next } 1' "$ISSUES_FILE" > "${ISSUES_FILE}.tmp" && mv "${ISSUES_FILE}.tmp" "$ISSUES_FILE" else # 如果沒有看板區域,直接添加到檔案末尾 echo "$issue_content" >> "$ISSUES_FILE" fi echo -e "${GREEN}✅ 問題 #${issue_number} 建立成功!${NC}" echo -e "標題: ${title}" echo -e "優先級: ${formatted_priority}" echo -e "模組: ${formatted_module}" echo -e "檔案: ${ISSUES_FILE}" # 詢問是否要開啟編輯器 read -p "是否要開啟編輯器完善問題描述? (y/N): " edit_choice if [[ $edit_choice =~ ^[Yy]$ ]]; then ${EDITOR:-nano} "$ISSUES_FILE" fi } # 主程式 main() { if [ "$1" = "help" ] || [ "$1" = "--help" ] || [ "$1" = "-h" ]; then show_help exit 0 fi create_issue "$1" "$2" "$3" } # 執行主程式 main "$@"