From d02cea21152d4e7e12250b5e5e327a677f9fc46a Mon Sep 17 00:00:00 2001 From: Ivan Li Date: Tue, 9 Mar 2021 22:50:26 +0800 Subject: [PATCH] =?UTF-8?q?fix(repos):=20=E5=AE=8C=E5=96=84=20commit=20log?= =?UTF-8?q?=20=E8=AE=A2=E9=98=85=E6=8E=A5=E5=8F=A3=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pipelines/pipelines.service.ts | 4 +--- src/repos/repos.module.ts | 2 ++ src/repos/repos.resolver.ts | 6 +++++- src/repos/repos.service.spec.ts | 7 +++++-- src/repos/repos.service.ts | 6 ++++-- 5 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/pipelines/pipelines.service.ts b/src/pipelines/pipelines.service.ts index 169b31d..20ef905 100644 --- a/src/pipelines/pipelines.service.ts +++ b/src/pipelines/pipelines.service.ts @@ -13,9 +13,7 @@ import { ListLogsOption } from '../repos/models/list-logs.options'; @Injectable() export class PipelinesService extends BaseDbService { - readonly uniqueFields: Array> = [ - ['branch', 'projectId'], - ]; + readonly uniqueFields: Array> = [['projectId', 'name']]; constructor( @InjectRepository(Pipeline) readonly repository: Repository, diff --git a/src/repos/repos.module.ts b/src/repos/repos.module.ts index 2b58ec7..ac411b6 100644 --- a/src/repos/repos.module.ts +++ b/src/repos/repos.module.ts @@ -8,6 +8,7 @@ import { ProjectsModule } from '../projects/projects.module'; import { BullModule } from '@nestjs/bull'; import { LIST_LOGS_TASK, LIST_LOGS_PUB_SUB } from './repos.constants'; import { PubSub } from 'graphql-subscriptions'; +import { ListLogsConsumer } from './list-logs.consumer'; @Module({ imports: [ @@ -21,6 +22,7 @@ import { PubSub } from 'graphql-subscriptions'; providers: [ ReposResolver, ReposService, + ListLogsConsumer, { provide: LIST_LOGS_PUB_SUB, useValue: new PubSub(), diff --git a/src/repos/repos.resolver.ts b/src/repos/repos.resolver.ts index b7b640f..b016d69 100644 --- a/src/repos/repos.resolver.ts +++ b/src/repos/repos.resolver.ts @@ -10,7 +10,11 @@ export class ReposResolver { @Inject(LIST_LOGS_PUB_SUB) private readonly pubSub: PubSub, ) {} - @Subscription(() => LogList) + @Subscription(() => LogList, { + resolve: (value) => { + return value; + }, + }) listLogsDone() { return this.pubSub.asyncIterator(LIST_LOGS_DONE); } diff --git a/src/repos/repos.service.spec.ts b/src/repos/repos.service.spec.ts index a9fffb3..b36a4fb 100644 --- a/src/repos/repos.service.spec.ts +++ b/src/repos/repos.service.spec.ts @@ -63,7 +63,10 @@ describe('ReposService', () => { }); describe('listLogs', () => { it('should be return logs', async () => { - const result = await service.listLogs({ projectId: '1' }); + const result = await service.listLogs({ + project: getTest1Project(), + branch: 'master', + }); expect(result).toBeDefined(); }, 20_000); }); @@ -71,7 +74,7 @@ describe('ReposService', () => { it('should be return branches', async () => { const result = await service.listBranches({ projectId: '1' }); expect(result).toBeDefined(); - }, 10_000); + }, 20_000); }); describe.skip('checkout', () => { diff --git a/src/repos/repos.service.ts b/src/repos/repos.service.ts index d90dace..8e6256b 100644 --- a/src/repos/repos.service.ts +++ b/src/repos/repos.service.ts @@ -40,7 +40,7 @@ export class ReposService { await mkdir(workspaceRoot, { recursive: true }); }); const git = gitP(workspaceRoot); - if (!(await git.checkIsRepo())) { + if (!(await git.checkIsRepo().catch(() => false))) { await git.init(); await git.addRemote(DEFAULT_REMOTE_NAME, project.sshUrl); } @@ -50,7 +50,9 @@ export class ReposService { async listLogs({ project, branch }: ListLogsOption) { const git = await this.getGit(project); - return await git.log(branch ? ['--branches', branch, '--'] : ['--all']); + return await git.log( + branch ? ['--branches', `remotes/origin/${branch}`, '--'] : ['--all'], + ); } async listBranches(dto: ListBranchesArgs) {