From 3b261f3704a6fa2f5d0f850db43754039cde93fe Mon Sep 17 00:00:00 2001 From: Surat Das Date: Wed, 22 Dec 2021 13:31:54 -0800 Subject: [PATCH 1/4] If branch not sent, take default branch --- src/builds/builds.controller.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/builds/builds.controller.ts b/src/builds/builds.controller.ts index 2adcb511..ee2c0bb0 100644 --- a/src/builds/builds.controller.ts +++ b/src/builds/builds.controller.ts @@ -75,7 +75,7 @@ export class BuildsController { await this.buildsService.deleteOldBuilds(project.id, project.maxBuildAllowed); const build = await this.buildsService.findOrCreate({ projectId: project.id, - branchName: createBuildDto.branchName, + branchName: (createBuildDto.branchName && createBuildDto.branchName.trim().length > 0) ? createBuildDto.branchName : project.mainBranchName, ciBuildId: createBuildDto.ciBuildId, }); return new BuildDto(build); From a9b3ae26213f043c290c055734aaf9c48a88ff2f Mon Sep 17 00:00:00 2001 From: Surat Das Date: Fri, 24 Dec 2021 12:37:47 -0800 Subject: [PATCH 2/4] Fixed review comments. Co-authored-by: Pavel Strunkin --- src/builds/builds.controller.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/builds/builds.controller.ts b/src/builds/builds.controller.ts index ee2c0bb0..879f3fe8 100644 --- a/src/builds/builds.controller.ts +++ b/src/builds/builds.controller.ts @@ -75,7 +75,7 @@ export class BuildsController { await this.buildsService.deleteOldBuilds(project.id, project.maxBuildAllowed); const build = await this.buildsService.findOrCreate({ projectId: project.id, - branchName: (createBuildDto.branchName && createBuildDto.branchName.trim().length > 0) ? createBuildDto.branchName : project.mainBranchName, + branchName: createBuildDto.branchName ?? project.mainBranchName, ciBuildId: createBuildDto.ciBuildId, }); return new BuildDto(build); From d1cb099bc75e97dc4aa3bb1427b497fcdc74aeb1 Mon Sep 17 00:00:00 2001 From: Surat Das Date: Fri, 24 Dec 2021 12:39:35 -0800 Subject: [PATCH 3/4] Added a test for null branch name --- test/builds.e2e-spec.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/test/builds.e2e-spec.ts b/test/builds.e2e-spec.ts index 72744c0f..7e23e982 100644 --- a/test/builds.e2e-spec.ts +++ b/test/builds.e2e-spec.ts @@ -76,6 +76,24 @@ describe('Builds (e2e)', () => { }); }); + it('201 by null branchname', () => { + const createBuildDto: CreateBuildDto = { + branchName: null, + project: project.id, + }; + return requestWithApiKey(app, 'post', '/builds', user.apiKey) + .send(createBuildDto) + .expect(201) + .expect((res) => { + expect(res.body.projectId).toBe(project.id); + expect(res.body.branchName).toBe(TEST_PROJECT.mainBranchName); + expect(res.body.failedCount).toBe(0); + expect(res.body.passedCount).toBe(0); + expect(res.body.unresolvedCount).toBe(0); + expect(res.body.isRunning).toBe(true); + }); + }); + it('201 by name', () => { const createBuildDto: CreateBuildDto = { branchName: 'branchName', From 9cbb79822b27bb91bad6ccd4c76cdb143e687a21 Mon Sep 17 00:00:00 2001 From: Surat Das Date: Fri, 24 Dec 2021 15:39:55 -0800 Subject: [PATCH 4/4] Made branch name optional in DTO --- src/builds/dto/build-create.dto.ts | 6 ++++-- test/builds.e2e-spec.ts | 17 +++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/builds/dto/build-create.dto.ts b/src/builds/dto/build-create.dto.ts index d9b1b0d4..a46ce9a3 100644 --- a/src/builds/dto/build-create.dto.ts +++ b/src/builds/dto/build-create.dto.ts @@ -8,9 +8,11 @@ export class CreateBuildDto { @IsNotEmpty() readonly ciBuildId?: string; - @ApiProperty() + @ApiPropertyOptional() + @IsOptional() @IsString() - readonly branchName: string; + @IsNotEmpty() + readonly branchName?: string; @ApiProperty() @IsString() diff --git a/test/builds.e2e-spec.ts b/test/builds.e2e-spec.ts index 7e23e982..f489e0aa 100644 --- a/test/builds.e2e-spec.ts +++ b/test/builds.e2e-spec.ts @@ -94,6 +94,23 @@ describe('Builds (e2e)', () => { }); }); + it('201 with no branchname and no ciBuildId', () => { + const createBuildDto: CreateBuildDto = { + project: project.id, + }; + return requestWithApiKey(app, 'post', '/builds', user.apiKey) + .send(createBuildDto) + .expect(201) + .expect((res) => { + expect(res.body.projectId).toBe(project.id); + expect(res.body.branchName).toBe(TEST_PROJECT.mainBranchName); + expect(res.body.failedCount).toBe(0); + expect(res.body.passedCount).toBe(0); + expect(res.body.unresolvedCount).toBe(0); + expect(res.body.isRunning).toBe(true); + }); + }); + it('201 by name', () => { const createBuildDto: CreateBuildDto = { branchName: 'branchName',