Skip to content

Precommit docs #210

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

Merged
merged 4 commits into from
Jul 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ venv.bak/
# mypy
.mypy_cache/

.idea
.vscode/
*.bak

Expand Down
14 changes: 14 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,20 @@ or the shortcut
cz c
```

### Integrating with Pre-commit
Commitizen can lint your commit message for you with `cz check`.
You can integrate this in your [pre-commit](https://pre-commit.com/) config with:
```yaml
Copy link
Member

Choose a reason for hiding this comment

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

Adding this config file is not enough for pre-commit, I'd suggest add the pre-commit install --hook-type commit-msg command

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm. This already assumes that the dev has run pre-commit before tho. When I was trying this out for myself I just added that snippet to my config and reran pre-commit. I think the stages: [commit-msg] is enough.

Copy link
Member

Choose a reason for hiding this comment

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

By default commit-msg is not set for pre-commit. Simply adding these lines to your .pre-commit-config.yaml will not trigger pre-commit at commit-msg stage.

The following is how I test it.

e.g.,

mkdir test-project
cd test-project
git init
# add a .pre-commit-config.yaml without commitizen
git add .
git commit
pre-commit install
# add commitizen config to .pre-commit-config.yaml
git add .
git commit

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hey @Lee-W, just to follow up, you're right. It needs the pre-commit install --hook-type commit-msg command.

Copy link
Member

Choose a reason for hiding this comment

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

Ah, I miss this part when I merged this PR. No worries. I'll add it in another PR.

---
repos:
- repo: https://github.com/commitizen-tools/commitizen
rev: master
hooks:
- id: commitizen
stages: [commit-msg]
```
Read more about the `check` command [here](https://commitizen-tools.github.io/commitizen/check/).

### Help

```bash
Expand Down
16 changes: 8 additions & 8 deletions docs/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ If you're a first-time contributor, you can check the issues with [good first is

## Before making a pull request

1. Fork [the repository](https://github.com/commitizen-tools/commitizen)
2. Clone the repository from you GitHub
3. Setup development environment through [poetry](https://python-poetry.org/) (`poetry install`)
4. Check out a new branch and add your modification
5. Add test cases for all your changes
1. Fork [the repository](https://github.com/commitizen-tools/commitizen).
2. Clone the repository from your GitHub.
3. Setup development environment through [poetry](https://python-poetry.org/) (`poetry install`).
4. Check out a new branch and add your modification.
5. Add test cases for all your changes.
(We use [CodeCov](https://codecov.io/) to ensure our test coverage does not drop.)
6. Use [commitizen](https://github.com/commitizen-tools/commitizen) to do git commit
7. Run `./scripts/lint` and `./scripts/test` to ensure you follow the coding style and the tests pass
8. Update `READMD.md` and `CHANGELOG.md` for your changes
6. Use [commitizen](https://github.com/commitizen-tools/commitizen) to do git commit.
7. Run `./scripts/lint` and `./scripts/test` to ensure you follow the coding style and the tests pass.
8. Update `READMD.md` and `CHANGELOG.md` for your changes.
9. Send a [pull request](https://github.com/commitizen-tools/commitizen/pulls) 🙏