Skip to content

Commit

Permalink
Allow channel updates across releases.
Browse files Browse the repository at this point in the history
  • Loading branch information
skewart committed Dec 21, 2015
1 parent b62934d commit 0190e8e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
12 changes: 7 additions & 5 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ module.exports = function nuts(opts) {
var fullUrl = getFullUrl(req);
var platform = req.params.platform;
var tag = req.params.version;
var channel = req.query.channel;

Q()
.then(function() {
Expand All @@ -170,9 +171,9 @@ module.exports = function nuts(opts) {
platform = platforms.detect(platform);

return versions.filter({
tag: '>='+tag,
tag: tag,
platform: platform,
channel: '*'
channel: channel
});
})
.then(function(versions) {
Expand All @@ -197,15 +198,16 @@ module.exports = function nuts(opts) {
var fullUrl = getFullUrl(req);
var platform = 'win_32';
var tag = req.params.version;
var channel = req.query.channel;

Q()
.then(function() {
platform = platforms.detect(platform);

return versions.filter({
tag: '>='+tag,
tag: tag,
platform: platform,
channel: '*'
channel: channel
});
})
.then(function(versions) {
Expand Down Expand Up @@ -251,7 +253,7 @@ module.exports = function nuts(opts) {
Q()
.then(function() {
return versions.filter({
tag: tag? '>='+tag : '*',
tag: tag? tag : '*',
channel: '*'
});
})
Expand Down
12 changes: 9 additions & 3 deletions lib/versions.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ module.exports = function(github, opts) {
opts = _.defaults(opts || {}, {
tag: 'latest',
platform: null,
channel: 'stable'
channel: extractChannel(opts.tag)
});
if (opts.platform) opts.platform = platforms.detect(opts.platform);

Expand All @@ -97,18 +97,24 @@ module.exports = function(github, opts) {
return _.chain(versions)
.filter(function(version) {
// Check channel
if (opts.channel != '*' && version.channel != opts.channel) return false;
if (!channelsMatch(version.channel, opts.channel)) return false;

// Not available for requested paltform
if (opts.platform && !platforms.satisfies(opts.platform, _.pluck(version.platforms, 'type'))) return false;

// Check tag satisfies request version
return opts.tag == 'latest' || semver.satisfies(version.tag, opts.tag);
return opts.tag == 'latest' || (semver.rcompare(version.tag, opts.tag) < 0);
})
.value();
});
}

function channelsMatch(versionChannel, currentChannel) {
if ((currentChannel === '*') ||
(currentChannel === versionChannel) ||
(currentChannel != 'stable' && versionChannel == 'stable')) return true;
}

// Resolve a platform
function resolveVersion(opts) {
return filterVersions(opts)
Expand Down

0 comments on commit 0190e8e

Please sign in to comment.