import { Badge } from '@/components/ui/badge'; import { CheckCircle, XCircle, Loader2 } from 'lucide-react'; import type { JsonData } from '@/types/common'; // 流水线阶段定义 // Logan.Li export interface PipelineStage { id: string; name: string; status: 'pending' | 'running' | 'success' | 'failed' | 'skipped'; duration: string; logs: string[]; } // 流水线模板(新建时快捷选择) // Logan.Li export const pipelineTemplates = [ { id: 'template-1', name: 'Node.js 项目', description: '适用于 Node.js 前端项目', stages: ['代码检出', '依赖安装', '代码检查', '构建打包', '部署'] }, { id: 'template-2', name: 'Go 项目', description: '适用于 Go 后端项目', stages: ['代码检出', '单元测试', '构建', '构建镜像', '部署'] }, { id: 'template-3', name: 'Java 项目', description: '适用于 Java Spring Boot 项目', stages: ['代码检出', 'Maven构建', '单元测试', '打包', '部署'] }, { id: 'template-4', name: 'Python 项目', description: '适用于 Python 项目', stages: ['代码检出', '依赖安装', '代码检查', '测试', '部署'] }, ]; // 解析 stages 字段(兼容 JSON 数组 / 逗号分隔字符串) // Logan.Li export function parseStages( stages: string): PipelineStage[] { if (Array.isArray(stages)) return stages; if (typeof stages === 'string') { try { const parsed = JSON.parse(stages); if (Array.isArray(parsed)) return parsed; } catch { return stages.split(',').map((s, i) => ({ id: `stage-${i + 1}`, name: s.trim(), status: 'success' as const, duration: '-', logs: [] })); } } return []; } // 由流水线名称生成 code(kebab-case) // Logan.Li export function nameToCode(name: string): string { return name .toLowerCase() .replace(/[^a-z0-9]/g, '-') .replace(/-+/g, '-') .replace(/^-|-$/g, '') || `pipeline-${Date.now()}`; } // 状态徽章(使用后端 last_status 字段) // Logan.Li export function getStatusBadge( status: string) { switch (status) { case 'success': return ( 成功 ); case 'failed': return ( 失败 ); case 'running': return ( 运行中 ); default: return ( 从未运行 ); } } // 阶段状态图标 // Logan.Li export function getStageStatusIcon(status: PipelineStage['status']) { switch (status) { case 'success': return ; case 'failed': return ; case 'running': return ; case 'skipped': return 跳过; default: return 待执行; } }