Skip to content

Commit

Permalink
fix: tests, get latest release tag recursively
Browse files Browse the repository at this point in the history
  • Loading branch information
barisusakli committed Oct 7, 2020
1 parent 804729f commit 8eb62e2
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/admin/versions.js
Expand Up @@ -10,17 +10,16 @@ let versionCacheLastModified = '';

const isPrerelease = /^v?\d+\.\d+\.\d+-.+$/;

function getLatestVersion(callback) {
var headers = {
function getLatestRelease(page, callback) {
const headers = {
Accept: 'application/vnd.github.v3+json',
'User-Agent': encodeURIComponent('NodeBB Admin Control Panel/' + meta.config.title),
};

if (versionCacheLastModified) {
headers['If-Modified-Since'] = versionCacheLastModified;
}

request('https://api.github.com/repos/NodeBB/NodeBB/tags', {
request('https://api.github.com/repos/NodeBB/NodeBB/tags?page=' + page, {
json: true,
headers: headers,
timeout: 1000,
Expand All @@ -34,7 +33,7 @@ function getLatestVersion(callback) {
}

if (res.statusCode !== 200) {
return callback(Error(res.statusMessage));
return callback(new Error(res.statusMessage));
}

releases = releases.filter(function (version) {
Expand All @@ -45,13 +44,20 @@ function getLatestVersion(callback) {
return semver.lt(a, b) ? 1 : -1;
});

if (!releases.length) {
return getLatestRelease(page + 1, callback);
}
versionCache = releases[0];
versionCacheLastModified = res.headers['last-modified'];

callback(null, versionCache);
});
}

function getLatestVersion(callback) {
getLatestRelease(1, callback);
}

exports.getLatestVersion = getLatestVersion;
exports.isPrerelease = isPrerelease;

Expand Down

0 comments on commit 8eb62e2

Please sign in to comment.