Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: add a commit-msg git hook to check commit messages #22969

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion package.json
Expand Up @@ -23,7 +23,8 @@
"preinstall": "node tools/yarn/check-yarn.js",
"postinstall": "yarn update-webdriver && node ./tools/postinstall-patches.js",
"update-webdriver": "webdriver-manager update --gecko false $CHROMEDRIVER_VERSION_ARG",
"check-env": "gulp check-env"
"check-env": "gulp check-env",
"commitmsg": "node ./scripts/git/commit-msg.js"
},
"dependencies": {
"core-js": "^2.4.1",
Expand Down Expand Up @@ -79,6 +80,7 @@
"gulp-conventional-changelog": "1.1.0",
"gulp-tslint": "8.1.2",
"hammerjs": "2.0.8",
"husky": "^0.14.3",
"incremental-dom": "0.4.1",
"jasmine": "2.4.1",
"jasmine-core": "2.4.1",
Expand Down
31 changes: 31 additions & 0 deletions scripts/git/commit-msg.js
@@ -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);
26 changes: 26 additions & 0 deletions yarn.lock
Expand Up @@ -855,6 +855,10 @@ chokidar@1.7.0, chokidar@^1.0.0, chokidar@^1.4.1:
optionalDependencies:
fsevents "^1.0.0"

ci-info@^1.0.0:
version "1.1.3"
resolved "https://registry.yarnpkg.com/ci-info/-/ci-info-1.1.3.tgz#710193264bb05c77b8c90d02f5aaf22216a667b2"

clang-format@1.0.41:
version "1.0.41"
resolved "https://registry.yarnpkg.com/clang-format/-/clang-format-1.0.41.tgz#28552e50b0c9e44d23f85aebe3d2fbd06c93620c"
Expand Down Expand Up @@ -2854,6 +2858,14 @@ https-proxy-agent@^1.0.0:
debug "2"
extend "3"

husky@^0.14.3:
version "0.14.3"
resolved "https://registry.yarnpkg.com/husky/-/husky-0.14.3.tgz#c69ed74e2d2779769a17ba8399b54ce0b63c12c3"
dependencies:
is-ci "^1.0.10"
normalize-path "^1.0.0"
strip-indent "^2.0.0"

iconv-lite@0.4.11:
version "0.4.11"
resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.4.11.tgz#2ecb42fd294744922209a2e7c404dac8793d8ade"
Expand Down Expand Up @@ -2960,6 +2972,12 @@ is-callable@^1.1.1, is-callable@^1.1.3:
version "1.1.3"
resolved "https://registry.yarnpkg.com/is-callable/-/is-callable-1.1.3.tgz#86eb75392805ddc33af71c92a0eedf74ee7604b2"

is-ci@^1.0.10:
version "1.1.0"
resolved "https://registry.yarnpkg.com/is-ci/-/is-ci-1.1.0.tgz#247e4162e7860cebbdaf30b774d6b0ac7dcfe7a5"
dependencies:
ci-info "^1.0.0"

is-date-object@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/is-date-object/-/is-date-object-1.0.1.tgz#9aa20eb6aeebbff77fbd33e74ca01b33581d3a16"
Expand Down Expand Up @@ -4136,6 +4154,10 @@ normalize-package-data@^2.3.0, normalize-package-data@^2.3.2, normalize-package-
semver "2 || 3 || 4 || 5"
validate-npm-package-license "^3.0.1"

normalize-path@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/normalize-path/-/normalize-path-1.0.0.tgz#32d0e472f91ff345701c15a8311018d3b0a90379"

normalize-path@^2.0.0, normalize-path@^2.0.1:
version "2.1.1"
resolved "https://registry.yarnpkg.com/normalize-path/-/normalize-path-2.1.1.tgz#1ab28b556e198363a8c1a6f7e6fa20137fe6aed9"
Expand Down Expand Up @@ -5577,6 +5599,10 @@ strip-indent@^1.0.1:
dependencies:
get-stdin "^4.0.1"

strip-indent@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/strip-indent/-/strip-indent-2.0.0.tgz#5ef8db295d01e6ed6cbf7aab96998d7822527b68"

strip-json-comments@~2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/strip-json-comments/-/strip-json-comments-2.0.1.tgz#3c531942e908c2697c0ec344858c286c7ca0a60a"
Expand Down