Skip to content

Commit 672eaa9

Browse files
Merge pull request #577 from elliotekj/#468-encourage-stable-version
#468 encourage stable version
2 parents ddc630d + 370b9c2 commit 672eaa9

File tree

3 files changed

+66
-5
lines changed

3 files changed

+66
-5
lines changed

app/routes/crate/version.js

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,49 @@ export default Ember.Route.extend({
1010
const controller = this.controllerFor(this.routeName);
1111
const maxVersion = crate.get('max_version');
1212

13-
// Fall back to the crate's `max_version` property
13+
const isUnstableVersion = version => {
14+
const versionLen = version.length;
15+
let majorMinorPatchChars = 0;
16+
let result = false;
17+
18+
for (let i = 0; i < versionLen; i++) {
19+
const char = version.charAt(i);
20+
21+
if (!isNaN(parseInt(char)) || char === '.') {
22+
majorMinorPatchChars++;
23+
} else {
24+
break;
25+
}
26+
}
27+
28+
if (versionLen !== majorMinorPatchChars) {
29+
result = true;
30+
}
31+
32+
return result;
33+
};
34+
35+
// Fallback to the crate's last stable version
36+
// If `max_version` is `0.0.0` then all versions have been yanked
1437
if (!requestedVersion && maxVersion !== '0.0.0') {
15-
params.version_num = maxVersion;
38+
if (isUnstableVersion(maxVersion)) {
39+
crate.get('versions').then(versions => {
40+
const latestStableVersion = versions.find(version => {
41+
if (!isUnstableVersion(version.get('num'))) {
42+
return version;
43+
}
44+
});
45+
46+
if (latestStableVersion == null) {
47+
// If no stable version exists, fallback to `maxVersion`
48+
params.version_num = maxVersion;
49+
} else {
50+
params.version_num = latestStableVersion.get('num');
51+
}
52+
});
53+
} else {
54+
params.version_num = maxVersion;
55+
}
1656
}
1757

1858
controller.set('crate', crate);

mirage/fixtures/crate.js

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,12 @@ export default {
2020
"version_downloads": "/api/v1/crates/nanomsg/downloads",
2121
"versions": null
2222
},
23-
"max_version": "0.6.1",
23+
"max_version": "0.7.0-alpha",
2424
"name": "nanomsg",
2525
"repository": "https://github.com/thehydroimpulse/nanomsg.rs",
26-
"updated_at": "2016-12-27T08:40:00Z",
26+
"updated_at": "2016-12-28T08:40:00Z",
2727
"versions": [
28+
40906,
2829
40905,
2930
28431,
3031
21273,
@@ -48,6 +49,26 @@ export default {
4849
}
4950
],
5051
"versions": [
52+
{
53+
"crate": "nanomsg",
54+
"created_at": "2016-12-28T08:40:00Z",
55+
"dl_path": "/api/v1/crates/nanomsg/0.7.0-alpha/download",
56+
"downloads": 260,
57+
"features": {
58+
"bundled": [
59+
"nanomsg-sys/bundled"
60+
]
61+
},
62+
"id": 40906,
63+
"links": {
64+
"authors": "/api/v1/crates/nanomsg/0.7.0-alpha/authors",
65+
"dependencies": "/api/v1/crates/nanomsg/0.7.0-alpha/dependencies",
66+
"version_downloads": "/api/v1/crates/nanomsg/0.7.0-alpha/downloads"
67+
},
68+
"num": "0.7.0-alpha",
69+
"updated_at": "2016-12-28T08:40:00Z",
70+
"yanked": false
71+
},
5172
{
5273
"crate": "nanomsg",
5374
"created_at": "2016-12-27T08:40:00Z",

tests/acceptance/crate-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ test('navigating to the all versions page', function(assert) {
2727
click('#crate-versions span.small a');
2828

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

0 commit comments

Comments
 (0)