From abc7cec3cf5d449b25c181b376da24499f04552e Mon Sep 17 00:00:00 2001 From: Izak Lipnik Date: Thu, 3 Aug 2017 18:22:45 +0200 Subject: [PATCH] feat(): calculated time of previous build --- src/api/db/build.ts | 18 +++++++++++++++++- .../app-build-details.component.ts | 5 ++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/api/db/build.ts b/src/api/db/build.ts index e87d90ee5..53b27b872 100644 --- a/src/api/db/build.ts +++ b/src/api/db/build.ts @@ -36,7 +36,23 @@ export function getBuild(id: number): Promise { return job; }); - resolve(build); + return build; + }) + .then(build => { + new Build() + .query(q => { + q.where('head_github_id', build.head_github_id) + .andWhere('id', '<', build.id) + .andWhere('start_time', 'is not null') + .andWhere('end_time', 'is not null') + .orderBy('id', 'desc'); + }) + .fetch() + .then(lastBuild => { + build.lastBuild = lastBuild; + + resolve(build); + }); }); }); } diff --git a/src/app/components/app-build-details/app-build-details.component.ts b/src/app/components/app-build-details/app-build-details.component.ts index b9bdc0848..83a1b1f5b 100644 --- a/src/app/components/app-build-details/app-build-details.component.ts +++ b/src/app/components/app-build-details/app-build-details.component.ts @@ -2,7 +2,7 @@ import { Component, OnInit, NgZone } from '@angular/core'; import { ActivatedRoute, Router } from '@angular/router'; import { ApiService } from '../../services/api.service'; import { SocketService } from '../../services/socket.service'; -import { distanceInWordsToNow, format } from 'date-fns'; +import { distanceInWordsToNow, distanceInWordsStrict, format } from 'date-fns'; @Component({ selector: 'app-build-details', @@ -15,6 +15,7 @@ export class AppBuildDetailsComponent implements OnInit { status: string; timeWords: string; totalTime: string; + previousRuntime: string; processingBuild: boolean; constructor( @@ -37,6 +38,8 @@ export class AppBuildDetailsComponent implements OnInit { this.build = build; this.build.jobs.forEach(job => job.time = '00:00'); this.timeWords = distanceInWordsToNow(this.build.start_time); + this.previousRuntime = distanceInWordsStrict( + this.build.lastBuild.end_time, this.build.lastBuild.start_time); this.status = this.getBuildStatus();