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

Conversation

vicb
Copy link
Contributor

@vicb vicb commented Mar 23, 2018

The commit command will fail if the commit message header does not follow the
Angular conventions as defined in /CONTRIBUTING.md.

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

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


The idea is to merge this one first and then I can work on the formatting hook to be merged after a few days (when we get feedback about how this one work for everybody).


Exemple output (success/fail)

$ git commit -m 'feat(compiler): blabla'
Found '/Users/berchet/Code/angular/.nvmrc' with version <8.9>
Now using node v8.9.4 (npm v5.6.0)
Found '/Users/berchet/Code/angular/.nvmrc' with version <8.9>
Now using node v8.9.4 (npm v5.6.0)
husky > npm run -s commitmsg (node v8.9.4)

[0323-checkMsgHook 214d6eb1c8] feat(compiler): blabla
 3 files changed, 55 insertions(+), 1 deletion(-)
 create mode 100644 scripts/git/commit-msg.js
$ git commit --amend -m 'sdfkjghfsdkj'
Found '/Users/berchet/Code/angular/.nvmrc' with version <8.9>
Now using node v8.9.4 (npm v5.6.0)
Found '/Users/berchet/Code/angular/.nvmrc' with version <8.9>
Now using node v8.9.4 (npm v5.6.0)
husky > npm run -s commitmsg (node v8.9.4)

INVALID COMMIT MSG: "sdfkjghfsdkj"
 => ERROR: The commit message does not match the format of '<type>(<scope>): <subject>' OR 'Revert: "type(<scope>): <subject>"'

husky > commit-msg hook failed (add --no-verify to bypass)

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.
@vicb vicb added action: review The PR is still awaiting reviews from at least one requested reviewer target: patch This PR is targeted for the next patch release labels Mar 23, 2018
Copy link
Contributor

@IgorMinar IgorMinar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good start. Thanks.

package.json Outdated
@@ -23,10 +23,12 @@
"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": "./scripts/git/commit-msg.js"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would that be ok on windows ?
do we need node ./scripts/git/commit-msg.js ?
@ocombe do you know ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't try it, but I am almost sure you need node 😁

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please @gkalpak it would really help to have someone confirms what works on win

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am afk until Sunday evening. I can confirm then (since you don't trust my "almost-sureness" 😛).

Copy link
Contributor

@ocombe ocombe Mar 26, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it doesn't work without node:

git commit -m "jlkjnljn"
husky > npm run -s commitmsg (node v8.9.2)

'.' n’est pas reconnu en tant que commande interne
ou externe, un programme exécutable ou un fichier de commandes.

husky > commit-msg hook failed (add --no-verify to bypass)

if I add node it works:

git commit -m "jlkjnljn"
husky > npm run -s commitmsg (node v8.9.2)

INVALID COMMIT MSG: "jlkjnljn"
 => ERROR: The commit message does not match the format of '<type>(<scope>): <subject>' OR 'Revert: "type(<scope>): <subject>"'

Check CONTRIBUTING.md at the root of the repo for more information.

husky > commit-msg hook failed (add --no-verify to bypass)

the good news is that it also works with GUI apps like git kraken, which is awesome :)

image

image

package.json Outdated
@@ -23,10 +23,12 @@
"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": "./scripts/git/commit-msg.js"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't try it, but I am almost sure you need node 😁

package.json Outdated
},
"dependencies": {
"core-js": "^2.4.1",
"husky": "^0.14.3",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be a devDependency?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep it should I thought It was there. (rant: why doesn't yarn understand --save-dev ???)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you should upgrade to husky rc because there are some bug in this version, and the new version have a separate config for hooks instead of config in script

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why doesn't yarn understand --save-dev

You have to speak in its language (--dev) if you want it to understand you 😛

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's what I ended up doing but obviously I did it wrong. But isn't it kind of stupid that --save-dev 1) is not understood 2) does not even print a warning ? Fragmentation sucks !

@vicb vicb added the action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews label Mar 24, 2018
@googlebot
Copy link

So there's good news and bad news.

👍 The good news is that everyone that needs to sign a CLA (the pull request submitter and all commit authors) have done so. Everything is all good there.

😕 The bad news is that it appears that one or more commits were authored by someone other than the pull request submitter. We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that here in the pull request.

Note to project maintainer: This is a terminal state, meaning the cla/google commit status will not change from this state. It's up to you to confirm consent of the commit author(s) and merge this pull request when appropriate.

@ocombe
Copy link
Contributor

ocombe commented Mar 26, 2018

I've updated the PR to add husky as a dev dep, and to add node in the script command.
(And it turns out that the script works with fixups!)

@ocombe ocombe added cla: yes and removed action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews cla: no labels Mar 26, 2018
@vicb vicb added action: merge The PR is ready for merge by the caretaker and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Mar 26, 2018
@ngbot
Copy link

ngbot bot commented Mar 26, 2018

I see that you just added the PR action: merge label, but the following checks are still failing:
    failure status "cla/google" is failing
    failure status "continuous-integration/travis-ci/pr" is failing

If you want your PR to be merged, it has to pass all the CI checks.

If you can't get the PR to a green state due to flakes or broken master, please try rebasing to master and/or restarting the CI job. If that fails and you believe that the issue is not due to your change, please contact the caretaker and ask for help.

@vicb
Copy link
Contributor Author

vicb commented Mar 26, 2018

Excellent Olivier, Thanks !!

@vicb vicb added the merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note label Mar 26, 2018
@vicb
Copy link
Contributor Author

vicb commented Mar 26, 2018

merge-assistance:

  • cla is ok (authors are @ocombe and myself)
  • travis failure is unrelated (just restarted the build to see if this helps)

@matsko matsko added target: major This PR is targeted for the next major release and removed target: patch This PR is targeted for the next patch release merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note labels Mar 26, 2018
@matsko matsko closed this in 7a406a3 Mar 26, 2018
@vicb vicb deleted the 0323-checkMsgHook branch August 3, 2018 19:07
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 13, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker cla: yes target: major This PR is targeted for the next major release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants