angular-docs-cn/scripts/git/commit-msg.js
Victor Berchet 7a406a32fa refactor: add a commit-msg git hook to check commit messages (#22969)
The commit command will fail if the commit message header does not follow the
Angular convetions as defined in /CONTRIBUTING.md.

You can force the commit by adding the `--no-verify` option.

NOTE:
You should remove all unused hooks (in <angular>/.git/hooks) before running
`yarn` so that husky hooks are installed correctly.

PR Close #22969
2018-03-26 18:34:31 -04:00

31 lines
842 B
JavaScript
Executable File

#! /usr/bin/env node
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
// git commit-msg hook to check the commit message against Angular conventions
// see `/CONTRIBUTING.md` for mode details.
'use strict';
const fs = require('fs');
const checkMsg = require('../../tools/validate-commit-message');
const msgFile = process.env['GIT_PARAMS'];
let isValid = true;
if (msgFile) {
const commitMsg = fs.readFileSync(msgFile, {encoding: 'utf-8'});
const firstLine = commitMsg.split('\n')[0];
isValid = checkMsg(firstLine);
if (!isValid) {
console.error('\nCheck CONTRIBUTING.md at the root of the repo for more information.')
}
}
process.exit(isValid ? 0 : 1);