mirror of
https://github.com/certd/certd.git
synced 2026-04-23 11:37:23 +08:00
chore: 模版创建流水线
This commit is contained in:
@@ -37,9 +37,12 @@ export class PipelineEntity {
|
||||
@Column({ comment: '来源', nullable: true, default: '' })
|
||||
from: string;
|
||||
|
||||
@Column({ name:"template_id", comment: '是否模版', nullable: true, default: '' })
|
||||
@Column({ name:"template_id", comment: '关联模版id', nullable: true, default: 0 })
|
||||
templateId: number;
|
||||
|
||||
@Column({ name:"is_template", comment: '是否模版', nullable: true, default: false })
|
||||
isTemplate: boolean;
|
||||
|
||||
@Column({
|
||||
name: 'last_history_time',
|
||||
comment: '最后一次执行时间',
|
||||
|
||||
@@ -23,6 +23,8 @@ export class TemplateEntity {
|
||||
|
||||
@Column({ name: 'title', comment: '标题' })
|
||||
title: string;
|
||||
@Column({ name: 'desc', comment: '说明' })
|
||||
desc: string;
|
||||
|
||||
@Column({ comment: '配置', length: 40960 })
|
||||
content: string;
|
||||
|
||||
@@ -119,7 +119,7 @@ export class PipelineService extends BaseService<PipelineEntity> {
|
||||
|
||||
async page(pageReq: PageReq<PipelineEntity>) {
|
||||
//模版流水线不要被查询出来
|
||||
set(pageReq,"query.templateId",0)
|
||||
set(pageReq,"query.isTemplate",false)
|
||||
const result = await super.page(pageReq);
|
||||
await this.fillLastVars(result.records);
|
||||
|
||||
|
||||
@@ -45,10 +45,11 @@ export class TemplateService extends BaseService<TemplateEntity> {
|
||||
let newPipeline = cloneDeep(pipelineEntity)
|
||||
//创建pipeline模版
|
||||
newPipeline.id = undefined;
|
||||
newPipeline.title = template.title+"模版流水线"
|
||||
newPipeline.title = template.title + "模版流水线"
|
||||
newPipeline.templateId = template.id
|
||||
newPipeline.isTemplate = true
|
||||
|
||||
const pipelineJson:Pipeline = JSON.parse(newPipeline.content)
|
||||
const pipelineJson: Pipeline = JSON.parse(newPipeline.content)
|
||||
delete pipelineJson.triggers
|
||||
pipelineJson.id = template.id
|
||||
pipelineJson.userId = template.userId
|
||||
@@ -56,7 +57,7 @@ export class TemplateService extends BaseService<TemplateEntity> {
|
||||
newPipeline.content = JSON.stringify(pipelineJson)
|
||||
newPipeline = await tx.getRepository(PipelineEntity).save(newPipeline)
|
||||
|
||||
const update :any= {}
|
||||
const update: any = {}
|
||||
update.id = template.id
|
||||
update.pipelineId = newPipeline.id
|
||||
await tx.getRepository(TemplateEntity).save(update)
|
||||
@@ -86,19 +87,40 @@ export class TemplateService extends BaseService<TemplateEntity> {
|
||||
pipeline,
|
||||
}
|
||||
}
|
||||
|
||||
async batchDelete(ids: number[], userId: number) {
|
||||
|
||||
const where :any= {
|
||||
const where: any = {
|
||||
id: In(ids),
|
||||
}
|
||||
if (userId > 0) {
|
||||
where.userId = userId
|
||||
}
|
||||
const list = await this.getRepository().find({where })
|
||||
const list = await this.getRepository().find({where})
|
||||
ids = list.map(item => item.id)
|
||||
const pipelineIds = list.map(item => item.pipelineId)
|
||||
await this.delete(ids);
|
||||
await this.pipelineService.batchDelete(pipelineIds,userId)
|
||||
await this.pipelineService.batchDelete(pipelineIds, userId)
|
||||
}
|
||||
|
||||
async createPipelineByTemplate(body: PipelineEntity) {
|
||||
const templateId = body.templateId;
|
||||
const template = await this.info(templateId);
|
||||
|
||||
if (!template && template.userId !== body.userId) {
|
||||
throw new Error('模板不存在');
|
||||
}
|
||||
|
||||
const tempPipeline = await this.pipelineService.info(template.pipelineId)
|
||||
|
||||
const newPipeline = {
|
||||
type: tempPipeline.type,
|
||||
from : "template",
|
||||
keepHistoryCount: tempPipeline.keepHistoryCount,
|
||||
... body,
|
||||
}
|
||||
|
||||
await this.pipelineService.save(newPipeline)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user