Skip to content

Commit 79009b4

Browse files
committed
fix(): show correct status of previous build run
1 parent 633b030 commit 79009b4

File tree

5 files changed

+29
-15
lines changed

5 files changed

+29
-15
lines changed

src/api/db/build.ts

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,12 @@ export function getBuilds(limit: number, offset: number): Promise<any> {
1414
builds = builds.toJSON();
1515
builds = builds.map(build => {
1616
build.jobs = build.jobs.map(job => {
17-
job.end_time = job.runs[job.runs.length - 1].end_time;
18-
job.start_time = job.runs[job.runs.length - 1].start_time;
19-
job.status = job.runs[job.runs.length - 1].status;
17+
if (job.runs.length > 0) {
18+
job.end_time = job.runs[job.runs.length - 1].end_time;
19+
job.start_time = job.runs[job.runs.length - 1].start_time;
20+
job.status = job.runs[job.runs.length - 1].status;
21+
}
22+
2023
return job;
2124
});
2225

@@ -30,7 +33,7 @@ export function getBuilds(limit: number, offset: number): Promise<any> {
3033

3134
export function getBuild(id: number): Promise<any> {
3235
return new Promise((resolve, reject) => {
33-
new Build({ id: id }).fetch({ withRelated: ['repository', 'jobs.runs', 'runs'] })
36+
new Build({ id: id }).fetch({ withRelated: ['repository', 'jobs.runs', 'runs.job_runs'] })
3437
.then(build => {
3538
if (!build) {
3639
reject();
@@ -44,6 +47,22 @@ export function getBuild(id: number): Promise<any> {
4447
return job;
4548
});
4649

50+
build.runs = build.runs.map(run => {
51+
if (run.job_runs) {
52+
if (run.job_runs.findIndex(j => j.status === 'queued') !== -1) {
53+
run.status = 'queued';
54+
} else if (run.job_runs.findIndex(j => j.status === 'running') !== -1) {
55+
run.status = 'running';
56+
} else if (run.job_runs.findIndex(j => j.status === 'failed') !== -1) {
57+
run.status = 'failed';
58+
} else if (run.job_runs.findIndex(j => j.status === 'success') !== -1) {
59+
run.status = 'success';
60+
}
61+
}
62+
63+
return run;
64+
});
65+
4766
return build;
4867
})
4968
.then(build => {
@@ -75,7 +94,7 @@ export function getLastRunId(buildId: number): Promise<any> {
7594
}
7695
const runs = build.related('runs').toJSON();
7796

78-
resolve (runs[runs.length - 1].id);
97+
resolve(runs.length > 0 ? runs[runs.length - 1].id : -1);
7998
});
8099
});
81100
}

src/api/db/job.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export function getLastRunId(jobId: number): Promise<any> {
4949
}
5050
const runs = job.related('runs').toJSON();
5151

52-
resolve (runs[runs.length - 1].id);
52+
resolve(runs.length > 0 ? runs[runs.length - 1].id : -1);
5353
});
5454
});
5555
}
@@ -97,14 +97,7 @@ export function resetJobs(buildId: number): Promise<any> {
9797
};
9898

9999
new Job().where({ builds_id: buildId }).save(data, { method: 'update', require: false })
100-
.then(jobs => {
101-
if (!jobs) {
102-
reject();
103-
} else {
104-
new Job().where({ builds_id: buildId }).fetchAll()
105-
.then(jobs => jobs ? resolve(jobs.toJSON()) : reject(jobs));
106-
}
107-
});
100+
.then(jobs => !jobs ? reject() : resolve(jobs.toJSON()));
108101
});
109102
}
110103

src/api/db/model.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export class BuildRun extends Bookshelf.Model<any> {
2424
get tableName() { return 'build_runs'; }
2525
get hasTimestamps() { return true; }
2626
build() { return this.belongsTo(Build, 'build_id'); }
27+
job_runs() { return this.hasMany(JobRun, 'build_run_id'); }
2728
}
2829

2930
export class Job extends Bookshelf.Model<any> {

src/api/process-manager.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ export function startBuild(data: any): Promise<any> {
130130
.then(build => {
131131
data.build_id = build.id;
132132
delete data.repositories_id;
133+
delete data.pr;
133134
insertBuildRun(data);
134135
const jobsCommands = generateCommands(repository.clone_url, repoDetails.config);
135136

src/app/components/app-build-details/app-build-details.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ <h1 class="bold">
140140
<hr/>
141141
<div class="columns list-item"
142142
*ngFor="let run of build.runs; let i = index;"
143-
[ngClass]="{ 'is-queued': run.status === 'queued', 'is-success': run.status === 'success', 'is-running': run.status === 'running', 'is-errored': true }">
143+
[ngClass]="{ 'is-queued': run.status === 'queued', 'is-success': run.status === 'success', 'is-running': run.status === 'running', 'is-errored': run.status === 'failed' }">
144144
<div class="column is-4">
145145
<span>{{ run.start_time | date:'dd MM yyyy hh:mm:ss' }} - {{ run.end_time | date:'dd MM yyyy hh:mm:ss' }}</span>
146146
</div>

0 commit comments

Comments
 (0)