diff --git a/src/api/status/public/js/build-log/api.js b/src/api/status/public/js/build-log/api.js index e6f542a9e0..dd56b3d994 100644 --- a/src/api/status/public/js/build-log/api.js +++ b/src/api/status/public/js/build-log/api.js @@ -1,5 +1,6 @@ // http://localhost:1111/pages/build.html -> http://localhost:4000/:path -const autodeploymentUrl = (path) => `//${window.location.hostname}:4000/${path}`; +// const autodeploymentUrl = (path) => `//${window.location.hostname}:4000/${path}`; +const autodeploymentUrl = (path) => `//dev.api.telescope.cdot.systems:4000/${path}`; export const checkBuildStatus = async () => { try { @@ -15,7 +16,10 @@ export const checkBuildStatus = async () => { return { building: true, title: data.type, + githubData: data.current.githubData, startedAt: new Date(data.current.startedDate), + stoppedAt: new Date(data.current.stopDate), + result: data.code, }; } catch (err) { console.error(err); diff --git a/src/api/status/public/js/build-log/build-header.js b/src/api/status/public/js/build-log/build-header.js index e87d523ed9..0b1c52ded3 100644 --- a/src/api/status/public/js/build-log/build-header.js +++ b/src/api/status/public/js/build-log/build-header.js @@ -1,6 +1,4 @@ -const autodeploymentUrl = (path) => `//dev.api.telescope.cdot.systems:4000/${path}`; - -const resMsg = document.getElementById('response-msg'); +const buildHeaderTitle = document.getElementById('build-header-title'); const buildHeaderInfo = document.getElementById('build-header-info'); const buildSender = document.getElementById('build-sender'); const buildSenderName = document.getElementById('build-sender-name'); @@ -10,38 +8,32 @@ const buildResult = document.getElementById('build-result'); const buildStarted = document.getElementById('build-started'); const buildDuration = document.getElementById('build-duration'); -function renderBuildInfo({ githubData, startedDate, stopDate, code }) { - resMsg.toggleAttribute('hidden'); - buildHeaderInfo.toggleAttribute('hidden'); +function renderBuildInfo({ githubData, startedAt, stoppedAt, result }) { + buildHeaderTitle.innerHTML = ''; + buildHeaderTitle.innerText = 'Build Status'; buildSender.setAttribute('href', githubData.sender.html_url); buildSenderName.innerText = githubData.sender.login; buildSenderImg.src = githubData.sender.avatar_url; buildGitSHA.setAttribute('href', githubData.compare); buildGitSHA.innerText = githubData.after.substring(0, 7); - buildResult.innerText = code === 0 ? 'Good' : 'Error'; - buildStarted.innerText = new Date(startedDate).toUTCString(); + buildResult.innerText = result === 0 ? 'Good' : 'Error'; + buildStarted.innerText = new Date(startedAt).toUTCString(); - const duration = new Date(stopDate).getTime() - new Date(startedDate).getTime(); + const duration = new Date(stoppedAt).getTime() - new Date(startedAt).getTime(); const minutes = Math.floor(duration / 60000); const seconds = ((duration % 60000) / 1000).toFixed(0); buildDuration.innerText = `${minutes}m ${seconds}s`; } -export default async function buildHeader() { - try { - const res = await fetch(autodeploymentUrl('status')); - if (!res.ok) { - const icon = document.createElement('i'); - icon.className = 'fas fa-server px-2'; - resMsg.innerHTML = ''; - resMsg.append(icon); - resMsg.innerHTML += 'Unable to get build info.'; - - throw new Error('Unable to get build info'); - } - const { previous } = await res.json(); - renderBuildInfo(previous); - } catch (err) { - console.error(err); +export default function buildHeader(data) { + if (!data.building) { + const icon = document.createElement('i'); + icon.className = 'fas fa-server px-2'; + buildHeaderTitle.innerHTML = ''; + buildHeaderTitle.append(icon); + buildHeaderTitle.innerHTML += 'Unable to get build info.'; + buildHeaderInfo.innerHTML = ''; + return; } + renderBuildInfo(data); } diff --git a/src/api/status/public/js/build-log/check-for-build.js b/src/api/status/public/js/build-log/check-for-build.js index a5e4e1de76..9cd9310fb0 100644 --- a/src/api/status/public/js/build-log/check-for-build.js +++ b/src/api/status/public/js/build-log/check-for-build.js @@ -1,6 +1,7 @@ /* eslint-disable consistent-return */ import { checkBuildStatus, getBuildLog } from './api.js'; import terminal from './terminal.js'; +import buildHeader from './build-header.js'; let build; let reader; @@ -27,12 +28,14 @@ function processLog({ done, value }) { } export default async function checkForBuild() { + const status = await checkBuildStatus(); + buildHeader(status); + // If we're already building, skip this check if (build) { return; } - const status = await checkBuildStatus(); if (status.building) { terminal.clear(); reader = await getBuildLog(); diff --git a/src/api/status/public/js/pages/build.js b/src/api/status/public/js/pages/build.js index 18eaf85189..44ce3efb15 100644 --- a/src/api/status/public/js/pages/build.js +++ b/src/api/status/public/js/pages/build.js @@ -1,8 +1,6 @@ import checkForBuild from '../build-log/check-for-build.js'; -import buildHeader from '../build-log/build-header.js'; window.addEventListener('load', () => { checkForBuild(); - buildHeader(); setInterval(checkForBuild, 5000); }); diff --git a/src/api/status/public/pages/build.html b/src/api/status/public/pages/build.html index 6c1b4e9d4a..fedb8ad312 100644 --- a/src/api/status/public/pages/build.html +++ b/src/api/status/public/pages/build.html @@ -167,12 +167,11 @@