Skip to content

Commit abc7cec

Browse files
Izak88jkuri
authored andcommitted
feat(): calculated time of previous build
1 parent d6157ad commit abc7cec

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

src/api/db/build.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,23 @@ export function getBuild(id: number): Promise<any> {
3636
return job;
3737
});
3838

39-
resolve(build);
39+
return build;
40+
})
41+
.then(build => {
42+
new Build()
43+
.query(q => {
44+
q.where('head_github_id', build.head_github_id)
45+
.andWhere('id', '<', build.id)
46+
.andWhere('start_time', 'is not null')
47+
.andWhere('end_time', 'is not null')
48+
.orderBy('id', 'desc');
49+
})
50+
.fetch()
51+
.then(lastBuild => {
52+
build.lastBuild = lastBuild;
53+
54+
resolve(build);
55+
});
4056
});
4157
});
4258
}

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Component, OnInit, NgZone } from '@angular/core';
22
import { ActivatedRoute, Router } from '@angular/router';
33
import { ApiService } from '../../services/api.service';
44
import { SocketService } from '../../services/socket.service';
5-
import { distanceInWordsToNow, format } from 'date-fns';
5+
import { distanceInWordsToNow, distanceInWordsStrict, format } from 'date-fns';
66

77
@Component({
88
selector: 'app-build-details',
@@ -15,6 +15,7 @@ export class AppBuildDetailsComponent implements OnInit {
1515
status: string;
1616
timeWords: string;
1717
totalTime: string;
18+
previousRuntime: string;
1819
processingBuild: boolean;
1920

2021
constructor(
@@ -37,6 +38,8 @@ export class AppBuildDetailsComponent implements OnInit {
3738
this.build = build;
3839
this.build.jobs.forEach(job => job.time = '00:00');
3940
this.timeWords = distanceInWordsToNow(this.build.start_time);
41+
this.previousRuntime = distanceInWordsStrict(
42+
this.build.lastBuild.end_time, this.build.lastBuild.start_time);
4043

4144
this.status = this.getBuildStatus();
4245

0 commit comments

Comments
 (0)