diff --git a/src/builds/builds.controller.ts b/src/builds/builds.controller.ts index 2adcb511..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, + branchName: createBuildDto.branchName ?? project.mainBranchName, ciBuildId: createBuildDto.ciBuildId, }); return new BuildDto(build); 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 72744c0f..f489e0aa 100644 --- a/test/builds.e2e-spec.ts +++ b/test/builds.e2e-spec.ts @@ -76,6 +76,41 @@ 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 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',