Compare commits

..

No commits in common. "0dadc09ec552ab2375fbb7e861475c2ad6a0d23c" and "8901c49bb3354b80a00ff93ba567ae3043691395" have entirely different histories.

12 changed files with 22 additions and 62 deletions

View File

@ -9,10 +9,5 @@ db:
database: fennec database: fennec
username: fennec username: fennec
password: password:
redis:
host: 192.168.31.194
port: 6379
password:
prefix: fennec
workspaces: workspaces:
root: '/Users/ivanli/Projects/fennec/workspaces' root: '/Users/ivanli/Projects/fennec/workspaces'

View File

@ -10,7 +10,6 @@ import { ReposModule } from './repos/repos.module';
import { PipelinesModule } from './pipelines/pipelines.module'; import { PipelinesModule } from './pipelines/pipelines.module';
import { PipelineTasksModule } from './pipeline-tasks/pipeline-tasks.module'; import { PipelineTasksModule } from './pipeline-tasks/pipeline-tasks.module';
import configuration from './commons/config/configuration'; import configuration from './commons/config/configuration';
import { RedisModule } from 'nestjs-redis';
@Module({ @Module({
imports: [ imports: [
@ -44,16 +43,6 @@ import { RedisModule } from 'nestjs-redis';
ReposModule, ReposModule,
PipelinesModule, PipelinesModule,
PipelineTasksModule, PipelineTasksModule,
RedisModule.forRootAsync({
imports: [ConfigModule],
useFactory: (configService: ConfigService) => ({
host: configService.get<string>('db.redis.host', 'localhost'),
port: configService.get<number>('db.redis.port', 6379),
password: configService.get<string>('db.redis.password', ''),
keyPrefix: configService.get<string>('db.redis.prefix', 'fennec'),
}),
inject: [ConfigService],
}),
], ],
controllers: [AppController], controllers: [AppController],
providers: [AppService, AppResolver], providers: [AppService, AppResolver],

View File

@ -1,4 +1,4 @@
import { Field, InputType } from '@nestjs/graphql'; import { InputType } from '@nestjs/graphql';
import { PipelineUnits } from '../enums/pipeline-units.enum'; import { PipelineUnits } from '../enums/pipeline-units.enum';
@InputType() @InputType()
@ -7,6 +7,5 @@ export class CreatePipelineTaskInput {
commit: string; commit: string;
@Field(() => PipelineUnits)
units: PipelineUnits[]; units: PipelineUnits[];
} }

View File

@ -1,5 +1,3 @@
import { registerEnumType } from '@nestjs/graphql';
export enum PipelineUnits { export enum PipelineUnits {
checkout = 'checkout', checkout = 'checkout',
installDependencies = 'installDependencies', installDependencies = 'installDependencies',
@ -7,8 +5,3 @@ export enum PipelineUnits {
deploy = 'deploy', deploy = 'deploy',
cleanUp = 'cleanUp', cleanUp = 'cleanUp',
} }
registerEnumType(PipelineUnits, {
name: 'PipelineUnits',
description: '流水线单元',
});

View File

@ -1,8 +1,5 @@
import { InputType, ObjectType } from '@nestjs/graphql';
import { WorkUnit } from './work-unit.model'; import { WorkUnit } from './work-unit.model';
@InputType('WorkUnitMetadataInput')
@ObjectType()
export class WorkUnitMetadata { export class WorkUnitMetadata {
version = 1; version = 1;
units: WorkUnit[]; units: WorkUnit[];

View File

@ -1,13 +1,6 @@
import { Field, InputType, ObjectType } from '@nestjs/graphql'; import { PipelineUnits as PipelineUnitTypes } from '../enums/pipeline-units.enum';
import {
PipelineUnits,
PipelineUnits as PipelineUnitTypes,
} from '../enums/pipeline-units.enum';
@ObjectType()
@InputType('WorkUnitInput')
export class WorkUnit { export class WorkUnit {
@Field(() => PipelineUnits)
type: PipelineUnitTypes; type: PipelineUnitTypes;
scripts: string[]; scripts: string[];
} }

View File

@ -5,25 +5,9 @@ import { TypeOrmModule } from '@nestjs/typeorm';
import { PipelineTask } from './pipeline-task.entity'; import { PipelineTask } from './pipeline-task.entity';
import { Pipeline } from '../pipelines/pipeline.entity'; import { Pipeline } from '../pipelines/pipeline.entity';
import { ReposModule } from '../repos/repos.module'; import { ReposModule } from '../repos/repos.module';
import { RedisModule } from 'nestjs-redis';
import { BullModule } from '@nestjs/bull';
import {
PIPELINE_TASK_QUEUE,
PIPELINE_TASK_LOG_QUEUE,
} from './pipeline-tasks.constants';
@Module({ @Module({
imports: [ imports: [TypeOrmModule.forFeature([PipelineTask, Pipeline]), ReposModule],
TypeOrmModule.forFeature([PipelineTask, Pipeline]),
BullModule.registerQueue(
{
name: PIPELINE_TASK_QUEUE,
},
{ name: PIPELINE_TASK_LOG_QUEUE },
),
RedisModule,
ReposModule,
],
providers: [PipelineTasksService, PipelineTasksResolver], providers: [PipelineTasksService, PipelineTasksResolver],
}) })
export class PipelineTasksModule {} export class PipelineTasksModule {}

View File

@ -17,9 +17,9 @@ export class PipelineTasksService {
private readonly repository: Repository<PipelineTask>, private readonly repository: Repository<PipelineTask>,
@InjectRepository(Pipeline) @InjectRepository(Pipeline)
private readonly pipelineRepository: Repository<Pipeline>, private readonly pipelineRepository: Repository<Pipeline>,
private readonly redis: RedisService,
@InjectQueue(PIPELINE_TASK_QUEUE) @InjectQueue(PIPELINE_TASK_QUEUE)
private readonly queue: Queue<PipelineTask>, private readonly queue: Queue<PipelineTask>,
private readonly redis: RedisService,
) {} ) {}
async addTask(dto: CreatePipelineTaskInput) { async addTask(dto: CreatePipelineTaskInput) {
const pipeline = await this.pipelineRepository.findOneOrFail({ const pipeline = await this.pipelineRepository.findOneOrFail({

View File

@ -1,7 +1,6 @@
import { InputType } from '@nestjs/graphql'; import { InputType } from '@nestjs/graphql';
import { WorkUnitMetadata } from '../../pipeline-tasks/models/work-unit-metadata.model';
import { import {
IsInstance, IsObject,
IsOptional, IsOptional,
IsString, IsString,
IsUUID, IsUUID,
@ -22,6 +21,6 @@ export class CreatePipelineInput {
name: string; name: string;
@IsOptional() @IsOptional()
@IsInstance(WorkUnitMetadata) @IsObject()
workUnitMetadata: WorkUnitMetadata; workUnitMetadata = {};
} }

View File

@ -9,7 +9,7 @@ import { ListPipelineArgs } from './dtos/list-pipelines.args';
export class PipelinesResolver { export class PipelinesResolver {
constructor(private readonly service: PipelinesService) {} constructor(private readonly service: PipelinesService) {}
@Query(() => [Pipeline]) @Query(() => [Pipeline])
async findPipelines(@Args() dto: ListPipelineArgs) { async findPipelines(@Args('listPipelineArgs') dto: ListPipelineArgs) {
return await this.service.list(dto); return await this.service.list(dto);
} }

View File

@ -4,7 +4,7 @@ import { IsOptional, IsString, IsUUID } from 'class-validator';
@InputType() @InputType()
export class CheckoutInput { export class CheckoutInput {
@IsUUID() @IsUUID()
pipelineId: string; projectId: string;
@IsString() @IsString()
@IsOptional() @IsOptional()

View File

@ -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 { ListLogsArgs } from './dtos/list-logs.args';
import { ReposService } from './repos.service'; import { ReposService } from './repos.service';
import { LogList } from './dtos/log-list.model'; import { LogList } from './dtos/log-list.model';
import { ListBranchesArgs } from './dtos/list-branches.args'; import { ListBranchesArgs } from './dtos/list-branches.args';
import { BranchList } from './dtos/branch-list.model'; import { BranchList } from './dtos/branch-list.model';
import { CheckoutInput } from './dtos/checkout.input';
import { ProjectsService } from '../projects/projects.service';
@Resolver() @Resolver()
export class ReposResolver { export class ReposResolver {
constructor(private readonly service: ReposService) {} constructor(
private readonly service: ReposService,
private readonly projectService: ProjectsService,
) {}
@Query(() => LogList) @Query(() => LogList)
async listLogs(@Args('listLogsArgs') dto: ListLogsArgs) { async listLogs(@Args('listLogsArgs') dto: ListLogsArgs) {
return await this.service.listLogs(dto); return await this.service.listLogs(dto);
@ -23,4 +28,10 @@ export class ReposResolver {
}; };
}); });
} }
@Mutation(() => Boolean)
async checkout(@Args('checkoutInput') dto: CheckoutInput): Promise<true> {
const project = await this.projectService.findOne(dto.projectId);
await this.service.checkoutCommit(project, dto.commitNumber);
return true;
}
} }