actions-hugo/lib/get-latest-version.js
Shohei Ueda 4d54b90c0e
Refactor: directory structure (#31)
* config: update version
* refactor: move source codes to lib directory, Close #30
* refactor: move test code
2019-09-18 07:32:17 +09:00

21 lines
706 B
JavaScript

const XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;
function getLatestVersion() {
return new Promise((resolve, reject) => {
const xhr = new XMLHttpRequest();
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 latestVersion = result.versions.stable;
resolve(latestVersion);
} else if (xhr.readyState === 4 && xhr.status !== 200) {
reject(`ERROR: got status ${xhr.status} of ${url}`);
}
};
});
}
module.exports = getLatestVersion;