From 32102ffefd762cb5190984960534ae6f4c0a73a5 Mon Sep 17 00:00:00 2001 From: Ivan Li Date: Sun, 28 Feb 2021 21:51:52 +0800 Subject: [PATCH] =?UTF-8?q?feat(repos):=20=E6=B7=BB=E5=8A=A0checkout?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/repos/dtos/checkout.input.ts | 16 ++++++++++++++++ src/repos/dtos/list-logs.args.ts | 2 +- src/repos/repos.module.ts | 3 ++- src/repos/repos.resolver.ts | 15 +++++++++++++-- 4 files changed, 32 insertions(+), 4 deletions(-) create mode 100644 src/repos/dtos/checkout.input.ts diff --git a/src/repos/dtos/checkout.input.ts b/src/repos/dtos/checkout.input.ts new file mode 100644 index 0000000..0694ad7 --- /dev/null +++ b/src/repos/dtos/checkout.input.ts @@ -0,0 +1,16 @@ +import { InputType } from '@nestjs/graphql'; +import { IsOptional, IsString, IsUUID } from 'class-validator'; + +@InputType() +export class CheckoutInput { + @IsUUID() + projectId: string; + + @IsString() + @IsOptional() + branch?: string; + + @IsString() + @IsOptional() + commitNumber?: string; +} diff --git a/src/repos/dtos/list-logs.args.ts b/src/repos/dtos/list-logs.args.ts index 1eed6f2..70ab5f3 100644 --- a/src/repos/dtos/list-logs.args.ts +++ b/src/repos/dtos/list-logs.args.ts @@ -1,4 +1,4 @@ -import { InputType, ObjectType } from '@nestjs/graphql'; +import { InputType } from '@nestjs/graphql'; import { IsOptional, IsString, IsUUID } from 'class-validator'; @InputType() diff --git a/src/repos/repos.module.ts b/src/repos/repos.module.ts index ae00feb..0e22a10 100644 --- a/src/repos/repos.module.ts +++ b/src/repos/repos.module.ts @@ -4,9 +4,10 @@ import { Project } from '../projects/project.entity'; import { ReposResolver } from './repos.resolver'; import { ReposService } from './repos.service'; import { ConfigModule } from '@nestjs/config'; +import { ProjectsModule } from '../projects/projects.module'; @Module({ - imports: [TypeOrmModule.forFeature([Project]), ConfigModule], + imports: [TypeOrmModule.forFeature([Project]), ConfigModule, ProjectsModule], providers: [ReposResolver, ReposService], }) export class ReposModule {} diff --git a/src/repos/repos.resolver.ts b/src/repos/repos.resolver.ts index 5da9bac..aba422c 100644 --- a/src/repos/repos.resolver.ts +++ b/src/repos/repos.resolver.ts @@ -1,13 +1,18 @@ -import { Args, Query, Resolver } from '@nestjs/graphql'; +import { Args, Mutation, 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) {} + constructor( + private readonly service: ReposService, + private readonly projectService: ProjectsService, + ) {} @Query(() => LogList) async listLogs(@Args('listLogsArgs') dto: ListLogsArgs) { return await this.service.listLogs(dto); @@ -23,4 +28,10 @@ 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; + } }