Skip to content

Commit

Permalink
Display build time for environments
Browse files Browse the repository at this point in the history
  • Loading branch information
steff456 committed Sep 7, 2023
1 parent 6df9e99 commit c9a400e
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/utils/helpers/buildMapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@ const isQueued = (status: string) => {
return BUILD_STATUS.includes(status);
};

const isCompleted = (status: string) => {
const isCompleted = (status: string, duration: number) => {
if (status === "COMPLETED") {
if (duration > 0) {
return `Completed in ${duration} min`;
}
return "Completed";
}
return STATUS_OPTIONS[status];
Expand All @@ -39,11 +42,18 @@ const dateToTimezone = (date: string) => {

export const buildMapper = (data: Build[], currentBuildId: number) => {
return data.map(({ id, status, ended_on, scheduled_on }: Build) => {
let duration = 0;
if (ended_on && scheduled_on) {
const startTime = new Date(scheduled_on);
const endTime = new Date(ended_on);
duration = (endTime.valueOf() - startTime.valueOf()) / 60000;
duration = Math.round(duration);
}
if (id === currentBuildId) {
return {
id,
name: `${dateToTimezone(ended_on ?? scheduled_on)} - Active`,
status: isCompleted(status)
status: isCompleted(status, duration)
};
}

Expand All @@ -68,7 +78,7 @@ export const buildMapper = (data: Build[], currentBuildId: number) => {
name: `${dateToTimezone(ended_on ?? scheduled_on)} - ${
STATUS_OPTIONS[status]
}`,
status: isCompleted(status)
status: isCompleted(status, duration)
};
});
};

0 comments on commit c9a400e

Please sign in to comment.