Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/builds/builds.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 4 additions & 2 deletions src/builds/dto/build-create.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ export class CreateBuildDto {
@IsNotEmpty()
readonly ciBuildId?: string;

@ApiProperty()
@ApiPropertyOptional()
@IsOptional()
@IsString()
readonly branchName: string;
@IsNotEmpty()
readonly branchName?: string;

@ApiProperty()
@IsString()
Expand Down
35 changes: 35 additions & 0 deletions test/builds.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down