Initial commit
This commit is contained in:
32
scripts/validate_commit.js
Normal file
32
scripts/validate_commit.js
Normal file
@@ -0,0 +1,32 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
const fs = require('fs');
|
||||
const chalk = require('chalk');
|
||||
const validate = require('@openware/coding-standards/dist').isCommitMsgValid;
|
||||
|
||||
const main = argv => {
|
||||
const msgFile = process.env.HUSKY_GIT_PARAMS || argv[2];
|
||||
if (!msgFile) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
const lines = fs.readFileSync(msgFile).toString()
|
||||
.split('\n')
|
||||
.map(x => x.trim())
|
||||
.filter(x => x.length !== 0 && !x.startsWith('#') && !x.startsWith('Co-authored-by:'));
|
||||
|
||||
for (line of lines) {
|
||||
const { right } = validate(line);
|
||||
if (right) {
|
||||
console.error(`
|
||||
${chalk.red(right)}: ${line}
|
||||
|
||||
Please read the commit message guidelines: ${chalk.blue.bold('http://chris.beams.io/posts/git-commit/')}
|
||||
`);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
};
|
||||
|
||||
process.exit(main(process.argv));
|
||||
Reference in New Issue
Block a user