Refactor: Get the latest version from Homebrew (#28)

Refactoring

* feat: Add reject to Promise
* feat: Add printing inputs
* feat: Add error handling to getLatestVersion()
* feat: show version of Hugo, Go, and Git (Close #23)
* refactor: Get the latest version from Homebrew (Close #26)
* refactor: enhance error message of promise reject

Enhancement for workflow

* gha: Add deps (test-prod job needs test job)
* gha: Fix matrix testing
* gha: comment out Build production step
* gha: remove Dump step

Update README

* docs: update readme
This commit is contained in:
Shohei Ueda
2019-09-18 04:11:47 +09:00
committed by GitHub
parent 85171ece4e
commit d46d0aa12e
6 changed files with 102 additions and 86 deletions

View File

@@ -1,22 +1,18 @@
const XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;
function getLatestVersion() {
// return new Promise((resolve, reject) => {
return new Promise(resolve => {
return new Promise((resolve, reject) => {
const xhr = new XMLHttpRequest();
const url = "https://api.github.com/repos/gohugoio/hugo/releases/latest";
const url = "https://formulae.brew.sh/api/formula/hugo.json";
xhr.open("GET", url);
xhr.send();
xhr.onreadystatechange = function() {
if (xhr.readyState === 4 && xhr.status === 200) {
const result = JSON.parse(xhr.responseText);
const latestURL = result["assets"][0].browser_download_url;
const latestVersion = latestURL.match(/(\d+).(\d+).(\d+)/g)[0];
const latestVersion = result.versions.stable;
resolve(latestVersion);
// } else {
// reject(`ERROR: got status ${xhr.status}`);
} else if (xhr.readyState === 4 && xhr.status !== 200) {
reject(`ERROR: got status ${xhr.status} of ${url}`);
}
};
});