Files
ljwx-study/sync_to_plane.sh
2026-01-29 18:29:48 +08:00

151 lines
4.1 KiB
Bash
Executable File

#!/bin/bash
# Plane 项目同步脚本
# 用途:将项目信息同步到 Plane 项目管理系统
set -e
# 配置信息
PLANE_API_KEY="plane_api_d500d9ead4d14a0aa28ef20c15aca11e"
PLANE_URL="http://192.168.1.83:8088"
WORKSPACE="ljwx"
PROJECT_ID="b08817de-98af-4cbd-ae73-c37a095953fe"
# 颜色定义
GREEN='\033[0;32m'
BLUE='\033[0;34m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
echo -e "${BLUE}=== Plane 项目同步工具 ===${NC}\n"
# 函数:创建 Issue
create_issue() {
local title="$1"
local description="$2"
local priority="${3:-medium}"
echo -e "${YELLOW}创建 Issue: ${title}${NC}"
response=$(curl -s -X POST "${PLANE_URL}/api/v1/workspaces/${WORKSPACE}/projects/${PROJECT_ID}/issues/" \
-H "X-API-Key: ${PLANE_API_KEY}" \
-H "Content-Type: application/json" \
-d "{
\"name\": \"${title}\",
\"description_html\": \"${description}\",
\"priority\": \"${priority}\"
}")
issue_id=$(echo "$response" | python3 -c "import sys, json; data=json.load(sys.stdin); print(data.get('sequence_id', 'N/A'))" 2>/dev/null)
if [ "$issue_id" != "N/A" ]; then
echo -e "${GREEN}✅ 成功创建 Issue #${issue_id}${NC}\n"
else
echo -e "❌ 创建失败\n"
fi
}
# 函数:获取项目信息
get_project_info() {
echo -e "${BLUE}📊 项目信息${NC}"
echo "项目名称: 学习助手 Pro (Pager)"
echo "项目路径: $(pwd)"
echo "Git 仓库: $(git config --get remote.origin.url 2>/dev/null || echo 'N/A')"
echo "当前分支: $(git branch --show-current 2>/dev/null || echo 'N/A')"
echo "最新提交: $(git log --oneline -1 2>/dev/null || echo 'N/A')"
echo -e "\n${BLUE}🔗 Plane 链接${NC}"
echo "项目主页: ${PLANE_URL}/ljwx/projects/${PROJECT_ID}"
echo "Issues列表: ${PLANE_URL}/ljwx/projects/${PROJECT_ID}/issues"
echo ""
}
# 函数:列出所有 Issues
list_issues() {
echo -e "${BLUE}📋 现有 Issues${NC}"
curl -s "${PLANE_URL}/api/v1/workspaces/${WORKSPACE}/projects/${PROJECT_ID}/issues/" \
-H "X-API-Key: ${PLANE_API_KEY}" | \
python3 -c "
import sys, json
data = json.load(sys.stdin)
issues = data.get('results', [])
if issues:
for idx, issue in enumerate(issues, 1):
name = issue.get('name', 'Unknown')
seq_id = issue.get('sequence_id', 'N/A')
priority = issue.get('priority', 'none')
state = issue.get('state', 'unknown')
print(f'{idx}. [#{seq_id}] {name} (优先级: {priority})')
else:
print('暂无 Issues')
"
echo ""
}
# 主菜单
show_menu() {
echo -e "${BLUE}请选择操作:${NC}"
echo "1. 查看项目信息"
echo "2. 列出所有 Issues"
echo "3. 创建新 Issue"
echo "4. 在浏览器中打开项目"
echo "5. 退出"
echo ""
read -p "请输入选项 (1-5): " choice
case $choice in
1)
get_project_info
;;
2)
list_issues
;;
3)
read -p "Issue 标题: " title
read -p "Issue 描述: " description
read -p "优先级 (low/medium/high) [medium]: " priority
priority=${priority:-medium}
create_issue "$title" "$description" "$priority"
;;
4)
open "${PLANE_URL}/ljwx/projects/${PROJECT_ID}" 2>/dev/null || \
xdg-open "${PLANE_URL}/ljwx/projects/${PROJECT_ID}" 2>/dev/null || \
echo "请手动打开: ${PLANE_URL}/ljwx/projects/${PROJECT_ID}"
;;
5)
echo "退出"
exit 0
;;
*)
echo "无效选项"
;;
esac
echo ""
read -p "按回车键继续..."
show_menu
}
# 如果没有参数,显示菜单
if [ $# -eq 0 ]; then
show_menu
else
# 命令行模式
case $1 in
info)
get_project_info
;;
list)
list_issues
;;
create)
shift
create_issue "$@"
;;
*)
echo "用法: $0 [info|list|create]"
exit 1
;;
esac
fi