qiskit.org icon indicating copy to clipboard operation
qiskit.org copied to clipboard

Setup commitlint

Open eddybrando opened this issue 4 years ago • 6 comments

commitlint checks if your commit messages meet the conventional commit format.

It's a suggested add-on in newer Nuxt versions.

eddybrando avatar Aug 13 '21 21:08 eddybrando

This is not decoration. It is not related to aesthetics. I think this could be code-quality

korgan00 avatar Aug 23 '21 10:08 korgan00

I'm going to do the best I can with this. However, commitlint relies on hooks to enforce the commit message meets the format criteria. Specifically, it relies on the commit-msg hook.

Typically, this would be enforced either by the developer manually adding the hook to their development environment (no guarantee it'll be followed), or by using a hook library like Husky.

  • One can't easily use their own Git Hook templates or manually-added hooks, along with Husky.

I recommend Husky, since it's a vetted library that's widely used. However, I can at least provide the configuration files in a PR for now.

shmolf avatar Oct 02 '21 18:10 shmolf

I'd like to ask... why use commitlint to enforce the format? What tools are leveraging it?

I ask, because I myself do use semantic-release to auto-tag my repo, and auto-generate my Changelog file.

Semantic Release relies on reading in commit messages written in a standard format, such as conventional commit, among others.

shmolf avatar Oct 02 '21 18:10 shmolf

I'm going to do the best I can with this. However, commitlint relies on hooks to enforce the commit message meets the format criteria. Specifically, it relies on the commit-msg hook.

Typically, this would be enforced either by the developer manually adding the hook to their development environment (no guarantee it'll be followed), or by using a hook library like Husky.

  • One can't easily use their own Git Hook templates or manually-added hooks, along with Husky.

I recommend Husky, since it's a vetted library that's widely used. However, I can at least provide the configuration files in a PR for now.

Git Hooks

We can either ask devs to create a commit-msg git hook via

mkdir -p .git/hooks/ && \
echo '#!/bin/sh
npx --no-install commitlint --edit \"$1\"' > .git\hooks\commit-msg

Side note: On windows, I ran into an error when I tried to commit.

SyntaxError: Invalid or unexpected token
...

This was because the file was created in UTF-16 BE encoding. It should be saved as UTF-8.

Husky

Install husky:

npm i -D husky

Then, we run husky's install command and set up the commit-msg hook.

npx husky install && npx husky add .husky/commit-msg 'npx --no-install commitlint --edit "$1"'

If you read the output, it should recommend installing pinst as well, and add some additional package.json scripts.

npm i -D pinst

And add to the package.json

  "scripts": {
    "postinstall": "husky install",
    "prepublishOnly": "pinst --disable",
    "postpublish": "pinst --enable"
  },


I can include any Husky stuff as part of the Pull Request, if that's the right decided.

shmolf avatar Oct 02 '21 21:10 shmolf

Thanks a lot @shmolf for the help!

We're currently awaiting the results of an internal discussion about the purpose of enforcing a certain structure in our commit messages.

eddybrando avatar Oct 26 '21 12:10 eddybrando

Thanks a lot @shmolf for the help!

We're currently awaiting the results of an internal discussion about the purpose of enforcing a certain structure in our commit messages.

It's not an easy decision, especially if there's already a current practice by devs to use their own hooks, or other concerns. If you have any questions, please feel free to ask.

shmolf avatar Oct 26 '21 13:10 shmolf

We didn't see the need as a team to setup commitlint.

eddybrando avatar Jul 28 '23 11:07 eddybrando