Compare commits
11 Commits
34cfc71a18
...
feat-confi
Author | SHA1 | Date | |
---|---|---|---|
f47a20f942 | |||
6b9f846154 | |||
3ba8fc9759 | |||
d5f49531e9 | |||
38dd05c4be | |||
8467a42b3b | |||
a299958fcb | |||
f07e18f71d | |||
eb7adc0ef2 | |||
122dca689d | |||
fcca1508eb |
4
.gitignore
vendored
4
.gitignore
vendored
@@ -33,4 +33,6 @@ lerna-debug.log*
|
||||
!.vscode/launch.json
|
||||
!.vscode/extensions.json
|
||||
|
||||
/config.yml
|
||||
/config.yml
|
||||
tsconfig.build.tsbuildinfo
|
||||
.eslintcache
|
||||
|
1
.husky/.gitignore
vendored
Normal file
1
.husky/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
_
|
5
.husky/pre-commit
Executable file
5
.husky/pre-commit
Executable file
@@ -0,0 +1,5 @@
|
||||
#!/bin/sh
|
||||
. "$(dirname "$0")/_/husky.sh"
|
||||
|
||||
npx lint-staged
|
||||
npm test
|
7445
package-lock.json
generated
7445
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -18,7 +18,8 @@
|
||||
"test:watch": "jest --watch",
|
||||
"test:cov": "jest --coverage",
|
||||
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
|
||||
"test:e2e": "jest --config ./test/jest-e2e.json"
|
||||
"test:e2e": "jest --config ./test/jest-e2e.json",
|
||||
"prepare": "husky install"
|
||||
},
|
||||
"dependencies": {
|
||||
"@golevelup/nestjs-rabbitmq": "^1.16.1",
|
||||
@@ -36,6 +37,7 @@
|
||||
"body-parser": "^1.19.0",
|
||||
"class-transformer": "^0.3.2",
|
||||
"class-validator": "^0.13.1",
|
||||
"configuration": "file:../configuration",
|
||||
"debug": "^4.3.1",
|
||||
"graphql": "^15.5.0",
|
||||
"graphql-tools": "^8.1.0",
|
||||
@@ -74,7 +76,9 @@
|
||||
"eslint": "^7.12.1",
|
||||
"eslint-config-prettier": "7.2.0",
|
||||
"eslint-plugin-prettier": "^3.1.4",
|
||||
"husky": "^7.0.2",
|
||||
"jest": "^26.6.3",
|
||||
"lint-staged": "^11.1.2",
|
||||
"prettier": "^2.1.2",
|
||||
"supertest": "^6.0.0",
|
||||
"ts-jest": "^26.4.3",
|
||||
@@ -102,5 +106,8 @@
|
||||
},
|
||||
"coverageDirectory": "../coverage",
|
||||
"testEnvironment": "node"
|
||||
},
|
||||
"lint-staged": {
|
||||
"{src,apps,libs,test}/**/*.ts": "eslint --cache --fix"
|
||||
}
|
||||
}
|
||||
|
@@ -20,6 +20,7 @@ import { LoggerModule } from 'nestjs-pino';
|
||||
import { EtcdModule } from 'nestjs-etcd';
|
||||
import pinoPretty from 'pino-pretty';
|
||||
import { fromPairs, map, pipe, toPairs } from 'ramda';
|
||||
import { ConfigurationsModule } from './configurations/configurations.module';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
@@ -64,7 +65,7 @@ import { fromPairs, map, pipe, toPairs } from 'ramda';
|
||||
playground: true,
|
||||
autoSchemaFile: true,
|
||||
installSubscriptionHandlers: true,
|
||||
context: ({ req, connection, ...args }) => {
|
||||
context: ({ req, connection }) => {
|
||||
return connection ? { req: connection.context } : { req };
|
||||
},
|
||||
subscriptions: {
|
||||
@@ -106,6 +107,7 @@ import { fromPairs, map, pipe, toPairs } from 'ramda';
|
||||
}),
|
||||
WebhooksModule,
|
||||
CommonsModule,
|
||||
ConfigurationsModule,
|
||||
],
|
||||
controllers: [AppController],
|
||||
providers: [AppService, AppResolver],
|
||||
|
@@ -1,8 +1,9 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { Global, Module } from '@nestjs/common';
|
||||
import { PasswordConverter } from './services/password-converter';
|
||||
import { RedisMutexModule } from './redis-mutex/redis-mutex.module';
|
||||
import { AuthModule } from '@nestjs-lib/auth';
|
||||
|
||||
@Global()
|
||||
@Module({
|
||||
imports: [RedisMutexModule, AuthModule],
|
||||
providers: [PasswordConverter],
|
||||
|
@@ -13,9 +13,9 @@ export class ApplicationException extends Error {
|
||||
this.error = message.error;
|
||||
this.message = message.message as any;
|
||||
} else if (typeof message === 'string') {
|
||||
super((message as unknown) as any);
|
||||
super(message as unknown as any);
|
||||
} else {
|
||||
super((message as unknown) as any);
|
||||
super(message as unknown as any);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -19,12 +19,16 @@ export class HttpExceptionFilter implements ExceptionFilter {
|
||||
case 'graphql': {
|
||||
const errorName = exception.message;
|
||||
const extensions: Record<string, any> = {};
|
||||
const err = exception.getResponse();
|
||||
const err = exception.getResponse() as any;
|
||||
if (typeof err === 'string') {
|
||||
extensions.message = err;
|
||||
} else {
|
||||
Object.assign(extensions, (err as any).extension);
|
||||
extensions.message = (err as any).message;
|
||||
Object.assign(extensions, err.extension);
|
||||
if (typeof err.message === 'string') {
|
||||
extensions.message = err.message;
|
||||
} else {
|
||||
extensions.message = err.error;
|
||||
}
|
||||
}
|
||||
extensions.error = errorName;
|
||||
this.logger.error(extensions);
|
||||
|
@@ -126,6 +126,7 @@ export class BaseDbService<Entity extends AppBaseEntity> extends TypeormHelper {
|
||||
}
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
async canYouRemoveWithIds(ids: string[]): Promise<void> {
|
||||
return;
|
||||
}
|
||||
|
11
src/configurations/configurations.module.ts
Normal file
11
src/configurations/configurations.module.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import { Configuration } from './entities/configuration.entity';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { Module } from '@nestjs/common';
|
||||
import { ConfigurationsService } from './configurations.service';
|
||||
import { ConfigurationsResolver } from './configurations.resolver';
|
||||
|
||||
@Module({
|
||||
imports: [TypeOrmModule.forFeature([Configuration])],
|
||||
providers: [ConfigurationsResolver, ConfigurationsService],
|
||||
})
|
||||
export class ConfigurationsModule {}
|
30
src/configurations/configurations.resolver.spec.ts
Normal file
30
src/configurations/configurations.resolver.spec.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import { JwtService } from '@nestjs-lib/auth';
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { ConfigurationsResolver } from './configurations.resolver';
|
||||
import { ConfigurationsService } from './configurations.service';
|
||||
|
||||
describe('ConfigurationsResolver', () => {
|
||||
let resolver: ConfigurationsResolver;
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
providers: [
|
||||
ConfigurationsResolver,
|
||||
{
|
||||
provide: ConfigurationsService,
|
||||
useValue: {},
|
||||
},
|
||||
{
|
||||
provide: JwtService,
|
||||
useValue: {},
|
||||
},
|
||||
],
|
||||
}).compile();
|
||||
|
||||
resolver = module.get<ConfigurationsResolver>(ConfigurationsResolver);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(resolver).toBeDefined();
|
||||
});
|
||||
});
|
39
src/configurations/configurations.resolver.ts
Normal file
39
src/configurations/configurations.resolver.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
import { UnprocessableEntityException } from '@nestjs/common';
|
||||
import { GetConfigurationArgs } from './dto/get-configuration.args';
|
||||
import { SetConfigurationInput } from './dto/set-configuration.input';
|
||||
import { Resolver, Mutation, Args, Query } from '@nestjs/graphql';
|
||||
import { ConfigurationsService } from './configurations.service';
|
||||
import { Configuration } from './entities/configuration.entity';
|
||||
import { any, pipe, values } from 'ramda';
|
||||
import { AccountRole, Roles } from '@nestjs-lib/auth';
|
||||
|
||||
@Roles(AccountRole.admin, AccountRole.super)
|
||||
@Resolver(() => Configuration)
|
||||
export class ConfigurationsResolver {
|
||||
constructor(private readonly configurationsService: ConfigurationsService) {}
|
||||
|
||||
@Mutation(() => Configuration)
|
||||
setConfiguration(
|
||||
@Args('setConfigurationInput', { type: () => SetConfigurationInput })
|
||||
setConfigurationInput: SetConfigurationInput,
|
||||
) {
|
||||
return this.configurationsService.setConfiguration(setConfigurationInput);
|
||||
}
|
||||
|
||||
@Query(() => Configuration, { nullable: true })
|
||||
getConfiguration(
|
||||
@Args()
|
||||
getConfigurationArgs: GetConfigurationArgs,
|
||||
) {
|
||||
if (
|
||||
pipe(
|
||||
values,
|
||||
any((value) => !value),
|
||||
)(getConfigurationArgs)
|
||||
) {
|
||||
throw new UnprocessableEntityException('Must pass a parameter');
|
||||
}
|
||||
|
||||
return this.configurationsService.findOneByConditions(getConfigurationArgs);
|
||||
}
|
||||
}
|
49
src/configurations/configurations.service.spec.ts
Normal file
49
src/configurations/configurations.service.spec.ts
Normal file
@@ -0,0 +1,49 @@
|
||||
import { getRepositoryToken } from '@nestjs/typeorm';
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { ConfigurationsService } from './configurations.service';
|
||||
import { Configuration } from './entities/configuration.entity';
|
||||
import { IsNull } from 'typeorm';
|
||||
import { Etcd3 } from 'etcd3';
|
||||
|
||||
describe('ConfigurationsService', () => {
|
||||
let service: ConfigurationsService;
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
providers: [
|
||||
ConfigurationsService,
|
||||
{
|
||||
provide: getRepositoryToken(Configuration),
|
||||
useValue: {},
|
||||
},
|
||||
{
|
||||
provide: Etcd3,
|
||||
useValue: {},
|
||||
},
|
||||
],
|
||||
}).compile();
|
||||
|
||||
service = module.get<ConfigurationsService>(ConfigurationsService);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(service).toBeDefined();
|
||||
});
|
||||
|
||||
describe('findOneByConditions', () => {
|
||||
it('should select by projectId only', async () => {
|
||||
const entity = new Configuration();
|
||||
const findOne = jest.fn<any, [any]>(() => Promise.resolve(entity));
|
||||
service['repository'].findOne = findOne;
|
||||
|
||||
await expect(
|
||||
service.findOneByConditions({ projectId: 'uuid' }),
|
||||
).resolves.toEqual(entity);
|
||||
|
||||
expect(findOne.mock.calls[0][0]).toMatchObject({
|
||||
projectId: 'uuid',
|
||||
pipelineId: IsNull(),
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
55
src/configurations/configurations.service.ts
Normal file
55
src/configurations/configurations.service.ts
Normal file
@@ -0,0 +1,55 @@
|
||||
import { GetConfigurationArgs } from './dto/get-configuration.args';
|
||||
import { BaseDbService } from './../commons/services/base-db.service';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { Configuration } from './entities/configuration.entity';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { FindConditions, IsNull, Repository } from 'typeorm';
|
||||
import { SetConfigurationInput } from './dto/set-configuration.input';
|
||||
import { pick } from 'ramda';
|
||||
import { Etcd3 } from 'etcd3';
|
||||
|
||||
@Injectable()
|
||||
export class ConfigurationsService extends BaseDbService<Configuration> {
|
||||
constructor(
|
||||
@InjectRepository(Configuration)
|
||||
configurationRepository: Repository<Configuration>,
|
||||
private readonly etcd: Etcd3,
|
||||
) {
|
||||
super(configurationRepository);
|
||||
}
|
||||
|
||||
async setConfiguration(dto: SetConfigurationInput) {
|
||||
let entity = await this.repository.findOne(
|
||||
pick(['pipelineId', 'projectId'], dto),
|
||||
);
|
||||
if (!entity) {
|
||||
entity = this.repository.create(dto);
|
||||
}
|
||||
entity = await this.repository.save(entity);
|
||||
await this.syncToEtcd(entity);
|
||||
return entity;
|
||||
}
|
||||
|
||||
async findOneByConditions(dto: FindConditions<GetConfigurationArgs>) {
|
||||
if (dto.projectId && !dto.pipelineId) {
|
||||
dto.pipelineId = IsNull();
|
||||
}
|
||||
return await this.repository.findOne(dto);
|
||||
}
|
||||
|
||||
async syncToEtcd({ pipelineId, id }: { pipelineId?: string; id?: string }) {
|
||||
const config = await this.repository.findOneOrFail({
|
||||
where: { pipelineId, id },
|
||||
relations: ['pipeline', 'project'],
|
||||
});
|
||||
|
||||
await this.etcd
|
||||
.put(`share/config/${config.id}`)
|
||||
.value(config.content)
|
||||
.exec();
|
||||
await this.etcd
|
||||
.put(`share/config/${config.pipeline.environment}/${config.project.name}`)
|
||||
.value(config.content)
|
||||
.exec();
|
||||
}
|
||||
}
|
17
src/configurations/dto/get-configuration.args.ts
Normal file
17
src/configurations/dto/get-configuration.args.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
import { ArgsType } from '@nestjs/graphql';
|
||||
import { IsUUID, IsOptional } from 'class-validator';
|
||||
|
||||
@ArgsType()
|
||||
export class GetConfigurationArgs {
|
||||
@IsUUID()
|
||||
@IsOptional()
|
||||
pipelineId?: string;
|
||||
|
||||
@IsUUID()
|
||||
@IsOptional()
|
||||
projectId?: string;
|
||||
|
||||
@IsUUID()
|
||||
@IsOptional()
|
||||
id?: string;
|
||||
}
|
26
src/configurations/dto/set-configuration.input.ts
Normal file
26
src/configurations/dto/set-configuration.input.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import { ConfigurationLanguage } from './../enums/configuration-language.enum';
|
||||
import { IsEnum, IsString, IsUUID, Length, IsOptional } from 'class-validator';
|
||||
import { InputType } from '@nestjs/graphql';
|
||||
|
||||
@InputType()
|
||||
export class SetConfigurationInput {
|
||||
@IsOptional()
|
||||
@IsUUID()
|
||||
id?: string;
|
||||
|
||||
@IsUUID()
|
||||
pipelineId: string;
|
||||
|
||||
@IsUUID()
|
||||
projectId: string;
|
||||
|
||||
@IsString()
|
||||
content: string;
|
||||
|
||||
@IsEnum(ConfigurationLanguage)
|
||||
language: ConfigurationLanguage;
|
||||
|
||||
@Length(0, 100)
|
||||
@IsOptional()
|
||||
name = 'Default Configuration';
|
||||
}
|
35
src/configurations/entities/configuration.entity.ts
Normal file
35
src/configurations/entities/configuration.entity.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import { Project } from './../../projects/project.entity';
|
||||
import { ConfigurationLanguage } from './../enums/configuration-language.enum';
|
||||
import { Pipeline } from './../../pipelines/pipeline.entity';
|
||||
import { AppBaseEntity } from './../../commons/entities/app-base-entity';
|
||||
import { ObjectType } from '@nestjs/graphql';
|
||||
import { Column, Entity, ManyToOne } from 'typeorm';
|
||||
|
||||
@Entity()
|
||||
@ObjectType()
|
||||
export class Configuration extends AppBaseEntity {
|
||||
@ManyToOne(() => Pipeline)
|
||||
pipeline: Pipeline;
|
||||
|
||||
@Column({ unique: true, nullable: true })
|
||||
pipelineId: string;
|
||||
|
||||
@ManyToOne(() => Project)
|
||||
project: Project;
|
||||
|
||||
@Column()
|
||||
projectId: string;
|
||||
|
||||
@Column({ comment: 'language defined in type field.' })
|
||||
content: string;
|
||||
|
||||
@Column({ comment: '配置名称' })
|
||||
name: string;
|
||||
|
||||
@Column({
|
||||
type: 'enum',
|
||||
enum: ConfigurationLanguage,
|
||||
comment: 'configuration content language',
|
||||
})
|
||||
language: ConfigurationLanguage;
|
||||
}
|
10
src/configurations/enums/configuration-language.enum.ts
Normal file
10
src/configurations/enums/configuration-language.enum.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
import { registerEnumType } from '@nestjs/graphql';
|
||||
|
||||
export enum ConfigurationLanguage {
|
||||
JavaScript = 'JavaScript',
|
||||
YAML = 'YAML',
|
||||
}
|
||||
|
||||
registerEnumType(ConfigurationLanguage, {
|
||||
name: 'ConfigurationLanguage',
|
||||
});
|
@@ -5,6 +5,7 @@ import { NestFactory } from '@nestjs/core';
|
||||
import { AppModule } from './app.module';
|
||||
import { HttpExceptionFilter } from './commons/filters/all.exception-filter';
|
||||
import { SanitizePipe } from './commons/pipes/sanitize.pipe';
|
||||
import { ServiceRegister } from 'configuration';
|
||||
|
||||
async function bootstrap() {
|
||||
const app = await NestFactory.create(AppModule, { bodyParser: false });
|
||||
@@ -17,6 +18,10 @@ async function bootstrap() {
|
||||
);
|
||||
const httpExceptionFilterLogger = await app.resolve(PinoLogger);
|
||||
app.useGlobalFilters(new HttpExceptionFilter(httpExceptionFilterLogger));
|
||||
await app.listen(configService.get<number>('http.port'));
|
||||
const server = await app.listen(configService.get<number>('http.port', 0));
|
||||
const port = server.address().port;
|
||||
const register = new ServiceRegister({ etcd: { hosts: 'http://rpi:2379' } });
|
||||
register.register('fennec/api', `http://localhost:${port}`);
|
||||
register.register('api.fennec', `http://localhost:${port}`);
|
||||
}
|
||||
bootstrap();
|
||||
|
@@ -1,4 +1,4 @@
|
||||
import { Field, InputType } from '@nestjs/graphql';
|
||||
import { InputType } from '@nestjs/graphql';
|
||||
import { PipelineUnits } from '../enums/pipeline-units.enum';
|
||||
|
||||
@InputType()
|
||||
|
@@ -1,6 +1,6 @@
|
||||
import { Field, InputType, Int, ObjectType } from '@nestjs/graphql';
|
||||
import { Type } from 'class-transformer';
|
||||
import { IsInstance, isInstance, ValidateNested } from 'class-validator';
|
||||
import { IsInstance, ValidateNested } from 'class-validator';
|
||||
import { WorkUnit } from './work-unit.model';
|
||||
|
||||
@InputType('WorkUnitMetadataInput')
|
||||
|
@@ -16,12 +16,10 @@ import {
|
||||
} from './pipeline-tasks.constants';
|
||||
import { PipelineTaskLogger } from './pipeline-task.logger';
|
||||
import { PipelineTaskFlushService } from './pipeline-task-flush.service';
|
||||
import { CommonsModule } from '../commons/commons.module';
|
||||
import { DeployByPm2Service } from './runners/deploy-by-pm2/deploy-by-pm2.service';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
CommonsModule,
|
||||
TypeOrmModule.forFeature([PipelineTask, Pipeline]),
|
||||
RedisModule,
|
||||
ReposModule,
|
||||
|
@@ -35,15 +35,6 @@ export class PipelineTasksResolver {
|
||||
);
|
||||
}
|
||||
|
||||
@Subscription(() => PipelineTask, {
|
||||
resolve: (value) => {
|
||||
return value;
|
||||
},
|
||||
})
|
||||
async pipelineTaskChanged(@Args('id') id: string) {
|
||||
// return await this.service.watchTaskUpdated(id);
|
||||
}
|
||||
|
||||
@Query(() => [PipelineTask])
|
||||
async listPipelineTaskByPipelineId(@Args('pipelineId') pipelineId: string) {
|
||||
return await this.service.listTasksByPipelineId(pipelineId);
|
||||
|
@@ -12,7 +12,6 @@ describe('PipelineTasksService', () => {
|
||||
let service: PipelineTasksService;
|
||||
let module: TestingModule;
|
||||
let taskRepository: Repository<PipelineTask>;
|
||||
let pipelineRepository: Repository<Pipeline>;
|
||||
|
||||
beforeEach(async () => {
|
||||
module = await Test.createTestingModule({
|
||||
@@ -43,7 +42,6 @@ describe('PipelineTasksService', () => {
|
||||
|
||||
service = module.get<PipelineTasksService>(PipelineTasksService);
|
||||
taskRepository = module.get(getRepositoryToken(PipelineTask));
|
||||
pipelineRepository = module.get(getRepositoryToken(Pipeline));
|
||||
jest
|
||||
.spyOn(taskRepository, 'save')
|
||||
.mockImplementation(async (data: any) => data);
|
||||
|
@@ -4,7 +4,6 @@ import { PipelineTask } from './pipeline-task.entity';
|
||||
import { Repository } from 'typeorm';
|
||||
import { CreatePipelineTaskInput } from './dtos/create-pipeline-task.input';
|
||||
import { Pipeline } from '../pipelines/pipeline.entity';
|
||||
import debug from 'debug';
|
||||
import { AmqpConnection, RabbitRPC } from '@golevelup/nestjs-rabbitmq';
|
||||
import {
|
||||
EXCHANGE_PIPELINE_TASK_TOPIC,
|
||||
@@ -19,8 +18,6 @@ import { InjectPinoLogger, PinoLogger } from 'nestjs-pino';
|
||||
import { getAppInstanceRouteKey } from '../commons/utils/rabbit-mq';
|
||||
import { ROUTE_PIPELINE_TASK_KILL } from './pipeline-tasks.constants';
|
||||
|
||||
const log = debug('fennec:pipeline-tasks:service');
|
||||
|
||||
@Injectable()
|
||||
export class PipelineTasksService {
|
||||
constructor(
|
||||
|
@@ -28,4 +28,8 @@ export class CreatePipelineInput {
|
||||
@ValidateNested()
|
||||
@IsInstance(WorkUnitMetadata)
|
||||
workUnitMetadata: WorkUnitMetadata;
|
||||
|
||||
@IsString()
|
||||
@MaxLength(100)
|
||||
environment: string;
|
||||
}
|
||||
|
@@ -12,7 +12,7 @@ export class Pipeline extends AppBaseEntity {
|
||||
@Column()
|
||||
projectId: string;
|
||||
|
||||
@Column({ comment: 'eg: remotes/origin/master' })
|
||||
@Column({ comment: 'E.g., remotes/origin/master' })
|
||||
branch: string;
|
||||
|
||||
@Column()
|
||||
@@ -20,4 +20,7 @@ export class Pipeline extends AppBaseEntity {
|
||||
|
||||
@Column({ type: 'jsonb' })
|
||||
workUnitMetadata: WorkUnitMetadata;
|
||||
|
||||
@Column()
|
||||
environment: string;
|
||||
}
|
||||
|
@@ -5,14 +5,11 @@ import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { Pipeline } from './pipeline.entity';
|
||||
import { CommitLogsResolver } from './commit-logs.resolver';
|
||||
import { PipelineTasksModule } from '../pipeline-tasks/pipeline-tasks.module';
|
||||
import { ReposModule } from '../repos/repos.module';
|
||||
import { RabbitMQModule } from '@golevelup/nestjs-rabbitmq';
|
||||
import { ConfigModule, ConfigService } from '@nestjs/config';
|
||||
import { CommonsModule } from '../commons/commons.module';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
CommonsModule,
|
||||
TypeOrmModule.forFeature([Pipeline]),
|
||||
PipelineTasksModule,
|
||||
RabbitMQModule.forRootAsync(RabbitMQModule, {
|
||||
|
@@ -2,13 +2,11 @@ import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { PipelinesService } from './pipelines.service';
|
||||
import { Pipeline } from './pipeline.entity';
|
||||
import { getRepositoryToken } from '@nestjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
import { Project } from '../projects/project.entity';
|
||||
import { AmqpConnection } from '@golevelup/nestjs-rabbitmq';
|
||||
|
||||
describe('PipelinesService', () => {
|
||||
let service: PipelinesService;
|
||||
let repository: Repository<Pipeline>;
|
||||
let pipeline: Pipeline;
|
||||
|
||||
beforeEach(async () => {
|
||||
@@ -40,7 +38,6 @@ describe('PipelinesService', () => {
|
||||
}).compile();
|
||||
|
||||
service = module.get<PipelinesService>(PipelinesService);
|
||||
repository = module.get(getRepositoryToken(Pipeline));
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
|
@@ -19,7 +19,9 @@ import { plainToClass } from 'class-transformer';
|
||||
|
||||
@Injectable()
|
||||
export class PipelinesService extends BaseDbService<Pipeline> {
|
||||
readonly uniqueFields: Array<Array<keyof Pipeline>> = [['projectId', 'name']];
|
||||
readonly uniqueFields: Array<Array<keyof Pipeline>> = [
|
||||
['projectId', 'name', 'environment'],
|
||||
];
|
||||
constructor(
|
||||
@InjectRepository(Pipeline)
|
||||
readonly repository: Repository<Pipeline>,
|
||||
|
@@ -1,5 +1,5 @@
|
||||
import { ObjectType } from '@nestjs/graphql';
|
||||
import { Entity, Column, DeleteDateColumn } from 'typeorm';
|
||||
import { Entity, Column } from 'typeorm';
|
||||
import { AppBaseEntity } from '../commons/entities/app-base-entity';
|
||||
|
||||
@ObjectType()
|
||||
|
@@ -6,11 +6,9 @@ import { Project } from './project.entity';
|
||||
import { RabbitMQModule } from '@golevelup/nestjs-rabbitmq';
|
||||
import { ConfigModule, ConfigService } from '@nestjs/config';
|
||||
import { EXCHANGE_PROJECT_FANOUT } from './projects.constants';
|
||||
import { CommonsModule } from '../commons/commons.module';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
CommonsModule,
|
||||
TypeOrmModule.forFeature([Project]),
|
||||
RabbitMQModule.forRootAsync(RabbitMQModule, {
|
||||
imports: [ConfigModule],
|
||||
|
@@ -1,10 +1,5 @@
|
||||
import { ObjectType, Field } from '@nestjs/graphql';
|
||||
import {
|
||||
LogResult,
|
||||
DefaultLogFields,
|
||||
BranchSummary,
|
||||
BranchSummaryBranch,
|
||||
} from 'simple-git';
|
||||
import { BranchSummaryBranch } from 'simple-git';
|
||||
|
||||
@ObjectType()
|
||||
export class Branch implements BranchSummaryBranch {
|
||||
|
@@ -7,14 +7,12 @@ import { ConfigModule, ConfigService } from '@nestjs/config';
|
||||
import { ProjectsModule } from '../projects/projects.module';
|
||||
import { EXCHANGE_REPO } from './repos.constants';
|
||||
import { RabbitMQModule } from '@golevelup/nestjs-rabbitmq';
|
||||
import { CommonsModule } from '../commons/commons.module';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
TypeOrmModule.forFeature([Project]),
|
||||
ConfigModule,
|
||||
ProjectsModule,
|
||||
CommonsModule,
|
||||
RabbitMQModule.forRootAsync(RabbitMQModule, {
|
||||
imports: [ConfigModule],
|
||||
useFactory: (configService: ConfigService) => ({
|
||||
|
@@ -161,7 +161,7 @@ describe('ReposService', () => {
|
||||
const project = new Project();
|
||||
const pipeline = new Pipeline();
|
||||
pipeline.branch = 'test';
|
||||
const fetch = jest.fn((_: any) => Promise.resolve());
|
||||
const fetch = jest.fn<any, [any]>(() => Promise.resolve());
|
||||
pipeline.project = project;
|
||||
const getGit = jest.spyOn(service, 'getGit').mockImplementation(() =>
|
||||
Promise.resolve({
|
||||
@@ -182,7 +182,7 @@ describe('ReposService', () => {
|
||||
const project = new Project();
|
||||
const pipeline = new Pipeline();
|
||||
pipeline.branch = 'test';
|
||||
const fetch = jest.fn((_: any) => Promise.resolve());
|
||||
const fetch = jest.fn<any, [any]>(() => Promise.resolve());
|
||||
pipeline.project = project;
|
||||
const getGit = jest
|
||||
.spyOn(service, 'getGit')
|
||||
@@ -196,7 +196,7 @@ describe('ReposService', () => {
|
||||
const project = new Project();
|
||||
const pipeline = new Pipeline();
|
||||
pipeline.branch = 'test';
|
||||
const fetch = jest.fn((_: any) => Promise.reject('error'));
|
||||
const fetch = jest.fn<any, [any]>(() => Promise.reject('error'));
|
||||
pipeline.project = project;
|
||||
const getGit = jest.spyOn(service, 'getGit').mockImplementation(() =>
|
||||
Promise.resolve({
|
||||
|
@@ -1,4 +1,4 @@
|
||||
import { MiddlewareConsumer, Module } from '@nestjs/common';
|
||||
import { Module } from '@nestjs/common';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { PipelineTasksModule } from '../pipeline-tasks/pipeline-tasks.module';
|
||||
import { GiteaWebhooksController } from './gitea-webhooks.controller';
|
||||
@@ -10,5 +10,4 @@ import { WebhooksService } from './webhooks.service';
|
||||
controllers: [GiteaWebhooksController],
|
||||
providers: [WebhooksService],
|
||||
})
|
||||
export class WebhooksModule {
|
||||
}
|
||||
export class WebhooksModule {}
|
||||
|
File diff suppressed because one or more lines are too long
@@ -10,8 +10,6 @@
|
||||
"lib": ["ES2021"],
|
||||
"sourceMap": true,
|
||||
"outDir": "./dist",
|
||||
"rootDir": "./src",
|
||||
"baseUrl": "./",
|
||||
"incremental": true,
|
||||
},
|
||||
}
|
||||
|
Reference in New Issue
Block a user