-
Notifications
You must be signed in to change notification settings - Fork 0
/
intershop-changelog.js
98 lines (87 loc) · 2.8 KB
/
intershop-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
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
'use strict';
var compareFunc = require('compare-func');
var Q = require('q');
var readFile = Q.denodeify(require('fs').readFile);
var resolve = require('path').resolve;
var parserOpts = {
headerPattern: /^(\w*)(?:\((.*)\))?: (.*)$/,
headerCorrespondence: ['type', 'scope', 'subject'],
noteKeywords: ['BREAKING CHANGE', 'BREAKING CHANGES'],
revertPattern: /^revert:\s([\s\S]*?)\s*This reverts commit (\w*)\./,
revertCorrespondence: ['header', 'hash'],
};
var writerOpts = {
transform: function (commit) {
var discard = true;
var issues = [];
commit.notes.forEach(note => {
note.title = 'BREAKING CHANGES';
discard = false;
});
if (commit.type === 'feat') {
commit.type = 'Features';
} else if (commit.type === 'fix') {
commit.type = 'Bug Fixes';
} else if (commit.type === 'perf') {
commit.type = 'Performance Improvements';
} else if (commit.type === 'docs') {
commit.type = 'Documentation';
} else if (discard) {
return;
} else if (commit.type === 'style') {
commit.type = 'Styles';
} else if (commit.type === 'refactor') {
commit.type = 'Code Refactoring';
} else if (commit.type === 'revert') {
commit.type = 'Reverts';
} else if (commit.type === 'test') {
commit.type = 'Tests';
} else if (commit.type === 'chore') {
commit.type = 'Chores';
}
if (commit.scope === '*') {
commit.scope = '';
}
if (typeof commit.hash === 'string') {
commit.hash = commit.hash.substring(0, 7);
}
// remove references that already appear in the subject
commit.references = commit.references.filter(reference => {
if (issues.indexOf(reference.issue) === -1) {
return true;
}
return false;
});
return commit;
},
groupBy: 'type',
commitGroupsSort: function (arg1, arg2) {
var order = ['Features', 'Bug Fixes', 'Performance Improvements', 'Documentation', 'Code Refactoring'];
if (order.indexOf(arg1.title) < order.indexOf(arg2.title)) {
return -1;
}
if (order.indexOf(arg1.title) > order.indexOf(arg2.title)) {
return 1;
}
return 0;
},
commitsSort: ['scope'],
noteGroupsSort: 'title',
notesSort: compareFunc,
};
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'),
readFile(resolve(__dirname, 'templates/footer.hbs'), 'utf-8'),
]).spread((template, header, commit, footer) => {
writerOpts.mainTemplate = template;
writerOpts.headerPartial = header;
writerOpts.commitPartial = commit;
writerOpts.footerPartial = footer;
return {
gitRawCommitsOpts: { merges: null },
parserOpts: parserOpts,
writerOpts: writerOpts,
};
});