Skip to content

Commit

Permalink
handle null values for the build started and finished dates
Browse files Browse the repository at this point in the history
  • Loading branch information
nilscox committed Aug 28, 2024
1 parent 5d5ad4c commit 6852d03
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/api/mappers/deployment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ function transformComputeDeployment(deployment: ApiDeployment): ComputeDeploymen
return {
status: lowerCase(stage.status!),
sha: deployment.provisioning_info?.sha,
// the API actually returns null
startedAt: stage.started_at!,
finishedAt: stage.finished_at!,
};
Expand Down
4 changes: 2 additions & 2 deletions src/api/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,8 @@ export type DeploymentStatus =
export type DeploymentBuild = {
status: DeploymentBuildStatus;
sha?: string;
startedAt: string;
finishedAt: string;
startedAt: string | null;
finishedAt: string | null;
};

export type DeploymentBuildStatus = 'unknown' | 'running' | 'failed' | 'completed' | 'aborted';
Expand Down
6 changes: 5 additions & 1 deletion src/modules/deployment/deployment-logs/deployment-logs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { useObserve } from 'src/hooks/lifecycle';
import { useLogs } from 'src/hooks/logs';
import { useNow } from 'src/hooks/timers';
import { Translate } from 'src/intl/translate';
import { assert } from 'src/utils/assert';

import { BuildLogs } from './build-logs';
import { Replicas } from './replicas';
Expand Down Expand Up @@ -200,7 +201,7 @@ function BuildSectionHeaderEnd({ expanded, deployment }: BuildSectionHeaderEndPr
return;
}

if (status === 'running' && expanded) {
if (status === 'running' && expanded && build.startedAt !== null) {
const duration = Math.floor((now.getTime() - new Date(build.startedAt).getTime()) / 1000);

return (
Expand Down Expand Up @@ -242,6 +243,9 @@ function getBuildStatus(deployment: ComputeDeployment): DeploymentBuildStatus |
}

function elapsed({ startedAt, finishedAt }: DeploymentBuild) {
assert(startedAt !== null);
assert(finishedAt !== null);

return (new Date(finishedAt).getTime() - new Date(startedAt).getTime()) / 1000;
}

Expand Down

0 comments on commit 6852d03

Please sign in to comment.