From 94c9d547499394152863a2ad05d8ea395d277ae8 Mon Sep 17 00:00:00 2001 From: Elliot Jackson Date: Sat, 25 Feb 2017 13:37:49 +0100 Subject: [PATCH 1/5] Set the latest version to be unstable MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit — Elliot Jackson --- mirage/fixtures/crate.js | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/mirage/fixtures/crate.js b/mirage/fixtures/crate.js index 3d4e670ab65..51ea63abf62 100644 --- a/mirage/fixtures/crate.js +++ b/mirage/fixtures/crate.js @@ -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, @@ -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", From 3c2793d4657c217aa01f89393eeaa14ff5d58399 Mon Sep 17 00:00:00 2001 From: Elliot Jackson Date: Sat, 25 Feb 2017 13:40:47 +0100 Subject: [PATCH 2/5] Show the last stable release of a crate on it's index page MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit — Elliot Jackson --- app/routes/crate/version.js | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/app/routes/crate/version.js b/app/routes/crate/version.js index 94c08cb4046..316d461cc3d 100644 --- a/app/routes/crate/version.js +++ b/app/routes/crate/version.js @@ -10,9 +10,34 @@ 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 unstableFlags = ['alpha', 'beta']; + + return unstableFlags.some((flag) => { + return version.includes(flag); + }); + }; + + // Fallback to the crate's last stable version if (!requestedVersion) { - 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); From 32d721898f64f627730f24a8191b40fbb43cb0a7 Mon Sep 17 00:00:00 2001 From: Elliot Jackson Date: Sat, 25 Feb 2017 14:18:27 +0100 Subject: [PATCH 3/5] Fix for Phantom MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `includes` is valid ES6 but Phantom doesn't seem to like it: the tests fail with it set. Reverted to the tried and true `indexOf`. All tests are passing. — Elliot Jackson --- app/routes/crate/version.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/routes/crate/version.js b/app/routes/crate/version.js index 316d461cc3d..727c02dd250 100644 --- a/app/routes/crate/version.js +++ b/app/routes/crate/version.js @@ -14,7 +14,7 @@ export default Ember.Route.extend({ const unstableFlags = ['alpha', 'beta']; return unstableFlags.some((flag) => { - return version.includes(flag); + return version.indexOf(flag) > -1; }); }; From 9a4a67c226dccba2c4332d98c8de98b7d624b6a1 Mon Sep 17 00:00:00 2001 From: Elliot Jackson Date: Wed, 8 Mar 2017 12:47:26 +0100 Subject: [PATCH 4/5] Get crate version tests passing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit — Elliot Jackson --- tests/acceptance/crate-test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/acceptance/crate-test.js b/tests/acceptance/crate-test.js index 21973f44dcc..47bad3f728c 100644 --- a/tests/acceptance/crate-test.js +++ b/tests/acceptance/crate-test.js @@ -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/); }); }); From 370b9c2d5e83589b9459c0510515beccc9cd2bd1 Mon Sep 17 00:00:00 2001 From: Elliot Jackson Date: Thu, 9 Mar 2017 10:04:02 +0100 Subject: [PATCH 5/5] Consider any version with chars after major.minor.patch as unstable MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit — Elliot Jackson --- app/routes/crate/version.js | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/app/routes/crate/version.js b/app/routes/crate/version.js index e69f1c33131..e41d3eec034 100644 --- a/app/routes/crate/version.js +++ b/app/routes/crate/version.js @@ -10,12 +10,26 @@ export default Ember.Route.extend({ const controller = this.controllerFor(this.routeName); const maxVersion = crate.get('max_version'); - const isUnstableVersion = (version) => { - const unstableFlags = ['alpha', 'beta']; + const isUnstableVersion = version => { + const versionLen = version.length; + let majorMinorPatchChars = 0; + let result = false; - return unstableFlags.some((flag) => { - return version.indexOf(flag) > -1; - }); + 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