Skip to content

Commit 881211b

Browse files
vikaspotluri123acburdine
authored andcommitted
fix(release-notes): add support for 4.x+ tag names
1 parent f0effa2 commit 881211b

File tree

2 files changed

+71
-2
lines changed

2 files changed

+71
-2
lines changed

lib/tasks/release-notes.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ module.exports = async (ctx, task) => {
33
let response;
44

55
try {
6-
response = await got('https://api.github.com/repos/TryGhost/Ghost/releases', {json: true, timeout: 5000});
6+
response = await got.get('https://api.github.com/repos/TryGhost/Ghost/releases', {json: true, timeout: 5000});
77
} catch (err) {
88
task.title = 'Unable to fetch release notes';
99
return;
1010
}
1111

12-
const relevantNotes = response.body.filter(note => note.tag_name === ctx.version)[0];
12+
const relevantNotes = response.body.filter(note => note.tag_name.replace('v', '') === ctx.version)[0];
1313

1414
if (!relevantNotes) {
1515
task.title = 'Release notes were not found';

test/unit/tasks/release-notes-spec.js

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
const {expect} = require('chai');
2+
const sinon = require('sinon');
3+
const got = require('got');
4+
5+
const runTask = require('../../../lib/tasks/release-notes');
6+
7+
const stubbedGithubResponseWithRelevantFields = () => [{
8+
tag_name: 'v4.0.1',
9+
body: '4.0.1 release notes'
10+
}, {
11+
tag_name: '3.42.2',
12+
body: '3.42.2 release notes'
13+
}];
14+
15+
describe('Unit: Tasks > Release Notes', function () {
16+
afterEach(function () {
17+
sinon.restore();
18+
});
19+
20+
it('Discovers releases for < 4.x', async function () {
21+
const stub = sinon.stub(got, 'get').resolves({body: stubbedGithubResponseWithRelevantFields()});
22+
const task = {title: 'original'};
23+
const ui = {log: sinon.stub()};
24+
const context = {ui, version: '3.42.2'};
25+
26+
await runTask(context, task);
27+
28+
expect(stub.calledOnce).to.be.true;
29+
expect(task.title).to.equal('Fetched release notes');
30+
expect(ui.log.args[0]).to.deep.equal(['\n3.42.2 release notes\n', 'green']);
31+
});
32+
33+
it('Discovers release for >= 4.x', async function () {
34+
const stub = sinon.stub(got, 'get').resolves({body: stubbedGithubResponseWithRelevantFields()});
35+
const task = {title: 'original'};
36+
const ui = {log: sinon.stub()};
37+
const context = {ui, version: '4.0.1'};
38+
39+
await runTask(context, task);
40+
41+
expect(stub.calledOnce).to.be.true;
42+
expect(task.title).to.equal('Fetched release notes');
43+
expect(ui.log.args[0]).to.deep.equal(['\n4.0.1 release notes\n', 'green']);
44+
});
45+
46+
it('Complains when there are no release notes', async function () {
47+
const stub = sinon.stub(got, 'get').resolves({body: stubbedGithubResponseWithRelevantFields()});
48+
const task = {title: 'original'};
49+
const ui = {log: sinon.stub()};
50+
const context = {ui, version: '3.14.15'};
51+
52+
await runTask(context, task);
53+
54+
expect(stub.calledOnce).to.be.true;
55+
expect(task.title).to.equal('Release notes were not found');
56+
});
57+
58+
it('Handles network errors', async function () {
59+
const stub = sinon.stub(got, 'get').rejects(new Error('What is this "GitHub" you speak of?'));
60+
const task = {title: 'original'};
61+
const ui = {log: sinon.stub()};
62+
const context = {ui, version: '3.14.15'};
63+
64+
await runTask(context, task);
65+
66+
expect(stub.calledOnce).to.be.true;
67+
expect(task.title).to.equal('Unable to fetch release notes');
68+
});
69+
});

0 commit comments

Comments
 (0)