Skip to content

Commit 898a762

Browse files
daniellockyeracburdine
authored andcommitted
feat(update): display release notes when updating Ghost
closes #1338 - we want to be able to display the release notes so we can inform users about new features - this commit adds a task to the update task which will query GitHub for the release notes and display them
1 parent 1194dbc commit 898a762

File tree

3 files changed

+40
-5
lines changed

3 files changed

+40
-5
lines changed

lib/commands/update.js

+4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class UpdateCommand extends Command {
2121
const MigrateCommand = require('./migrate');
2222
const migrator = require('../tasks/migrator');
2323
const majorUpdate = require('../tasks/major-update');
24+
const releaseNotes = require('../tasks/release-notes');
2425

2526
const instance = this.system.getInstance();
2627

@@ -70,6 +71,9 @@ class UpdateCommand extends Command {
7071

7172
// TODO: add meaningful update checks after this task
7273
const tasks = [{
74+
title: 'Fetching release notes',
75+
task: releaseNotes
76+
}, {
7377
title: 'Downloading and updating Ghost',
7478
skip: ({rollback}) => rollback,
7579
task: this.downloadAndUpdate

lib/tasks/release-notes.js

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
module.exports = async (ctx, task) => {
2+
const got = require('got');
3+
let response;
4+
5+
try {
6+
response = await got('https://api.github.com/repos/TryGhost/Ghost/releases', {json: true});
7+
} catch (err) {
8+
task.title = 'Unable to fetch release notes';
9+
return;
10+
}
11+
12+
const relevantNotes = response.body.filter(note => note.tag_name === ctx.version)[0];
13+
14+
if (!relevantNotes) {
15+
task.title = 'Release notes were not found';
16+
return;
17+
}
18+
19+
task.title = 'Fetched release notes';
20+
ctx.ui.log(`\n${relevantNotes.body}\n`, 'green');
21+
};

test/unit/commands/update-spec.js

+15-5
Original file line numberDiff line numberDiff line change
@@ -191,11 +191,13 @@ describe('Unit: Commands > Update', function () {
191191
rollback: sinon.stub().resolves()
192192
};
193193

194+
const releaseNotesStub = sinon.stub().resolves();
194195
const majorUpdateStub = sinon.stub();
195196

196197
const UpdateCommand = proxyquire(modulePath, {
197198
'../tasks/migrator': migratorStub,
198-
'../tasks/major-update': majorUpdateStub
199+
'../tasks/major-update': majorUpdateStub,
200+
'../tasks/release-notes': releaseNotesStub
199201
});
200202

201203
const ghostConfig = configStub();
@@ -262,11 +264,13 @@ describe('Unit: Commands > Update', function () {
262264
rollback: sinon.stub().resolves()
263265
};
264266

267+
const releaseNotesStub = sinon.stub().resolves();
265268
const majorUpdateStub = sinon.stub();
266269

267270
const UpdateCommand = proxyquire(modulePath, {
268271
'../tasks/migrator': migratorStub,
269-
'../tasks/major-update': majorUpdateStub
272+
'../tasks/major-update': majorUpdateStub,
273+
'../tasks/release-notes': releaseNotesStub
270274
});
271275

272276
const ghostConfig = configStub();
@@ -435,11 +439,13 @@ describe('Unit: Commands > Update', function () {
435439
rollback: sinon.stub().resolves()
436440
};
437441

442+
const releaseNotesStub = sinon.stub().resolves();
438443
const majorUpdateStub = sinon.stub();
439444

440445
const UpdateCommand = proxyquire(modulePath, {
441446
'../tasks/migrator': migratorStub,
442-
'../tasks/major-update': majorUpdateStub
447+
'../tasks/major-update': majorUpdateStub,
448+
'../tasks/release-notes': releaseNotesStub
443449
});
444450

445451
const ui = {log: sinon.stub(), listr: sinon.stub(), run: sinon.stub()};
@@ -490,11 +496,13 @@ describe('Unit: Commands > Update', function () {
490496
migrate: sinon.stub().resolves(),
491497
rollback: sinon.stub().resolves()
492498
};
499+
const releaseNotesStub = sinon.stub().resolves();
493500
const majorUpdateStub = sinon.stub();
494501

495502
const UpdateCommand = proxyquire(modulePath, {
496503
'../tasks/migrator': migratorStub,
497-
'../tasks/major-update': majorUpdateStub
504+
'../tasks/major-update': majorUpdateStub,
505+
'../tasks/release-notes': releaseNotesStub
498506
});
499507

500508
const config = configStub();
@@ -561,8 +569,10 @@ describe('Unit: Commands > Update', function () {
561569
migrate: sinon.stub().resolves(),
562570
rollback: sinon.stub().resolves()
563571
};
572+
const releaseNotesStub = sinon.stub().resolves();
564573
const UpdateCommand = proxyquire(modulePath, {
565-
'../tasks/migrator': migratorStub
574+
'../tasks/migrator': migratorStub,
575+
'../tasks/release-notes': releaseNotesStub
566576
});
567577
const ui = {log: sinon.stub(), listr: sinon.stub(), run: sinon.stub()};
568578
const system = {getInstance: sinon.stub()};

0 commit comments

Comments
 (0)