Skip to content

Commit

Permalink
♻️ Show degraded performance in README
Browse files Browse the repository at this point in the history
  • Loading branch information
AnandChowdhary committed Nov 22, 2020
1 parent ee91b1e commit 04d39fb
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
3 changes: 3 additions & 0 deletions src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -53,6 +55,7 @@ export interface UpptimeConfig {
responseTimeGraphAlt?: string;
liveStatus?: string;
allSystemsOperational?: string;
degradedPerformance?: string;
completeOutage?: string;
partialOutage?: string;
} & Record<string, string>;
Expand Down
24 changes: 18 additions & 6 deletions src/summary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ export const generateSummary = async () => {
// This object will track the summary data of all sites
const pageStatuses: Array<SiteStatus> = [];

// 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) {
Expand Down Expand Up @@ -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({
Expand All @@ -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}`;
Expand All @@ -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) | <img alt="${i18n.responseTimeGraphAlt || "Response time graph"}" src="./graphs/${
Expand Down Expand Up @@ -224,10 +234,12 @@ ${config.summaryEndHtmlComment || "<!--end: status pages-->"}${endText}`;
if (line.includes("<!--live status-->")) {
line = `${line.split("<!--live status-->")[0]}<!--live status--> **${
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;
Expand Down

0 comments on commit 04d39fb

Please sign in to comment.