Compare commits
2 Commits
8901c49bb3
...
0dadc09ec5
Author | SHA1 | Date | |
---|---|---|---|
|
0dadc09ec5 | ||
|
38d3cb0db8 |
@ -9,5 +9,10 @@ db:
|
||||
database: fennec
|
||||
username: fennec
|
||||
password:
|
||||
redis:
|
||||
host: 192.168.31.194
|
||||
port: 6379
|
||||
password:
|
||||
prefix: fennec
|
||||
workspaces:
|
||||
root: '/Users/ivanli/Projects/fennec/workspaces'
|
@ -10,6 +10,7 @@ import { ReposModule } from './repos/repos.module';
|
||||
import { PipelinesModule } from './pipelines/pipelines.module';
|
||||
import { PipelineTasksModule } from './pipeline-tasks/pipeline-tasks.module';
|
||||
import configuration from './commons/config/configuration';
|
||||
import { RedisModule } from 'nestjs-redis';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
@ -43,6 +44,16 @@ import configuration from './commons/config/configuration';
|
||||
ReposModule,
|
||||
PipelinesModule,
|
||||
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],
|
||||
providers: [AppService, AppResolver],
|
||||
|
@ -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[];
|
||||
}
|
||||
|
@ -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: '流水线单元',
|
||||
});
|
||||
|
@ -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[];
|
||||
|
@ -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[];
|
||||
}
|
||||
|
@ -5,9 +5,25 @@ import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { PipelineTask } from './pipeline-task.entity';
|
||||
import { Pipeline } from '../pipelines/pipeline.entity';
|
||||
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({
|
||||
imports: [TypeOrmModule.forFeature([PipelineTask, Pipeline]), ReposModule],
|
||||
imports: [
|
||||
TypeOrmModule.forFeature([PipelineTask, Pipeline]),
|
||||
BullModule.registerQueue(
|
||||
{
|
||||
name: PIPELINE_TASK_QUEUE,
|
||||
},
|
||||
{ name: PIPELINE_TASK_LOG_QUEUE },
|
||||
),
|
||||
RedisModule,
|
||||
ReposModule,
|
||||
],
|
||||
providers: [PipelineTasksService, PipelineTasksResolver],
|
||||
})
|
||||
export class PipelineTasksModule {}
|
||||
|
@ -17,9 +17,9 @@ export class PipelineTasksService {
|
||||
private readonly repository: Repository<PipelineTask>,
|
||||
@InjectRepository(Pipeline)
|
||||
private readonly pipelineRepository: Repository<Pipeline>,
|
||||
private readonly redis: RedisService,
|
||||
@InjectQueue(PIPELINE_TASK_QUEUE)
|
||||
private readonly queue: Queue<PipelineTask>,
|
||||
private readonly redis: RedisService,
|
||||
) {}
|
||||
async addTask(dto: CreatePipelineTaskInput) {
|
||||
const pipeline = await this.pipelineRepository.findOneOrFail({
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -4,7 +4,7 @@ import { IsOptional, IsString, IsUUID } from 'class-validator';
|
||||
@InputType()
|
||||
export class CheckoutInput {
|
||||
@IsUUID()
|
||||
projectId: string;
|
||||
pipelineId: string;
|
||||
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
|
@ -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<true> {
|
||||
const project = await this.projectService.findOne(dto.projectId);
|
||||
await this.service.checkoutCommit(project, dto.commitNumber);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user