-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathauto-changelog.js
37 lines (34 loc) · 1.04 KB
/
auto-changelog.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
module.exports = function (Handlebars) {
Handlebars.registerHelper('custom', function (context, extra, options) {
if ((!context || context.length === 0) && (!extra || extra.length === 0)) {
return '';
}
const list = [...context, ...extra]
.filter(item => {
const commit = item.commit || item;
if (options.hash.exclude) {
const pattern = new RegExp(options.hash.exclude, 'm');
if (pattern.test(commit.message)) {
return false;
}
}
if (options.hash.message) {
const pattern = new RegExp(options.hash.message, 'm');
return pattern.test(commit.message);
}
if (options.hash.subject) {
const pattern = new RegExp(options.hash.subject);
return pattern.test(commit.subject);
}
return true;
})
.map(item => options.fn(item))
.join('');
if (!list) {
return '';
}
return options.hash.heading
? `${options.hash.heading}\n\n${list}`
: `${list}`;
});
};