-
Notifications
You must be signed in to change notification settings - Fork 2
/
notes.js
101 lines (83 loc) · 2.42 KB
/
notes.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
99
100
101
'use strict';
const dateformat = require('dateformat');
const parseUrl = require('github-url-from-git');
const util = require('./lib/util');
const fs = require('fs');
const path = require('path');
const merge = /^Merge /;
module.exports = (pluginConfig, info, cb) => {
let notes = '';
const repository = info.pkg.repository ? parseUrl(info.pkg.repository.url) : null;
const pkg = info.pkg;
const commits = info.commits ? info.commits : JSON.parse(fs.readFileSync(path.join(process.cwd(), '.semantic-commits.json')).toString());
const changes = {
new: [],
changed: [],
leftover: [],
breaking: [],
};
notes += `## ${pkg.version}\n`;
notes += `**${dateformat(new Date(), 'mmmm dd, yyyy')}**\n\n`;
commits.forEach(commit => {
// Get Emoji
const emoji = util.getEmoji(commit.message) || [];
const message = commit.message.trim().split('\n').filter(msg => {
if (msg === '') {
return false;
}
return true;
});
let msg = '';
if (!merge.test(commit.message)) {
// Add Message
msg = `* ${message[0].trim()}`;
// Add Link to Commit.
if (repository !== null) {
msg += ` ([commit](${repository}/commit/${commit.hash}))`;
}
// Add sub-messages as sub-bullets
if (message.length > 1) {
message.shift();
message.forEach(submsg => {
msg += `\n * ${submsg}`;
});
}
// Determine which section to add message to
if (msg.indexOf(':boom:') !== -1) {
changes.breaking.push(msg);
}
else if (msg.indexOf(':new:') >= 0 || msg.indexOf(':racehorse:') >= 0 || msg.indexOf(':lock:') >= 0) {
changes.new.push(msg);
}
else if (emoji.length) {
changes.changed.push(msg);
}
else {
changes.leftover.push(msg);
}
}
});
// Write out messages
if (changes.breaking.length) {
notes += '**Breaking Changes**\n\n';
notes += changes.breaking.join('\n');
notes += '\n\n';
}
if (changes.new.length) {
notes += '**New**\n\n';
notes += changes.new.join('\n');
notes += '\n\n';
}
if (changes.changed.length || changes.leftover.length) {
notes += '**Changed**\n\n';
if (changes.changed.length) {
notes += changes.changed.join('\n');
}
notes += '\n';
if (changes.leftover.length) {
notes += changes.leftover.join('\n');
}
notes += '\n';
}
cb(null, notes);
};