feat(platform): support native server filterBy, workflow compact list and auto-corp credentials

This commit is contained in:
gitea committed 2026-10-22 16:50:25 +08:00
1 parent deed5a5628
commit 975f76af74
10 files changed
+483 -28

No files matched your search

+42 -9
View File
@@ -14,36 +14,62 @@ export async function handleList(parsed: CliParsedArgs, runtime: CliRuntime): Pr
const page = numberOption(parsed.options, ["page"]) || 1;
const pageSize = numberOption(parsed.options, ["pageSize", "size"]) || 50;
const filterPlatformId = stringOption(parsed.options, PLATFORM_ID_OPTION_KEYS);
const keyword = stringOption(parsed.options, ["keyword", "q", "query"]);
const isFull = booleanOption(parsed.options, ["full", "with-tasks", "withTasks"], false);
const rawResult = await listAllWorkflows(clients, { page, pageSize });
const workflows = filterPlatformId
let workflows = filterPlatformId
? rawResult.workflows.filter(
(wf) => wf.platformId === filterPlatformId || wf.platformName === filterPlatformId
)
: rawResult.workflows;
const result = filterPlatformId
? { ...rawResult, workflows, totalWorkflows: workflows.length }
: rawResult;
if (keyword) {
const kw = keyword.toLowerCase();
workflows = workflows.filter(
(wf) =>
wf.pipelineName.toLowerCase().includes(kw) ||
wf.id.toLowerCase().includes(kw) ||
Boolean(wf.platformName && wf.platformName.toLowerCase().includes(kw))
);
}
// 默认轻量化模式:列表态剥离庞大的 tasks 节点树与代码脚本,只输出核心元数据和节点数统计
const outputWorkflows = isFull
? workflows
: workflows.map(({ tasks, ...rest }) => ({
...rest,
nodeCount: tasks?.length ?? 0,
}));
const result = {
...rawResult,
workflows: outputWorkflows,
totalWorkflows: workflows.length,
};
if (runtime.jsonMode) {
return { stdout: printJson(result, runtime.outputOptions), stderr: "", exitCode: 0 };
}
if (result.workflows.length === 0) {
if (workflows.length === 0) {
const emptyMsg = keyword
? `企业 [${runtime.selectedCorp!.name}] 下未找到包含关键词 "${keyword}" 的工作流\n`
: `企业 [${runtime.selectedCorp!.name}] 下暂无工作流\n`;
return {
stdout: `企业 [${runtime.selectedCorp!.name}] 下暂无工作流\n`,
stdout: emptyMsg,
stderr: "",
exitCode: 0,
};
}
const rows = result.workflows.map((wf, i) => [
const rows = workflows.map((wf, i) => [
i + 1,
wf.id,
wf.pipelineName,
wf.platformName || wf.platformId || "-",
wf.state === 1 ? "🟢 启用" : "⚪ 停用",
wf.tasks?.length ?? "-",
wf.tasks?.length ?? (wf as any).nodeCount ?? "-",
]);
const table = printTable(
@@ -51,8 +77,15 @@ export async function handleList(parsed: CliParsedArgs, runtime: CliRuntime): Pr
rows
);
const filterDesc = [
filterPlatformId ? `应用: ${filterPlatformId}` : "",
keyword ? `关键词: "${keyword}"` : "",
].filter(Boolean).join(", ");
const titleSuffix = filterDesc ? ` (过滤: ${filterDesc}, 共 ${workflows.length} 条)` : ` (共 ${workflows.length} 条)`;
return {
stdout: `====== [${runtime.selectedCorp!.name}] 工作流列表 (共 ${result.workflows.length} 条) ======\n${table}\n`,
stdout: `====== [${runtime.selectedCorp!.name}] 工作流列表${titleSuffix} ======\n${table}\n`,
stderr: "",
exitCode: 0,
};