-
Notifications
You must be signed in to change notification settings - Fork 111
Expand file tree
/
Copy pathformatCommitMessage.js
More file actions
67 lines (48 loc) · 1.73 KB
/
Copy pathformatCommitMessage.js
File metadata and controls
67 lines (48 loc) · 1.73 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
/* eslint-disable complexity */
const wrap = require('word-wrap');
const MAX_LINE_WIDTH = 72;
const makeAffectsLine = function (answers) {
const selectedPackages = answers.packages;
if (selectedPackages && selectedPackages.length) {
return `\naffects: ${selectedPackages.join(', ')}`;
}
return '';
};
const formatCommitMessage = (state) => {
const {config, answers} = state;
const wrapOptions = {
indent: '',
trim: true,
width: MAX_LINE_WIDTH
};
const emoji = config.types[answers.type].emoji;
const scope = answers.scope ? '(' + answers.scope.trim() + ')' : '';
const subject = answers.subject.trim();
const type = answers.type;
const format = config.format || '{type}{scope}: {emoji}{subject}';
const affectsLine = makeAffectsLine(answers);
// Wrap these lines at MAX_LINE_WIDTH character
const body = wrap((answers.body || '') + affectsLine, wrapOptions);
const breaking = wrap(answers.breaking, wrapOptions);
const issues = wrap(answers.issues, wrapOptions);
// @note(emoji) Add space after emoji (breakingChangePrefix/closedIssueEmoji)
const head = format
.replace(/\{emoji\}/g, config.disableEmoji ? '' : emoji + ' ')
.replace(/\{scope\}/g, scope)
.replace(/\{subject\}/g, subject)
.replace(/\{type\}/g, type);
let msg = head;
if (body) {
msg += '\n\n' + body;
}
if (breaking) {
const breakingEmoji = config.disableEmoji ? '' : config.breakingChangePrefix;
msg += '\n\nBREAKING CHANGE: ' + breakingEmoji + breaking;
}
if (issues) {
const closedIssueEmoji = config.disableEmoji ? '' : config.closedIssuePrefix;
msg += '\n\n' + closedIssueEmoji + config.closedIssueMessage + issues;
}
return msg;
};
module.exports = formatCommitMessage;