fix: tests, get latest release tag recursively

v1.18.x
Barış Soner Uşaklı 4 years ago
parent 804729fcec
commit 8eb62e2210

@ -10,8 +10,8 @@ let versionCacheLastModified = '';
const isPrerelease = /^v?\d+\.\d+\.\d+-.+$/; const isPrerelease = /^v?\d+\.\d+\.\d+-.+$/;
function getLatestVersion(callback) { function getLatestRelease(page, callback) {
var headers = { const headers = {
Accept: 'application/vnd.github.v3+json', Accept: 'application/vnd.github.v3+json',
'User-Agent': encodeURIComponent('NodeBB Admin Control Panel/' + meta.config.title), 'User-Agent': encodeURIComponent('NodeBB Admin Control Panel/' + meta.config.title),
}; };
@ -19,8 +19,7 @@ function getLatestVersion(callback) {
if (versionCacheLastModified) { if (versionCacheLastModified) {
headers['If-Modified-Since'] = versionCacheLastModified; headers['If-Modified-Since'] = versionCacheLastModified;
} }
request('https://api.github.com/repos/NodeBB/NodeBB/tags?page=' + page, {
request('https://api.github.com/repos/NodeBB/NodeBB/tags', {
json: true, json: true,
headers: headers, headers: headers,
timeout: 1000, timeout: 1000,
@ -34,7 +33,7 @@ function getLatestVersion(callback) {
} }
if (res.statusCode !== 200) { if (res.statusCode !== 200) {
return callback(Error(res.statusMessage)); return callback(new Error(res.statusMessage));
} }
releases = releases.filter(function (version) { releases = releases.filter(function (version) {
@ -45,6 +44,9 @@ function getLatestVersion(callback) {
return semver.lt(a, b) ? 1 : -1; return semver.lt(a, b) ? 1 : -1;
}); });
if (!releases.length) {
return getLatestRelease(page + 1, callback);
}
versionCache = releases[0]; versionCache = releases[0];
versionCacheLastModified = res.headers['last-modified']; versionCacheLastModified = res.headers['last-modified'];
@ -52,6 +54,10 @@ function getLatestVersion(callback) {
}); });
} }
function getLatestVersion(callback) {
getLatestRelease(1, callback);
}
exports.getLatestVersion = getLatestVersion; exports.getLatestVersion = getLatestVersion;
exports.isPrerelease = isPrerelease; exports.isPrerelease = isPrerelease;

Loading…
Cancel
Save