-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
42 lines (34 loc) · 1.25 KB
/
index.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
const path = require('path');
const colors = require('colors');
const receivedArguments = process.argv.slice(2);
const [localRef, commitId, gitHookDirectory, commitMsg] = receivedArguments;
const projectDirectory = gitHookDirectory.replace(/\.git\/hooks$/, '');
const defaults = require('./defaults');
let packageJson;
try {
packageJson = require(path.join(projectDirectory, 'package.json'));
} catch (e) {
console.log(defaults.errorWhileParsingPackageJson, e);
process.exit(1);
}
let config = packageJson['pre-push-commit-naming-enforcement'] || {};
function getConfFromKey(key)
{
return (config[key] !== undefined) ? config[key] : defaults[key];
}
/* pre-push module is disabled, we stop right there */
if( !getConfFromKey("enabled") )
{
console.log(getConfFromKey("enabled"));
process.exit(0);
}
let [, title, body] = new RegExp(getConfFromKey("regexToSeparateTitleAndBody")).exec(commitMsg);
if(new RegExp(getConfFromKey("regexToCheckTitle")).exec(title) === null)
{
console.log(defaults.titleNotCorresponding.red);
console.log(`Involved branch : ${localRef}`.yellow);
console.log(`Involved commit id : ${commitId}`.yellow);
console.log(`Involved commit title : ${title}`.underline.yellow);
process.exit(1);
}
process.exit(0);