-
Notifications
You must be signed in to change notification settings - Fork 1
/
writer-opts.js
71 lines (61 loc) · 1.91 KB
/
writer-opts.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
const Q = require('q');
const readFile = Q.denodeify(require('fs').readFile);
const resolve = require('path').resolve;
function getCommitGroup(type) {
switch (type) {
case 'breaking':
case 'major':
return 'Breaking Changes';
case 'feat':
case 'feature':
case 'minor':
return 'New Features';
default:
return 'Other Changes';
}
}
function getWriterOpts() {
return {
transform: (commit) => {
if (!commit.type) {
commit.type = 'patch';
}
commit.group = getCommitGroup(commit.type);
// Parse the issue number from the commit message.
// This assumes (by convention) Jira issue numbers.
const issue = commit.subject.match(/^[A-Z0-9]+-\d+/);
if (issue) {
commit.issue = issue[0];
}
// Parse the prose from the commit message.
const message = commit.subject.match(/: (.*)/);
if (message) {
// Remove the trailing version qualifier keyword in parenthesis.
commit.message = message[1].replace(/( )*\((major|minor|patch|breaking|feat|feature|fix)\)/, '');
}
if (!commit.message || commit.message.match(/Merge pull request #\d*/)) {
// Don't consider merge commits – the underlying commits will each be evaluated.
return;
}
return commit;
},
groupBy: 'group',
commitGroupsSort: 'title',
commitsSort: ['type', 'message'],
parserOpts: {
headerPattern: /.*:(.*)\(*/,
},
};
}
module.exports = Q.all([
readFile(resolve(__dirname, './templates/template.hbs'), 'utf-8'),
readFile(resolve(__dirname, './templates/header.hbs'), 'utf-8'),
readFile(resolve(__dirname, './templates/commit.hbs'), 'utf-8'),
])
.spread((template, header, commit) => {
const writerOpts = getWriterOpts();
writerOpts.mainTemplate = template;
writerOpts.headerPartial = header;
writerOpts.commitPartial = commit;
return writerOpts;
});