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
This commit is contained in:

committed by
Matias Niemelä

parent
bf6a416bce
commit
7a406a32fa
31
scripts/git/commit-msg.js
Executable file
31
scripts/git/commit-msg.js
Executable file
@ -0,0 +1,31 @@
|
||||
#! /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);
|
Reference in New Issue
Block a user