forked from tamiadev/semantic-release-tamia
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generateNotes.js
49 lines (40 loc) · 1.19 KB
/
generateNotes.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
'use strict';
const SRError = require('@semantic-release/error');
const gitLatestSemverTag = require('git-latest-semver-tag');
const commitsBetween = require('commits-between');
const indent = require('indent');
const isChangelog = require('./lib/util').isChangelog;
const isFix = commit => commit.startsWith('Fix:');
const highlightTag = text => text.replace(/^Fix:/, '**Fixed:**');
const formatListItem = text => '* ' + indent(text, 2).trim();
const asList = items => items.map(formatListItem).join('\n');
module.exports = (pluginConfig, config, cb) => {
gitLatestSemverTag((err, tag) => {
if (err) {
cb(new SRError(`Cannot get latest semver tag: ${err}`));
return;
}
commitsBetween({ from: tag })
.then(
commits => {
const lastCommit = commits[0];
// Last commit is a changelog commit
if (isChangelog(lastCommit.subject)) {
cb(null, lastCommit.body);
return;
}
// Patch release: just list all fixes
const fixes = commits
.map(commit => commit.subject)
.filter(isFix)
.map(highlightTag)
;
cb(null, asList(fixes));
},
err => {
cb(new SRError(`Cannot get commits list: ${err}`));
}
)
;
});
}