Skip to content

Commit ed4eda0

Browse files
chancancodepatricklx
authored andcommitted
Render the CHANGELOG for the current version (emberjs#1115)
There are a few cases where the CHANGELOG on master may not match the version you are actually running. For example, master can be behind the stable branch's CHANGELOGs, or you could be loading and running a nightly version. This patch try to fetch the CHANGELOG from the correct Git tag to ensure things matches up correctly.
1 parent c963988 commit ed4eda0

3 files changed

Lines changed: 94 additions & 30 deletions

File tree

app/routes/whats-new.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,32 @@
11
import TabRoute from 'ember-inspector/routes/tab';
22
import fetch from 'fetch';
33

4-
const checkStatus = function(response) {
4+
function checkStatus(response) {
55
if (response.status >= 200 && response.status < 300) {
66
return response;
77
} else {
88
const error = new Error(response.statusText);
99
error.response = response;
1010
throw error;
1111
}
12-
};
12+
}
1313

14-
const getLatestEntry = function(doc) {
15-
const regex = /^#{2} ?\[(v?[.\d]+)\]((?:[\s\S](?!^#{2}))+)/gm;
14+
function getLatestEntry(doc) {
15+
const regex = /^#{2} ?\[(.+)\]((?:[\s\S](?!^#{2}))+)/gm;
1616
const matches = doc.match(regex);
1717
return matches ? matches[0] : '';
18-
};
18+
}
1919

2020
export default TabRoute.extend({
2121
error: false,
2222

2323
model() {
24-
return fetch('https://raw.githubusercontent.com/emberjs/ember-inspector/master/CHANGELOG.md')
24+
let { version } = this.config;
25+
26+
let ref = (version.indexOf('alpha') === -1) ? `v${version}` : 'master';
27+
let url = `https://raw.githubusercontent.com/emberjs/ember-inspector/${encodeURIComponent(ref)}/CHANGELOG.md`;
28+
29+
return fetch(url)
2530
.then(checkStatus)
2631
.then((response) => response.text())
2732
.then((text) => getLatestEntry(text))

config/environment.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ module.exports = function(environment) {
88
environment,
99
rootURL: '',
1010
locationType: 'hash',
11+
version: packageJson.version,
1112
emberVersionsSupported: packageJson.emberVersionsSupported,
1213
previousEmberVersionsSupported: packageJson.previousEmberVersionsSupported,
1314
EmberENV: {

tests/acceptance/whats-new-test.js

Lines changed: 82 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,63 +3,121 @@ import { module, test } from 'qunit';
33
import { setupApplicationTest } from 'ember-qunit';
44
import Pretender from 'pretender';
55

6-
const CHANGELOG_URL = 'https://raw.githubusercontent.com/emberjs/ember-inspector/master/CHANGELOG.md';
7-
const CHANGELOG_RESPONSE = `
8-
# Changelog
6+
function urlFor(ref) {
7+
return `https://raw.githubusercontent.com/emberjs/ember-inspector/${encodeURIComponent(ref)}/CHANGELOG.md`;
8+
}
99

10+
function generateContent(master = false) {
11+
let content = [];
12+
13+
content.push(`# Changelog`);
14+
15+
if (master) {
16+
content.push(`
1017
## [Unreleased](https://github.com/emberjs/ember-inspector/tree/HEAD)
1118
1219
**Merged pull requests:**
1320
14-
- Stuff
21+
- Stuff`);
22+
}
1523

24+
content.push(`
1625
## [v3.3.0](https://github.com/emberjs/ember-inspector/tree/v3.3.0) (2018-08-02)
1726
1827
[Full Changelog](https://emberjs.com)
1928
2029
**Implemented enhancements:**
2130
31+
- Stuff
32+
2233
## [v3.2.0](https://github.com/emberjs/ember-inspector/tree/v3.2.0) (2018-07-03)
2334
2435
[Full Changelog](https://emberjs.com)
2536
2637
**Fixed bugs:**
2738
28-
- Data
29-
`;
39+
- Data`);
40+
41+
return content.join('\n');
42+
}
3043

31-
module('Whats New', function (hooks) {
32-
setupApplicationTest(hooks);
44+
module('Whats New', function(outer) {
45+
setupApplicationTest(outer);
46+
47+
outer.beforeEach(function() {
48+
this.config = this.owner.lookup('config:main');
49+
this.originalVersion = this.config.version;
50+
});
51+
52+
outer.afterEach(function() {
53+
this.config.version = this.originalVersion;
3354

34-
hooks.afterEach(function() {
3555
if (this.server) {
3656
this.server.shutdown();
3757
}
3858
});
3959

40-
test('Changelog is parsed and displayed', async function(assert) {
41-
this.server = new Pretender(function () {
42-
this.get(CHANGELOG_URL, () => [200, { 'Content-Type': 'text/plain' }, CHANGELOG_RESPONSE]);
60+
module('Released version', function(inner) {
61+
inner.beforeEach(function() {
62+
this.config.version = '3.3.0';
63+
});
64+
65+
test('Changelog is parsed and displayed', async function(assert) {
66+
this.server = new Pretender(function () {
67+
this.get(urlFor('v3.3.0'), () => [200, { 'Content-Type': 'text/plain' }, generateContent()]);
68+
});
69+
70+
await visit('/info/whats-new');
71+
72+
assert.dom('.whats-new h2').exists({ count: 1 }, 'correct section of markdown is rendered');
73+
74+
assert.equal(
75+
find('.whats-new h2 a').text,
76+
'v3.3.0',
77+
'correct section of markdown is rendered'
78+
);
4379
});
4480

45-
await visit('/info/whats-new');
81+
test('Error message is displayed on request failure', async function(assert) {
82+
this.server = new Pretender(function () {
83+
this.get(urlFor('v3.3.0'), () => [404, {}, '']);
84+
});
4685

47-
assert.dom('.whats-new h2').exists({ count: 1 }, 'correct section of markdown is rendered');
86+
await visit('/info/whats-new');
4887

49-
assert.equal(
50-
find('.whats-new h2 a').text,
51-
'v3.3.0',
52-
'correct section of markdown is rendered'
53-
);
88+
assert.dom('.whats-new p').exists({ count: 1 }, 'Changelog could not be loaded');
89+
});
5490
});
5591

56-
test('Error message is displayed on request failure', async function(assert) {
57-
this.server = new Pretender(function () {
58-
this.get(CHANGELOG_URL, () => [404, {}, '']);
92+
module('Nightly version', function(inner) {
93+
inner.beforeEach(function() {
94+
this.config.version = '3.4.0-alpha.1';
5995
});
6096

61-
await visit('/info/whats-new');
97+
test('Changelog is parsed and displayed', async function(assert) {
98+
this.server = new Pretender(function () {
99+
this.get(urlFor('master'), () => [200, { 'Content-Type': 'text/plain' }, generateContent(true)]);
100+
});
101+
102+
await visit('/info/whats-new');
103+
104+
assert.dom('.whats-new h2').exists({ count: 1 }, 'correct section of markdown is rendered');
62105

63-
assert.dom('.whats-new p').exists({ count: 1 }, 'Changelog could not be loaded');
106+
assert.equal(
107+
find('.whats-new h2 a').text,
108+
'Unreleased',
109+
'correct section of markdown is rendered'
110+
);
111+
});
112+
113+
test('Error message is displayed on request failure', async function(assert) {
114+
this.server = new Pretender(function () {
115+
this.get(urlFor('master'), () => [404, {}, '']);
116+
});
117+
118+
await visit('/info/whats-new');
119+
120+
assert.dom('.whats-new p').exists({ count: 1 }, 'Changelog could not be loaded');
121+
});
64122
});
65123
});

0 commit comments

Comments
 (0)