Skip to content

#468 encourage stable version #577

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 42 additions & 2 deletions app/routes/crate/version.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,49 @@ export default Ember.Route.extend({
const controller = this.controllerFor(this.routeName);
const maxVersion = crate.get('max_version');

// Fall back to the crate's `max_version` property
const isUnstableVersion = version => {
const versionLen = version.length;
let majorMinorPatchChars = 0;
let result = false;

for (let i = 0; i < versionLen; i++) {
const char = version.charAt(i);

if (!isNaN(parseInt(char)) || char === '.') {
majorMinorPatchChars++;
} else {
break;
}
}

if (versionLen !== majorMinorPatchChars) {
result = true;
}

return result;
};

// Fallback to the crate's last stable version
// If `max_version` is `0.0.0` then all versions have been yanked
if (!requestedVersion && maxVersion !== '0.0.0') {
params.version_num = maxVersion;
if (isUnstableVersion(maxVersion)) {
crate.get('versions').then(versions => {
const latestStableVersion = versions.find(version => {
if (!isUnstableVersion(version.get('num'))) {
return version;
}
});

if (latestStableVersion == null) {
// If no stable version exists, fallback to `maxVersion`
params.version_num = maxVersion;
} else {
params.version_num = latestStableVersion.get('num');
}
});
} else {
params.version_num = maxVersion;
}
}

controller.set('crate', crate);
Expand Down
25 changes: 23 additions & 2 deletions mirage/fixtures/crate.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ export default {
"version_downloads": "/api/v1/crates/nanomsg/downloads",
"versions": null
},
"max_version": "0.6.1",
"max_version": "0.7.0-alpha",
"name": "nanomsg",
"repository": "https://github.com/thehydroimpulse/nanomsg.rs",
"updated_at": "2016-12-27T08:40:00Z",
"updated_at": "2016-12-28T08:40:00Z",
"versions": [
40906,
40905,
28431,
21273,
Expand All @@ -48,6 +49,26 @@ export default {
}
],
"versions": [
{
"crate": "nanomsg",
"created_at": "2016-12-28T08:40:00Z",
"dl_path": "/api/v1/crates/nanomsg/0.7.0-alpha/download",
"downloads": 260,
"features": {
"bundled": [
"nanomsg-sys/bundled"
]
},
"id": 40906,
"links": {
"authors": "/api/v1/crates/nanomsg/0.7.0-alpha/authors",
"dependencies": "/api/v1/crates/nanomsg/0.7.0-alpha/dependencies",
"version_downloads": "/api/v1/crates/nanomsg/0.7.0-alpha/downloads"
},
"num": "0.7.0-alpha",
"updated_at": "2016-12-28T08:40:00Z",
"yanked": false
},
{
"crate": "nanomsg",
"created_at": "2016-12-27T08:40:00Z",
Expand Down
2 changes: 1 addition & 1 deletion tests/acceptance/crate-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ test('navigating to the all versions page', function(assert) {
click('#crate-versions span.small a');

andThen(function() {
matchesText(assert, '.info', /All 12 versions of nanomsg since December \d+, 2014/);
matchesText(assert, '.info', /All 13 versions of nanomsg since December \d+, 2014/);
});
});

Expand Down