Files
Gereh/scripts/validate_commit.js
2026-08-13 20:00:11 +03:30

33 lines
833 B
JavaScript

#!/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));