From f6938f5ec5b30bcbc95459841ca39d7f402f43de Mon Sep 17 00:00:00 2001 From: Steve Faulkner Date: Wed, 15 Jul 2020 07:49:06 -0500 Subject: [PATCH] Add deployment status CLI utility (#86) --- utils/deployment-status/index.js | 33 +++++++++++ utils/deployment-status/package-lock.json | 67 +++++++++++++++++++++++ utils/deployment-status/package.json | 17 ++++++ 3 files changed, 117 insertions(+) create mode 100644 utils/deployment-status/index.js create mode 100644 utils/deployment-status/package-lock.json create mode 100644 utils/deployment-status/package.json diff --git a/utils/deployment-status/index.js b/utils/deployment-status/index.js new file mode 100644 index 000000000..fb41ca12e --- /dev/null +++ b/utils/deployment-status/index.js @@ -0,0 +1,33 @@ +const fetch = require("node-fetch"); +const chalk = require("chalk"); +const moment = require("moment"); +const log = console.log; + +async function main() { + const prodResponse = await fetch("https://cosmos.azure.com/version.txt"); + const mpacResponse = await fetch("https://cosmos.azure.com/mpac/version.txt"); + const commitsResponse = await fetch("https://api.github.com/repos/Azure/cosmos-explorer/commits"); + const prod = await prodResponse.text(); + const mpac = await mpacResponse.text(); + const commits = await commitsResponse.json(); + const [, prodSha, prodDateString] = prod.match(/(\w+)\s(.+)/); + const [, mpacSha, mpacDateString] = mpac.match(/(\w+)\s(.+)/); + const prodDate = moment(prodDateString); + const mpacDate = moment(mpacDateString); + + let color = "red"; + + commits.forEach(commit => { + if (commit.sha === mpacSha) { + color = "yellow"; + log(chalk.keyword(color)(`\n=========== MPAC ${mpacDate.fromNow()} =============\n`)); + } + if (commit.sha === prodSha) { + color = "green"; + log(chalk.keyword(color)(`\n============= PROD ${prodDate.fromNow()} =============\n`)); + } + log(chalk.keyword(color)(commit.commit.message.split("\n")[0], commit.author.login, commit.sha)); + }); +} + +main(); diff --git a/utils/deployment-status/package-lock.json b/utils/deployment-status/package-lock.json new file mode 100644 index 000000000..60a3d059c --- /dev/null +++ b/utils/deployment-status/package-lock.json @@ -0,0 +1,67 @@ +{ + "name": "deployment-status", + "version": "1.0.0", + "lockfileVersion": 1, + "requires": true, + "dependencies": { + "@types/color-name": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/@types/color-name/-/color-name-1.1.1.tgz", + "integrity": "sha512-rr+OQyAjxze7GgWrSaJwydHStIhHq2lvY3BOC2Mj7KnzI7XK0Uw1TOOdI9lDoajEbSWLiYgoo4f1R51erQfhPQ==" + }, + "ansi-styles": { + "version": "4.2.1", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.2.1.tgz", + "integrity": "sha512-9VGjrMsG1vePxcSweQsN20KY/c4zN0h9fLjqAbwbPfahM3t+NL+M9HC8xeXG2I8pX5NoamTGNuomEUFI7fcUjA==", + "requires": { + "@types/color-name": "^1.1.1", + "color-convert": "^2.0.1" + } + }, + "chalk": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.0.tgz", + "integrity": "sha512-qwx12AxXe2Q5xQ43Ac//I6v5aXTipYrSESdOgzrN+9XjgEpyjpKuvSGaN4qE93f7TQTlerQQ8S+EQ0EyDoVL1A==", + "requires": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + } + }, + "color-convert": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", + "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", + "requires": { + "color-name": "~1.1.4" + } + }, + "color-name": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", + "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==" + }, + "has-flag": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", + "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==" + }, + "moment": { + "version": "2.27.0", + "resolved": "https://registry.npmjs.org/moment/-/moment-2.27.0.tgz", + "integrity": "sha512-al0MUK7cpIcglMv3YF13qSgdAIqxHTO7brRtaz3DlSULbqfazqkc5kEjNrLDOM7fsjshoFIihnU8snrP7zUvhQ==" + }, + "node-fetch": { + "version": "2.6.0", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.0.tgz", + "integrity": "sha512-8dG4H5ujfvFiqDmVu9fQ5bOHUC15JMjMY/Zumv26oOvvVJjM67KF8koCWIabKQ1GJIa9r2mMZscBq/TbdOcmNA==" + }, + "supports-color": { + "version": "7.1.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.1.0.tgz", + "integrity": "sha512-oRSIpR8pxT1Wr2FquTNnGet79b3BWljqOuoW/h4oBhxJ/HUbX5nX6JSruTkvXDCFMwDPvsaTTbvMLKZWSy0R5g==", + "requires": { + "has-flag": "^4.0.0" + } + } + } +} diff --git a/utils/deployment-status/package.json b/utils/deployment-status/package.json new file mode 100644 index 000000000..5eefa5108 --- /dev/null +++ b/utils/deployment-status/package.json @@ -0,0 +1,17 @@ +{ + "name": "deployment-status", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "keywords": [], + "author": "", + "license": "ISC", + "dependencies": { + "chalk": "^4.1.0", + "moment": "^2.27.0", + "node-fetch": "^2.6.0" + } +}