diff --git a/src/pipeline-tasks/dtos/create-pipeline-task.input.ts b/src/pipeline-tasks/dtos/create-pipeline-task.input.ts index 340d50e..3c40445 100644 --- a/src/pipeline-tasks/dtos/create-pipeline-task.input.ts +++ b/src/pipeline-tasks/dtos/create-pipeline-task.input.ts @@ -1,4 +1,4 @@ -import { InputType } from '@nestjs/graphql'; +import { Field, InputType } from '@nestjs/graphql'; import { PipelineUnits } from '../enums/pipeline-units.enum'; @InputType() @@ -7,5 +7,6 @@ export class CreatePipelineTaskInput { commit: string; + @Field(() => PipelineUnits) units: PipelineUnits[]; } diff --git a/src/pipeline-tasks/enums/pipeline-units.enum.ts b/src/pipeline-tasks/enums/pipeline-units.enum.ts index 4c85a25..8048336 100644 --- a/src/pipeline-tasks/enums/pipeline-units.enum.ts +++ b/src/pipeline-tasks/enums/pipeline-units.enum.ts @@ -1,3 +1,5 @@ +import { registerEnumType } from '@nestjs/graphql'; + export enum PipelineUnits { checkout = 'checkout', installDependencies = 'installDependencies', @@ -5,3 +7,8 @@ export enum PipelineUnits { deploy = 'deploy', cleanUp = 'cleanUp', } + +registerEnumType(PipelineUnits, { + name: 'PipelineUnits', + description: '流水线单元', +}); diff --git a/src/pipeline-tasks/models/work-unit-metadata.model.ts b/src/pipeline-tasks/models/work-unit-metadata.model.ts index 4fb2967..1659e11 100644 --- a/src/pipeline-tasks/models/work-unit-metadata.model.ts +++ b/src/pipeline-tasks/models/work-unit-metadata.model.ts @@ -1,5 +1,8 @@ +import { InputType, ObjectType } from '@nestjs/graphql'; import { WorkUnit } from './work-unit.model'; +@InputType('WorkUnitMetadataInput') +@ObjectType() export class WorkUnitMetadata { version = 1; units: WorkUnit[]; diff --git a/src/pipeline-tasks/models/work-unit.model.ts b/src/pipeline-tasks/models/work-unit.model.ts index 20d5977..08191f0 100644 --- a/src/pipeline-tasks/models/work-unit.model.ts +++ b/src/pipeline-tasks/models/work-unit.model.ts @@ -1,6 +1,13 @@ -import { PipelineUnits as PipelineUnitTypes } from '../enums/pipeline-units.enum'; +import { Field, InputType, ObjectType } from '@nestjs/graphql'; +import { + PipelineUnits, + PipelineUnits as PipelineUnitTypes, +} from '../enums/pipeline-units.enum'; +@ObjectType() +@InputType('WorkUnitInput') export class WorkUnit { + @Field(() => PipelineUnits) type: PipelineUnitTypes; scripts: string[]; } diff --git a/src/pipelines/dtos/create-pipeline.input.ts b/src/pipelines/dtos/create-pipeline.input.ts index 100a4fe..9e8d12a 100644 --- a/src/pipelines/dtos/create-pipeline.input.ts +++ b/src/pipelines/dtos/create-pipeline.input.ts @@ -1,6 +1,7 @@ import { InputType } from '@nestjs/graphql'; +import { WorkUnitMetadata } from '../../pipeline-tasks/models/work-unit-metadata.model'; import { - IsObject, + IsInstance, IsOptional, IsString, IsUUID, @@ -21,6 +22,6 @@ export class CreatePipelineInput { name: string; @IsOptional() - @IsObject() - workUnitMetadata = {}; + @IsInstance(WorkUnitMetadata) + workUnitMetadata: WorkUnitMetadata; } diff --git a/src/pipelines/pipelines.resolver.ts b/src/pipelines/pipelines.resolver.ts index 6c65fd6..ac80865 100644 --- a/src/pipelines/pipelines.resolver.ts +++ b/src/pipelines/pipelines.resolver.ts @@ -9,7 +9,7 @@ import { ListPipelineArgs } from './dtos/list-pipelines.args'; export class PipelinesResolver { constructor(private readonly service: PipelinesService) {} @Query(() => [Pipeline]) - async findPipelines(@Args('listPipelineArgs') dto: ListPipelineArgs) { + async findPipelines(@Args() dto: ListPipelineArgs) { return await this.service.list(dto); } diff --git a/src/repos/dtos/checkout.input.ts b/src/repos/dtos/checkout.input.ts index 0694ad7..6bacda6 100644 --- a/src/repos/dtos/checkout.input.ts +++ b/src/repos/dtos/checkout.input.ts @@ -4,7 +4,7 @@ import { IsOptional, IsString, IsUUID } from 'class-validator'; @InputType() export class CheckoutInput { @IsUUID() - projectId: string; + pipelineId: string; @IsString() @IsOptional() diff --git a/src/repos/repos.resolver.ts b/src/repos/repos.resolver.ts index aba422c..5da9bac 100644 --- a/src/repos/repos.resolver.ts +++ b/src/repos/repos.resolver.ts @@ -1,18 +1,13 @@ -import { Args, Mutation, Query, Resolver } from '@nestjs/graphql'; +import { Args, Query, Resolver } from '@nestjs/graphql'; import { ListLogsArgs } from './dtos/list-logs.args'; import { ReposService } from './repos.service'; import { LogList } from './dtos/log-list.model'; import { ListBranchesArgs } from './dtos/list-branches.args'; import { BranchList } from './dtos/branch-list.model'; -import { CheckoutInput } from './dtos/checkout.input'; -import { ProjectsService } from '../projects/projects.service'; @Resolver() export class ReposResolver { - constructor( - private readonly service: ReposService, - private readonly projectService: ProjectsService, - ) {} + constructor(private readonly service: ReposService) {} @Query(() => LogList) async listLogs(@Args('listLogsArgs') dto: ListLogsArgs) { return await this.service.listLogs(dto); @@ -28,10 +23,4 @@ export class ReposResolver { }; }); } - @Mutation(() => Boolean) - async checkout(@Args('checkoutInput') dto: CheckoutInput): Promise { - const project = await this.projectService.findOne(dto.projectId); - await this.service.checkoutCommit(project, dto.commitNumber); - return true; - } }