-
-
Notifications
You must be signed in to change notification settings - Fork 483
Expand file tree
/
Copy path.auto-changelog-helpers.js
More file actions
77 lines (65 loc) 路 2.29 KB
/
Copy path.auto-changelog-helpers.js
File metadata and controls
77 lines (65 loc) 路 2.29 KB
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
module.exports = function (Handlebars) {
Handlebars.registerHelper('normalize', function (commits, merges, fixes) {
const result = [];
function add(item) {
if (!item) return;
const c = item.commit || item;
result.push({
subject: c.subject || item.subject || item.message || '',
message: c.message || c.subject || item.message || '',
author: item.author || c.author || '',
shorthash: item.shorthash || c.shorthash || '',
href: item.href || c.href || '',
breaking: !!(item.breaking || c.breaking),
});
}
(commits || []).forEach(add);
(merges || []).forEach(add);
(fixes || []).forEach(add);
return result;
});
Handlebars.registerHelper('features', function (commits) {
if (!commits) return [];
return commits.filter((c) => /^feat[(:]/.test(c.message));
});
Handlebars.registerHelper('fixes', function (commits) {
if (!commits) return [];
return commits.filter((c) => /^[fF]ix[(:\s]/.test(c.message));
});
Handlebars.registerHelper('deps', function (commits) {
if (!commits) return [];
return commits.filter((c) => c.message.startsWith('chore(deps'));
});
Handlebars.registerHelper('chores', function (commits) {
if (!commits) return [];
return commits.filter(
(c) => /^chore[(:]/.test(c.message) && !c.message.startsWith('chore(deps')
);
});
Handlebars.registerHelper('docs', function (commits) {
if (!commits) return [];
return commits.filter((c) => /^docs[(:]/.test(c.message));
});
Handlebars.registerHelper('refactor', function (commits) {
if (!commits) return [];
return commits.filter((c) => /^refactor[(:]/.test(c.message));
});
Handlebars.registerHelper('formatAuthor', function (author) {
if (!author) return '';
if (/^[a-z0-9[\]()._/-]+$/.test(author)) {
return '@' + author;
}
return author;
});
Handlebars.registerHelper('formatDate', function (date) {
if (!date) return '';
const match = date.match(/^(\d{4}-\d{2}-\d{2})/);
return match ? match[1] : date;
});
Handlebars.registerHelper('others', function (commits) {
if (!commits) return [];
return commits.filter(
(c) => !/^(feat|fix|chore|docs|refactor|test|style|perf|ci|build|revert)[(:]/.test(c.message)
);
});
};