From 04d39fb1e2bb5f7841eaa8d1f5f8f224fc62576f Mon Sep 17 00:00:00 2001 From: Anand Chowdhary Date: Sun, 22 Nov 2020 15:11:26 +0530 Subject: [PATCH] :recycle: Show degraded performance in README --- src/interfaces.ts | 3 +++ src/summary.ts | 24 ++++++++++++++++++------ 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/interfaces.ts b/src/interfaces.ts index 295cc093..42552c79 100644 --- a/src/interfaces.ts +++ b/src/interfaces.ts @@ -41,9 +41,11 @@ export interface UpptimeConfig { liveStatusHtmlComment?: string; commitPrefixStatusUp?: string; commitPrefixStatusDown?: string; + commitPrefixStatusDegraded?: string; i18n?: { up?: string; down?: string; + degraded?: string; url?: string; status?: string; history?: string; @@ -53,6 +55,7 @@ export interface UpptimeConfig { responseTimeGraphAlt?: string; liveStatus?: string; allSystemsOperational?: string; + degradedPerformance?: string; completeOutage?: string; partialOutage?: string; } & Record; diff --git a/src/summary.ts b/src/summary.ts index 4ccd769e..e03d842e 100644 --- a/src/summary.ts +++ b/src/summary.ts @@ -29,9 +29,10 @@ export const generateSummary = async () => { // This object will track the summary data of all sites const pageStatuses: Array = []; - // We'll keep incrementing this if there are down sites + // We'll keep incrementing this if there are down/degraded sites // This is used to show the overall status later let numberOfDown = 0; + let numberOfDegraded = 0; // Loop through each site and add compute the current status for await (const site of config.sites) { @@ -64,11 +65,15 @@ export const generateSummary = async () => { .filter((item) => item && !isNaN(item)) .reduce((p, c) => p + c, 0) / history.data.length; - // Current status is "up" or "down" based on the emoji prefix of the commit message - const status = history.data[0].commit.message + // Current status is "up", "down", or "degraded" based on the emoji prefix of the commit message + const status: "up" | "down" | "degraded" = history.data[0].commit.message .split(" ")[0] .includes(config.commitPrefixStatusUp || "🟩") ? "up" + : history.data[0].commit.message + .split(" ")[0] + .includes(config.commitPrefixStatusDegraded || "🟨") + ? "degraded" : "down"; pageStatuses.push({ @@ -80,6 +85,7 @@ export const generateSummary = async () => { time: Math.floor(averageTime), }); if (status === "down") numberOfDown++; + if (status === "degraded") numberOfDegraded++; } let website = `https://${config.owner}.github.io/${config.repo}`; @@ -100,7 +106,11 @@ ${pageStatuses .map( (page) => `| ${page.url.includes("$") ? page.name : `[${page.name}](${page.url})`} | ${ - page.status === "up" ? i18n.up || "🟩 Up" : i18n.down || "🟥 Down" + page.status === "up" + ? i18n.up || "🟩 Up" + : page.status === "degraded" + ? i18n.degraded || "🟨 Degraded" + : i18n.down || "🟥 Down" } | [${page.slug}.yml](https://github.com/${owner}/${repo}/commits/master/history/${ page.slug }.yml) | ${i18n.responseTimeGraphAlt || "}${endText}`; if (line.includes("")) { line = `${line.split("")[0]} **${ numberOfDown === 0 - ? i18n.allSystemsOperational || "🟩 All systems operational" + ? numberOfDegraded === 0 + ? i18n.allSystemsOperational || "🟩 All systems operational" + : i18n.degradedPerformance || "🟨 Degraded performance" : numberOfDown === config.sites.length ? i18n.completeOutage || "🟥 Complete outage" - : i18n.partialOutage || "🟨 Partial outage" + : i18n.partialOutage || "🟧 Partial outage" }**`; } return line;