Skip to content

Commit 4b755c3

Browse files
suratdaspashidlos
andauthored
If branch not sent, take default branch (#163)
* If branch not sent, take default branch * Fixed review comments. Co-authored-by: Pavel Strunkin <[email protected]> * Added a test for null branch name * Made branch name optional in DTO Co-authored-by: Pavel Strunkin <[email protected]>
1 parent 9b06f5e commit 4b755c3

File tree

3 files changed

+40
-3
lines changed

3 files changed

+40
-3
lines changed

src/builds/builds.controller.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export class BuildsController {
7575
await this.buildsService.deleteOldBuilds(project.id, project.maxBuildAllowed);
7676
const build = await this.buildsService.findOrCreate({
7777
projectId: project.id,
78-
branchName: createBuildDto.branchName,
78+
branchName: createBuildDto.branchName ?? project.mainBranchName,
7979
ciBuildId: createBuildDto.ciBuildId,
8080
});
8181
return new BuildDto(build);

src/builds/dto/build-create.dto.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@ export class CreateBuildDto {
88
@IsNotEmpty()
99
readonly ciBuildId?: string;
1010

11-
@ApiProperty()
11+
@ApiPropertyOptional()
12+
@IsOptional()
1213
@IsString()
13-
readonly branchName: string;
14+
@IsNotEmpty()
15+
readonly branchName?: string;
1416

1517
@ApiProperty()
1618
@IsString()

test/builds.e2e-spec.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,41 @@ describe('Builds (e2e)', () => {
7676
});
7777
});
7878

79+
it('201 by null branchname', () => {
80+
const createBuildDto: CreateBuildDto = {
81+
branchName: null,
82+
project: project.id,
83+
};
84+
return requestWithApiKey(app, 'post', '/builds', user.apiKey)
85+
.send(createBuildDto)
86+
.expect(201)
87+
.expect((res) => {
88+
expect(res.body.projectId).toBe(project.id);
89+
expect(res.body.branchName).toBe(TEST_PROJECT.mainBranchName);
90+
expect(res.body.failedCount).toBe(0);
91+
expect(res.body.passedCount).toBe(0);
92+
expect(res.body.unresolvedCount).toBe(0);
93+
expect(res.body.isRunning).toBe(true);
94+
});
95+
});
96+
97+
it('201 with no branchname and no ciBuildId', () => {
98+
const createBuildDto: CreateBuildDto = {
99+
project: project.id,
100+
};
101+
return requestWithApiKey(app, 'post', '/builds', user.apiKey)
102+
.send(createBuildDto)
103+
.expect(201)
104+
.expect((res) => {
105+
expect(res.body.projectId).toBe(project.id);
106+
expect(res.body.branchName).toBe(TEST_PROJECT.mainBranchName);
107+
expect(res.body.failedCount).toBe(0);
108+
expect(res.body.passedCount).toBe(0);
109+
expect(res.body.unresolvedCount).toBe(0);
110+
expect(res.body.isRunning).toBe(true);
111+
});
112+
});
113+
79114
it('201 by name', () => {
80115
const createBuildDto: CreateBuildDto = {
81116
branchName: 'branchName',

0 commit comments

Comments
 (0)