mirror of
https://github.com/certd/certd.git
synced 2026-04-23 19:57:27 +08:00
chore: 模版创建流水线
This commit is contained in:
@@ -52,6 +52,7 @@ export class CnameProviderService extends BaseService<CnameProviderEntity> {
|
||||
}
|
||||
}
|
||||
|
||||
//@ts-ignore
|
||||
async delete(ids: any) {
|
||||
if (!ids) {
|
||||
return;
|
||||
|
||||
@@ -37,6 +37,9 @@ export class PipelineEntity {
|
||||
@Column({ comment: '来源', nullable: true, default: '' })
|
||||
from: string;
|
||||
|
||||
@Column({ name:"template_id", comment: '是否模版', nullable: true, default: '' })
|
||||
templateId: number;
|
||||
|
||||
@Column({
|
||||
name: 'last_history_time',
|
||||
comment: '最后一次执行时间',
|
||||
|
||||
@@ -46,6 +46,7 @@ import {UserSuiteEntity, UserSuiteService} from "@certd/commercial-core";
|
||||
import {CertInfoService} from "../../monitor/service/cert-info-service.js";
|
||||
import {TaskServiceBuilder} from "./task-service-getter.js";
|
||||
import {nanoid} from "nanoid";
|
||||
import {set} from "lodash-es";
|
||||
|
||||
const runningTasks: Map<string | number, Executor> = new Map();
|
||||
|
||||
@@ -117,6 +118,8 @@ export class PipelineService extends BaseService<PipelineEntity> {
|
||||
}
|
||||
|
||||
async page(pageReq: PageReq<PipelineEntity>) {
|
||||
//模版流水线不要被查询出来
|
||||
set(pageReq,"query.templateId",0)
|
||||
const result = await super.page(pageReq);
|
||||
await this.fillLastVars(result.records);
|
||||
|
||||
@@ -281,6 +284,7 @@ export class PipelineService extends BaseService<PipelineEntity> {
|
||||
},
|
||||
where: {
|
||||
disabled: false,
|
||||
templateId: 0,
|
||||
},
|
||||
});
|
||||
const ids = idEntityList.map(item => {
|
||||
@@ -385,7 +389,8 @@ export class PipelineService extends BaseService<PipelineEntity> {
|
||||
}
|
||||
}
|
||||
|
||||
async delete(id: any) {
|
||||
//@ts-ignore
|
||||
async delete(id:any) {
|
||||
await this.clearTriggers(id);
|
||||
//TODO 删除storage
|
||||
// const storage = new DbStorage(pipeline.userId, this.storageService);
|
||||
|
||||
@@ -1,12 +1,15 @@
|
||||
import {Inject, Provide, Scope, ScopeEnum} from '@midwayjs/core';
|
||||
import {BaseService, SysSettingsService} from '@certd/lib-server';
|
||||
import {InjectEntityModel} from '@midwayjs/typeorm';
|
||||
import {Repository} from 'typeorm';
|
||||
import { TemplateEntity } from '../entity/template.js';
|
||||
import { PipelineService } from './pipeline-service.js';
|
||||
import {In, Repository} from 'typeorm';
|
||||
import {TemplateEntity} from '../entity/template.js';
|
||||
import {PipelineService} from './pipeline-service.js';
|
||||
import {cloneDeep} from "lodash-es";
|
||||
import {PipelineEntity} from "../entity/pipeline.js";
|
||||
import {Pipeline} from "@certd/pipeline";
|
||||
|
||||
@Provide()
|
||||
@Scope(ScopeEnum.Request, { allowDowngrade: true })
|
||||
@Scope(ScopeEnum.Request, {allowDowngrade: true})
|
||||
export class TemplateService extends BaseService<TemplateEntity> {
|
||||
@InjectEntityModel(TemplateEntity)
|
||||
repository: Repository<TemplateEntity>;
|
||||
@@ -22,6 +25,47 @@ export class TemplateService extends BaseService<TemplateEntity> {
|
||||
return this.repository;
|
||||
}
|
||||
|
||||
async add(param: any) {
|
||||
const pipelineId = param.pipelineId;
|
||||
delete param.pipelineId;
|
||||
|
||||
const pipelineEntity = await this.pipelineService.info(pipelineId);
|
||||
if (!pipelineEntity) {
|
||||
throw new Error('pipeline not found');
|
||||
}
|
||||
if (pipelineEntity.userId !== param.userId) {
|
||||
throw new Error('permission denied');
|
||||
}
|
||||
|
||||
|
||||
let template = null
|
||||
await this.transaction(async (tx: any) => {
|
||||
|
||||
template = await tx.getRepository(TemplateEntity).save(param);
|
||||
let newPipeline = cloneDeep(pipelineEntity)
|
||||
//创建pipeline模版
|
||||
newPipeline.id = undefined;
|
||||
newPipeline.title = template.title+"模版流水线"
|
||||
newPipeline.templateId = template.id
|
||||
|
||||
const pipelineJson:Pipeline = JSON.parse(newPipeline.content)
|
||||
delete pipelineJson.triggers
|
||||
pipelineJson.id = template.id
|
||||
pipelineJson.userId = template.userId
|
||||
pipelineJson.title = newPipeline.title
|
||||
newPipeline.content = JSON.stringify(pipelineJson)
|
||||
newPipeline = await tx.getRepository(PipelineEntity).save(newPipeline)
|
||||
|
||||
const update :any= {}
|
||||
update.id = template.id
|
||||
update.pipelineId = newPipeline.id
|
||||
await tx.getRepository(TemplateEntity).save(update)
|
||||
})
|
||||
|
||||
return template
|
||||
|
||||
}
|
||||
|
||||
async detail(id: number, userId: number) {
|
||||
const info = await this.info(id)
|
||||
if (!info) {
|
||||
@@ -30,12 +74,31 @@ export class TemplateService extends BaseService<TemplateEntity> {
|
||||
if (info.userId !== userId) {
|
||||
throw new Error('无权限');
|
||||
}
|
||||
const pipeline = await this.pipelineService.info(info.pipelineId);
|
||||
let pipeline = null
|
||||
if (info.pipelineId) {
|
||||
const pipelineEntity = await this.pipelineService.info(info.pipelineId);
|
||||
pipeline = JSON.parse(pipelineEntity.content)
|
||||
}
|
||||
|
||||
|
||||
return {
|
||||
template:info,
|
||||
pipeline: JSON.parse(pipeline.content),
|
||||
template: info,
|
||||
pipeline,
|
||||
}
|
||||
}
|
||||
async batchDelete(ids: number[], userId: number) {
|
||||
|
||||
const where :any= {
|
||||
id: In(ids),
|
||||
}
|
||||
if (userId > 0) {
|
||||
where.userId = userId
|
||||
}
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -129,6 +129,7 @@ export class RoleService extends BaseService<RoleEntity> {
|
||||
return permissionSet;
|
||||
}
|
||||
|
||||
//@ts-ignore
|
||||
async delete(id: any) {
|
||||
const idArr = this.resolveIdArr(id);
|
||||
//@ts-ignore
|
||||
|
||||
@@ -253,6 +253,7 @@ export class UserService extends BaseService<UserEntity> {
|
||||
await this.update(param);
|
||||
}
|
||||
|
||||
//@ts-ignore
|
||||
async delete(ids: any) {
|
||||
if (typeof ids === 'string') {
|
||||
ids = ids.split(',');
|
||||
|
||||
Reference in New Issue
Block a user