-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.picklogrc.js
63 lines (53 loc) · 1.77 KB
/
.picklogrc.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
const origin = 'https://[email protected]/BearJ/picklog';
const comparePath = `${origin}/compare/`;
const commitPath = `${origin}/commit/`;
module.exports = {
filters: [
{
name: 'Features',
regExp: /^feat(\(.*?\))?:\s/i,
},
{
name: 'Bugfixes',
regExp: /^fix(\(.*?\))?:\s/i,
},
{
name: 'Performance Improvements',
regExp: /^perf(\(.*?\))?:\s/i,
},
{
name: 'Reverts',
regExp: /^revert(\(.*?\))?:\s/i,
},
],
parse(commits) {
// RegExp.prototype.toJSON = RegExp.prototype.toString; // JSON.stringify会调用正则表达式的toJSON
// return JSON.stringify(commits, null, 2);
let output = '';
commits.forEach((log) => {
let date = new Date(log.timestamp * 1000);
date = `${date.getFullYear()}-${(`0${date.getMonth() + 1}`).substr(-2)}-${(`0${date.getDate()}`).substr(-2)}`;
let currentTag = log.tag || log.commits[0].h;
let prevTag = log.previousTag || log.commits[log.commits.length - 1].h;
output += `### [${currentTag}](${comparePath}${prevTag || ''}...${currentTag}) (${date})\n\n`;
log.results.forEach((result) => {
output += `#### ${result.filter.name}\n`;
result.commits.forEach((commit) => {
const { regExp } = result.filter;
let subject = commit.s.match(regExp) || '';
if (subject[1]) {
const type = subject[1].match(/\((.*?)\)/)[1];
subject = `**${type}:** ${commit.s.replace(regExp, '')}`;
} else {
subject = commit.s.replace(regExp, '');
}
output += `* ${subject}([${commit.h}](${commitPath}${commit.h}))\n`;
});
output += '\n';
});
output += '\n\n';
});
return output;
},
tagFilter: /^v\d+\.\d+\.\d+$/,
};