refactor: PipelineManager split into 4 files (776 to 438 lines)
This commit is contained in:
1 parent
419dd160b8
commit
3f033e9db8
5 files changed
+506
-376
No files matched your search
@@ -0,0 +1,91 @@
|
||||
import { Badge } from '@/components/ui/badge';
|
||||
import { CheckCircle, XCircle, Loader2 } from 'lucide-react';
|
||||
|
||||
// 流水线阶段定义 // 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: any): 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: any) {
|
||||
switch (status) {
|
||||
case 'success':
|
||||
return (
|
||||
<Badge variant="outline" className="border-emerald-500/30 text-emerald-400 bg-emerald-500/10">
|
||||
<CheckCircle className="h-3 w-3 mr-1" />
|
||||
成功
|
||||
</Badge>
|
||||
);
|
||||
case 'failed':
|
||||
return (
|
||||
<Badge variant="outline" className="border-red-500/30 text-red-400 bg-red-500/10">
|
||||
<XCircle className="h-3 w-3 mr-1" />
|
||||
失败
|
||||
</Badge>
|
||||
);
|
||||
case 'running':
|
||||
return (
|
||||
<Badge variant="outline" className="border-blue-500/30 text-blue-400 bg-blue-500/10 animate-pulse">
|
||||
<Loader2 className="h-3 w-3 mr-1 animate-spin" />
|
||||
运行中
|
||||
</Badge>
|
||||
);
|
||||
default:
|
||||
return (
|
||||
<Badge variant="outline" className="border-[var(--dg-border)] text-[var(--dg-text-secondary)]">
|
||||
从未运行
|
||||
</Badge>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// 阶段状态图标 // Logan.Li
|
||||
export function getStageStatusIcon(status: PipelineStage['status']) {
|
||||
switch (status) {
|
||||
case 'success':
|
||||
return <CheckCircle className="h-4 w-4 text-emerald-400" />;
|
||||
case 'failed':
|
||||
return <XCircle className="h-4 w-4 text-red-400" />;
|
||||
case 'running':
|
||||
return <Loader2 className="h-4 w-4 text-blue-400 animate-spin" />;
|
||||
case 'skipped':
|
||||
return <span className="text-[var(--dg-text-secondary)] text-xs">跳过</span>;
|
||||
default:
|
||||
return <span className="text-[var(--dg-text-secondary)] opacity-60 text-xs">待执行</span>;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user