Use releases instead of tags in update check, ignore prereleases/drafts

cshd
Dragory 2020-08-17 02:07:03 +03:00
parent f8d53741e4
commit 958db5135d
No known key found for this signature in database
GPG Key ID: 5F387BA66DF8AAC1
1 changed files with 5 additions and 2 deletions

View File

@ -42,7 +42,7 @@ async function refreshVersions() {
https.get( https.get(
{ {
hostname: "api.github.com", hostname: "api.github.com",
path: `/repos/${owner}/${repo}/tags`, path: `/repos/${owner}/${repo}/releases`,
headers: { headers: {
"User-Agent": `Modmail Bot (https://github.com/${owner}/${repo}) (${packageJson.version})` "User-Agent": `Modmail Bot (https://github.com/${owner}/${repo}) (${packageJson.version})`
} }
@ -62,7 +62,10 @@ async function refreshVersions() {
const parsed = JSON.parse(data); const parsed = JSON.parse(data);
if (! Array.isArray(parsed) || parsed.length === 0) return; 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({ await knex("updates").update({
available_version: latestVersion, available_version: latestVersion,
last_checked: moment.utc().format("YYYY-MM-DD HH:mm:ss") last_checked: moment.utc().format("YYYY-MM-DD HH:mm:ss")