Compare commits
3 Commits
22be1ffb33
...
feat-api-f
Author | SHA1 | Date | |
---|---|---|---|
|
0d71700f11 | ||
|
bd045c6abe | ||
|
8e3dea7099 |
@@ -15,7 +15,6 @@ import { WebhooksModule } from './webhooks/webhooks.module';
|
|||||||
import { RawBodyMiddleware } from './commons/middlewares/raw-body.middleware';
|
import { RawBodyMiddleware } from './commons/middlewares/raw-body.middleware';
|
||||||
import { GiteaWebhooksController } from './webhooks/gitea-webhooks.controller';
|
import { GiteaWebhooksController } from './webhooks/gitea-webhooks.controller';
|
||||||
import { ParseBodyMiddleware } from './commons/middlewares/parse-body.middleware';
|
import { ParseBodyMiddleware } from './commons/middlewares/parse-body.middleware';
|
||||||
import { BullModule } from '@nestjs/bull';
|
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [
|
imports: [
|
||||||
@@ -46,17 +45,6 @@ import { BullModule } from '@nestjs/bull';
|
|||||||
}),
|
}),
|
||||||
inject: [ConfigService],
|
inject: [ConfigService],
|
||||||
}),
|
}),
|
||||||
BullModule.forRootAsync({
|
|
||||||
imports: [ConfigModule],
|
|
||||||
useFactory: (configService: ConfigService) => ({
|
|
||||||
redis: {
|
|
||||||
host: configService.get<string>('db.redis.host', 'localhost'),
|
|
||||||
port: configService.get<number>('db.redis.port', 6379),
|
|
||||||
password: configService.get<string>('db.redis.password', ''),
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
inject: [ConfigService],
|
|
||||||
}),
|
|
||||||
ProjectsModule,
|
ProjectsModule,
|
||||||
ReposModule,
|
ReposModule,
|
||||||
PipelinesModule,
|
PipelinesModule,
|
||||||
|
@@ -69,10 +69,6 @@ export class PipelineTasksService {
|
|||||||
return await this.repository.find({ pipelineId });
|
return await this.repository.find({ pipelineId });
|
||||||
}
|
}
|
||||||
|
|
||||||
async listTasksByCommitHash(hash: string) {
|
|
||||||
return await this.repository.find({ commit: hash });
|
|
||||||
}
|
|
||||||
|
|
||||||
async doNextTask(pipeline: Pipeline) {
|
async doNextTask(pipeline: Pipeline) {
|
||||||
const [lckKey, tasksKey] = this.getRedisTokens(pipeline);
|
const [lckKey, tasksKey] = this.getRedisTokens(pipeline);
|
||||||
const redis = this.redis.getClient();
|
const redis = this.redis.getClient();
|
||||||
|
@@ -1,18 +0,0 @@
|
|||||||
import { Test, TestingModule } from '@nestjs/testing';
|
|
||||||
import { CommitLogsResolver } from './commit-logs.resolver';
|
|
||||||
|
|
||||||
describe('CommitLogsResolver', () => {
|
|
||||||
let resolver: CommitLogsResolver;
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
|
||||||
const module: TestingModule = await Test.createTestingModule({
|
|
||||||
providers: [CommitLogsResolver],
|
|
||||||
}).compile();
|
|
||||||
|
|
||||||
resolver = module.get<CommitLogsResolver>(CommitLogsResolver);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should be defined', () => {
|
|
||||||
expect(resolver).toBeDefined();
|
|
||||||
});
|
|
||||||
});
|
|
@@ -1,39 +0,0 @@
|
|||||||
import {
|
|
||||||
Args,
|
|
||||||
Info,
|
|
||||||
Parent,
|
|
||||||
ResolveField,
|
|
||||||
Resolver,
|
|
||||||
Subscription,
|
|
||||||
} from '@nestjs/graphql';
|
|
||||||
import { GraphQLResolveInfo } from 'graphql';
|
|
||||||
import { PipelineTasksService } from '../pipeline-tasks/pipeline-tasks.service';
|
|
||||||
import { LogFields, LogList } from '../repos/dtos/log-list.model';
|
|
||||||
import { PipelinesService } from './pipelines.service';
|
|
||||||
|
|
||||||
@Resolver(() => LogFields)
|
|
||||||
export class CommitLogsResolver {
|
|
||||||
constructor(
|
|
||||||
private readonly service: PipelinesService,
|
|
||||||
private readonly taskServices: PipelineTasksService,
|
|
||||||
) {}
|
|
||||||
@Subscription(() => LogList, {
|
|
||||||
resolve: (value) => {
|
|
||||||
return value;
|
|
||||||
},
|
|
||||||
})
|
|
||||||
async listLogsForPipeline(
|
|
||||||
@Args('id', { type: () => String }) id: string,
|
|
||||||
@Info() info: GraphQLResolveInfo,
|
|
||||||
) {
|
|
||||||
info.returnType.toString();
|
|
||||||
const job = await this.service.listLogsForPipeline(id);
|
|
||||||
return (async function* () {
|
|
||||||
yield await job.finished();
|
|
||||||
})();
|
|
||||||
}
|
|
||||||
@ResolveField()
|
|
||||||
async tasks(@Parent() commit: LogFields) {
|
|
||||||
return await this.taskServices.listTasksByCommitHash(commit.hash);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -5,8 +5,6 @@ import { TypeOrmModule } from '@nestjs/typeorm';
|
|||||||
import { Pipeline } from './pipeline.entity';
|
import { Pipeline } from './pipeline.entity';
|
||||||
import { BullModule } from '@nestjs/bull';
|
import { BullModule } from '@nestjs/bull';
|
||||||
import { LIST_LOGS_TASK } from '../repos/repos.constants';
|
import { LIST_LOGS_TASK } from '../repos/repos.constants';
|
||||||
import { CommitLogsResolver } from './commit-logs.resolver';
|
|
||||||
import { PipelineTasksModule } from '../pipeline-tasks/pipeline-tasks.module';
|
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [
|
imports: [
|
||||||
@@ -14,8 +12,7 @@ import { PipelineTasksModule } from '../pipeline-tasks/pipeline-tasks.module';
|
|||||||
BullModule.registerQueue({
|
BullModule.registerQueue({
|
||||||
name: LIST_LOGS_TASK,
|
name: LIST_LOGS_TASK,
|
||||||
}),
|
}),
|
||||||
PipelineTasksModule,
|
|
||||||
],
|
],
|
||||||
providers: [PipelinesResolver, PipelinesService, CommitLogsResolver],
|
providers: [PipelinesResolver, PipelinesService],
|
||||||
})
|
})
|
||||||
export class PipelinesModule {}
|
export class PipelinesModule {}
|
||||||
|
@@ -1,9 +1,10 @@
|
|||||||
import { Args, Mutation, Query, Resolver } from '@nestjs/graphql';
|
import { Args, Mutation, Query, Resolver, Subscription } from '@nestjs/graphql';
|
||||||
import { CreatePipelineInput } from './dtos/create-pipeline.input';
|
import { CreatePipelineInput } from './dtos/create-pipeline.input';
|
||||||
import { UpdatePipelineInput } from './dtos/update-pipeline.input';
|
import { UpdatePipelineInput } from './dtos/update-pipeline.input';
|
||||||
import { Pipeline } from './pipeline.entity';
|
import { Pipeline } from './pipeline.entity';
|
||||||
import { PipelinesService } from './pipelines.service';
|
import { PipelinesService } from './pipelines.service';
|
||||||
import { ListPipelineArgs } from './dtos/list-pipelines.args';
|
import { ListPipelineArgs } from './dtos/list-pipelines.args';
|
||||||
|
import { LogList } from '../repos/dtos/log-list.model';
|
||||||
|
|
||||||
@Resolver()
|
@Resolver()
|
||||||
export class PipelinesResolver {
|
export class PipelinesResolver {
|
||||||
@@ -41,4 +42,16 @@ export class PipelinesResolver {
|
|||||||
async deletePipeline(@Args('id', { type: () => String }) id: string) {
|
async deletePipeline(@Args('id', { type: () => String }) id: string) {
|
||||||
return await this.service.remove(id);
|
return await this.service.remove(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Subscription(() => LogList, {
|
||||||
|
resolve: (value) => {
|
||||||
|
return value;
|
||||||
|
},
|
||||||
|
})
|
||||||
|
async listLogsForPipeline(@Args('id', { type: () => String }) id: string) {
|
||||||
|
const job = await this.service.listLogsForPipeline(id);
|
||||||
|
return (async function* () {
|
||||||
|
yield await job.finished();
|
||||||
|
})();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,6 +1,5 @@
|
|||||||
import { ObjectType, Field } from '@nestjs/graphql';
|
import { ObjectType, Field } from '@nestjs/graphql';
|
||||||
import { LogResult, DefaultLogFields } from 'simple-git';
|
import { LogResult, DefaultLogFields } from 'simple-git';
|
||||||
import { PipelineTask } from '../../pipeline-tasks/pipeline-task.entity';
|
|
||||||
|
|
||||||
@ObjectType()
|
@ObjectType()
|
||||||
export class LogFields {
|
export class LogFields {
|
||||||
@@ -11,7 +10,6 @@ export class LogFields {
|
|||||||
body: string;
|
body: string;
|
||||||
author_name: string;
|
author_name: string;
|
||||||
author_email: string;
|
author_email: string;
|
||||||
tasks: PipelineTask[];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ObjectType()
|
@ObjectType()
|
||||||
|
@@ -4,6 +4,7 @@ import { PipelineTasksModule } from '../pipeline-tasks/pipeline-tasks.module';
|
|||||||
import { GiteaWebhooksController } from './gitea-webhooks.controller';
|
import { GiteaWebhooksController } from './gitea-webhooks.controller';
|
||||||
import { WebhookLog } from './webhook-log.entity';
|
import { WebhookLog } from './webhook-log.entity';
|
||||||
import { WebhooksService } from './webhooks.service';
|
import { WebhooksService } from './webhooks.service';
|
||||||
|
import { raw } from 'body-parser';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [TypeOrmModule.forFeature([WebhookLog]), PipelineTasksModule],
|
imports: [TypeOrmModule.forFeature([WebhookLog]), PipelineTasksModule],
|
||||||
@@ -11,4 +12,9 @@ import { WebhooksService } from './webhooks.service';
|
|||||||
providers: [WebhooksService],
|
providers: [WebhooksService],
|
||||||
})
|
})
|
||||||
export class WebhooksModule {
|
export class WebhooksModule {
|
||||||
|
// configure(consumer: MiddlewareConsumer) {
|
||||||
|
// consumer
|
||||||
|
// .apply(raw({ type: 'application/json' }))
|
||||||
|
// .forRoutes(GiteaWebhooksController);
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user