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

Documentation to work with commitlint? #122

Closed
radiosilence opened this issue Mar 24, 2020 · 10 comments
Closed

Documentation to work with commitlint? #122

radiosilence opened this issue Mar 24, 2020 · 10 comments

Comments

@radiosilence
Copy link

Unfortunately the commitlint documentation only has these instructions:

{
  "husky": {
    "hooks": {
      "commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
    }
  }
}

And it's unclear whether lefthook exposes whatever HUSKY_GIT_PARAMS are in such a way that it works with commitlint.

@Arkweid
Copy link
Collaborator

Arkweid commented Mar 25, 2020

Hi @radiosilence
It is impossible to store documentation for every tool in the world. Check the full guide and if you have a questions feel free to ask.

Maybe that what a you looking for?
https://github.com/Arkweid/lefthook/blob/master/docs/full_guide.md#bash-script-example

@muuvmuuv
Copy link

muuvmuuv commented May 5, 2020

I use it like this:

pre-commit:
  parallel: true
  commands:
    lint-commit:
      run: npx commitlint --from HEAD~1 --to HEAD

@tillsanders
Copy link

@muuvmuuv Somehow, this doesn't work for me. I also read, that the pre-commit hook should not work for this usecase. Apparently, the commit-msg hook should be used instead. Though this won't work for me as well :/

@tillsanders
Copy link

tillsanders commented Jun 13, 2020

@Arkweid I took a look at your example using the bash script. I'm trying to figure out how this could be used with a tool like commitlint without using a separate script file. Is there a way to access the commit message in the run command? Maybe using an environment variable or an argument?

@Arkweid
Copy link
Collaborator

Arkweid commented Jun 15, 2020

For simple run lefthook not pass arguments from git.
If you need just a commit message, so as a mentioned above you could use a various git commands like git show

@muuvmuuv
Copy link

Oh, sorry, noticed that my above does not work, but this one does:

commit-msg:
  commands:
    lint-commit-msg:
      run: npx commitlint --edit
  --edit, -e             read last commit message from the specified file or fallbacks to ./.git/COMMIT_EDITMSG

@paambaati
Copy link

paambaati commented Mar 3, 2021

I have a similar use-case with git-notify, where I need to pass Git parameters to post-merge, post-rewrite and post-checkout hooks, with the params being dynamic — https://github.com/jevakallio/git-notify#installing-hooks-by-any-other-means

Has someone had success doing this?

EDIT: I can see in https://github.com/Arkweid/lefthook/blob/master/docs/full_guide.md#git-hook-argument-shorthands-in-commands that a specific Git hook argument at position i can be accessed with {i}, but is there a way I can access all arguments?

@muuvmuuv
Copy link

muuvmuuv commented Mar 3, 2021

@paambaati where is this related to Commitlint? Post a new issue for this please.

@PawFV
Copy link

PawFV commented Jan 25, 2022

commit-msg:
  commands:
    lint-commit-msg:
      run: npx commitlint --edit

For me the above one was linting previous commit message instead of the current one.
After reading lefthooks for a while I solved doing the following.

run:

lefthook add -d commit-msg
# will create .lefthook/commit-msg dir

Inside .lefthook/commit-msg create a bash script called commit_check and add the following.

if ! npx commitlint --edit --verbose; then
    exit 1
fi

Then in lefthook.yml add the following

commit-msg:
  scripts:
    'commit_check':
      runner: bash

Ref: https://github.com/evilmartians/lefthook/blob/master/docs/full_guide.md#managing-scripts

@tenshiAMD
Copy link

I think we can close this since this guide already solved this issue.

@mrexox mrexox closed this as completed Sep 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants