-
Notifications
You must be signed in to change notification settings - Fork 0
/
commit-msg
executable file
·53 lines (41 loc) · 1.32 KB
/
commit-msg
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
#!/usr/bin/env node
'use strict';
var fs = require('fs');
module.exports.validateCommitMessage = (message) => {
let errorCode = 0;
let lines = message.split('\n');
let line = lines.shift();
if (!line) {
return errorCode;
}
if (line.length > 72) {
console.error(`Commit message title is ${line.length} characters long; Limit it to 72 characters`);
errorCode = 1;
}
if (!/^[A-Z]/.test(line)) {
console.error('Capitalize the commit message');
errorCode = 1;
}
if ('.' === line.slice(-1)) {
console.error('Do not end the commit message with a period');
errorCode = 1;
}
line = lines.shift();
if (line && line.length > 0) {
console.error('Second commit message line is not empty');
errorCode = 1;
}
lines.some((line) => {
if (line === '# ------------------------ >8 ------------------------') {
return true;
}
if (line && line.charAt(0) !== '#' && line.length > 72) {
console.error(`Commit message body line is ${line.length} characters long; Limit it to 72 characters`);
errorCode = 1;
}
});
return errorCode;
};
fs.readFile(process.argv[2], (_, buffer) => {
process.exit(module.exports.validateCommitMessage(buffer.toString()));
});