fix: 修复复制流水线出现的各种问题

This commit is contained in:
xiaojunnuo
2024-09-03 11:42:05 +08:00
parent 5ade12d700
commit 6314e8d7eb
3 changed files with 79 additions and 21 deletions
@@ -10,11 +10,52 @@ import { env } from "/@/utils/util.env";
import { useUserStore } from "/@/store/modules/user";
import dayjs from "dayjs";
import { useSettingStore } from "/@/store/modules/settings";
import _ from "lodash-es";
export default function ({ crudExpose, context: { certdFormRef } }: CreateCrudOptionsProps): CreateCrudOptionsRet {
const router = useRouter();
const { t } = useI18n();
const lastResRef = ref();
function setRunnableIds(pipeline: any) {
const idMap: any = {};
function createId(oldId: any) {
if (oldId == null) {
return nanoid();
}
const newId = nanoid();
idMap[oldId] = newId;
return newId;
}
if (pipeline.stages) {
for (const stage of pipeline.stages) {
stage.id = createId(stage.id);
if (stage.tasks) {
for (const task of stage.tasks) {
task.id = createId(task.id);
if (task.steps) {
for (const step of task.steps) {
step.id = createId(step.id);
}
}
}
}
}
}
for (const trigger of pipeline.triggers) {
trigger.id = nanoid();
}
for (const notification of pipeline.notifications) {
notification.id = nanoid();
}
let content = JSON.stringify(pipeline);
for (const key in idMap) {
content = content.replaceAll(key, idMap[key]);
}
return JSON.parse(content);
}
const pageRequest = async (query: UserPageQuery): Promise<UserPageRes> => {
return await api.GetList(query);
};
@@ -34,9 +75,16 @@ export default function ({ crudExpose, context: { certdFormRef } }: CreateCrudOp
title: form.title
});
} else {
const content = JSON.parse(form.content);
content.title = form.title;
form.content = JSON.stringify(content);
//复制的流水线
delete form.status;
delete form.lastHistoryTime;
delete form.lastVars;
delete form.createTime;
delete form.id;
let pipeline = JSON.parse(form.content);
pipeline.title = form.title;
pipeline = setRunnableIds(pipeline);
form.content = JSON.stringify(pipeline);
}
const res = await api.AddObj(form);
@@ -48,12 +96,11 @@ export default function ({ crudExpose, context: { certdFormRef } }: CreateCrudOp
// 添加certd pipeline
const triggers = [];
if (form.triggerCron) {
triggers.push({ id: nanoid(), title: "定时触发", type: "timer", props: { cron: form.triggerCron } });
triggers.push({ title: "定时触发", type: "timer", props: { cron: form.triggerCron } });
}
const notifications = [];
if (form.emailNotify) {
notifications.push({
id: nanoid(),
type: "email",
when: ["error", "turnToSuccess"],
options: {
@@ -61,19 +108,16 @@ export default function ({ crudExpose, context: { certdFormRef } }: CreateCrudOp
}
});
}
const pipeline = {
let pipeline = {
title: form.domains[0] + "证书自动化",
stages: [
{
id: nanoid(),
title: "证书申请阶段",
tasks: [
{
id: nanoid(),
title: "证书申请任务",
steps: [
{
id: nanoid(),
title: "申请证书",
input: {
renewDays: 20,
@@ -92,8 +136,10 @@ export default function ({ crudExpose, context: { certdFormRef } }: CreateCrudOp
triggers,
notifications
};
pipeline = setRunnableIds(pipeline);
const id = await api.Save({
title: pipeline.title,
content: JSON.stringify(pipeline),
keepHistoryCount: 30
});
@@ -147,7 +193,8 @@ export default function ({ crudExpose, context: { certdFormRef } }: CreateCrudOp
click: async (context) => {
const { ui } = useUi();
// @ts-ignore
const row = context[ui.tableColumn.row];
let row = context[ui.tableColumn.row];
row = _.cloneDeep(row);
row.title = row.title + "_copy";
await crudExpose.openCopy({
row: row,
@@ -31,7 +31,7 @@
<div class="flow-line"></div>
</div>
<div class="task">
<a-button shape="round" type="primary" @click="run">
<a-button shape="round" type="primary" @click="run()">
<fs-icon icon="ion:play"></fs-icon>
手动触发
</a-button>
@@ -231,7 +231,6 @@ import PiTaskView from "./component/task-view/index.vue";
import PiStatusShow from "./component/status-show.vue";
import _ from "lodash-es";
import { message, Modal, notification } from "ant-design-vue";
import { pluginManager } from "/@/views/certd/pipeline/pipeline/plugin";
import { nanoid } from "nanoid";
import { PipelineDetail, PipelineOptions, PluginGroups, RunHistory } from "./type";
import type { Runnable } from "@certd/pipeline";