45 lines
1.5 KiB
TypeScript
45 lines
1.5 KiB
TypeScript
import { Roles, AccountRole } from '@nestjs-lib/auth';
|
|
import { Query } from '@nestjs/graphql';
|
|
import {
|
|
Args,
|
|
Parent,
|
|
ResolveField,
|
|
Resolver,
|
|
Subscription,
|
|
} from '@nestjs/graphql';
|
|
import { PipelineTasksService } from '../pipeline-tasks/pipeline-tasks.service';
|
|
import { Commit, LogFields } from '../repos/dtos/log-list.model';
|
|
import { PipelinesService } from './pipelines.service';
|
|
|
|
@Roles(AccountRole.admin, AccountRole.super)
|
|
@Resolver(() => Commit)
|
|
export class CommitLogsResolver {
|
|
constructor(
|
|
private readonly service: PipelinesService,
|
|
private readonly taskServices: PipelineTasksService,
|
|
) {}
|
|
@Subscription(() => String, { resolve: (val) => val, nullable: true })
|
|
async syncCommits(
|
|
@Args('pipelineId', { type: () => String })
|
|
pipelineId: string,
|
|
@Args('appInstance', { type: () => String, nullable: true })
|
|
appInstance?: string,
|
|
) {
|
|
const pipeline = await this.service.findOneWithProject(pipelineId);
|
|
const syncCommitsPromise = this.service.syncCommits(pipeline, appInstance);
|
|
return (async function* () {
|
|
yield await syncCommitsPromise;
|
|
})();
|
|
}
|
|
@ResolveField()
|
|
async tasks(@Parent() commit: LogFields) {
|
|
return await this.taskServices.listTasksByCommitHash(commit.hash);
|
|
}
|
|
|
|
@Query(() => [Commit], { nullable: true })
|
|
async commits(@Args('pipelineId', { type: () => String }) id: string) {
|
|
const pipeline = await this.service.findOneWithProject(id);
|
|
return await this.service.listCommits(pipeline);
|
|
}
|
|
}
|