From 958db5135dce7713d09e562221e58532abc50d51 Mon Sep 17 00:00:00 2001 From: Dragory <2606411+Dragory@users.noreply.github.com> Date: Mon, 17 Aug 2020 02:07:03 +0300 Subject: [PATCH] Use releases instead of tags in update check, ignore prereleases/drafts --- src/data/updates.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/data/updates.js b/src/data/updates.js index ac83ad8..02b8cf1 100644 --- a/src/data/updates.js +++ b/src/data/updates.js @@ -42,7 +42,7 @@ async function refreshVersions() { https.get( { hostname: "api.github.com", - path: `/repos/${owner}/${repo}/tags`, + path: `/repos/${owner}/${repo}/releases`, headers: { "User-Agent": `Modmail Bot (https://github.com/${owner}/${repo}) (${packageJson.version})` } @@ -62,7 +62,10 @@ async function refreshVersions() { const parsed = JSON.parse(data); if (! Array.isArray(parsed) || parsed.length === 0) return; - const latestVersion = parsed[0].name; + const latestStableRelease = parsed.find(r => ! r.prerelease && ! r.draft); + if (! latestStableRelease) return; + + const latestVersion = latestStableRelease.name; await knex("updates").update({ available_version: latestVersion, last_checked: moment.utc().format("YYYY-MM-DD HH:mm:ss")