Skip to content

Commit 0f27e2d

Browse files
ci(pre-commit): add gitlint hook for commit message validation
- Add gitlint hook to .pre-commit-config.yaml on commit-msg stage - Update CONTRIBUTING.md to document both pre-commit hook installation commands - Clarify that commit-msg hook is required for gitlint validation Signed-off-by: Mustafa Kaptan <[email protected]>
1 parent 51c1bc6 commit 0f27e2d

File tree

2 files changed

+61
-6
lines changed

2 files changed

+61
-6
lines changed

.pre-commit-config.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,8 @@ repos:
2323
- id: ruff
2424
args: [--fix]
2525
- id: ruff-format
26+
- repo: https://github.com/jorisroovers/gitlint
27+
rev: v0.19.1
28+
hooks:
29+
- id: gitlint
30+
stages: [commit-msg]

CONTRIBUTING.md

Lines changed: 56 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,19 @@ The rest of this document assumes you are in the virtual environment by either a
4848
4949
### Pre-Commit-Hooks
5050
51-
Pre commit hooks can be setup with:
51+
Pre-commit hooks can be set up with:
5252
5353
```bash
5454
pre-commit install
55+
pre-commit install --hook-type commit-msg
5556
```
5657
58+
The first command installs hooks that run before commits (code formatting, linting, etc.).
59+
The second command installs the `commit-msg` hook that validates commit messages using gitlint.
60+
61+
> [!NOTE]
62+
> Both hooks are required: the first validates your code, the second enforces conventional commit message standards as described in the [Commit Message Enforcement](#commit-message-enforcement) section.
63+
5764
### Tests
5865

5966
Run tests with the following command:
@@ -121,6 +128,23 @@ We use [**gitlint**](https://github.com/jorisroovers/gitlint) to enforce convent
121128
- Custom title length limits (5-100 characters)
122129
- Ignores GitHub Actions bot commits
123130

131+
> [!TIP]
132+
> **Recovering failed commit messages**: If gitlint rejects your commit, Git saves your message in `.git/COMMIT_EDITMSG`. Recover it with:
133+
> ```bash
134+
> git commit --edit --file=.git/COMMIT_EDITMSG
135+
> ```
136+
>
137+
> Or create a convenient alias for quick recovery:
138+
> ```bash
139+
> git config --global alias.recommit 'commit -s --edit --file=.git/COMMIT_EDITMSG'
140+
> # Then simply use: git recommit
141+
> ```
142+
>
143+
> Test your message before committing:
144+
> ```bash
145+
> echo "feat: my feature" | gitlint
146+
> ```
147+
124148
#### Commit Message Format
125149
126150
Follow this format for all commits:
@@ -130,9 +154,27 @@ Follow this format for all commits:
130154
131155
[optional body]
132156
157+
Signed-off-by: Your Name <[email protected]>
158+
133159
[optional footer(s)]
134160
```
135161
162+
**Important:** All commits must include a `Signed-off-by` line (Developer Certificate of Origin).
163+
164+
**Adding sign-off automatically:**
165+
166+
```bash
167+
# Use -s flag when committing
168+
git commit -s -m "feat: your message"
169+
170+
# Or configure git to always prompt for sign-off with an alias
171+
git config alias.cs 'commit -s'
172+
173+
# Then use: git cs -m "feat: your message"
174+
```
175+
176+
The `Signed-off-by` line certifies that you have the right to submit the code under the project's license.
177+
136178
**Common types:**
137179

138180
- `feat`: New features
@@ -153,15 +195,23 @@ Follow this format for all commits:
153195
**Examples:**
154196

155197
```txt
156-
# feature for exporters
198+
# Feature for exporters
157199
feat(exporters): add jsonschema exporter
158200
159-
# fix in graphql processing
201+
This adds a new exporter that converts schemas to JSON Schema format.
202+
203+
Signed-off-by: John Doe <[email protected]>
204+
205+
# Fix in graphql processing
160206
fix: resolve memory leak in graphql processing
161207
162-
# feature including breaking change
208+
Signed-off-by: John Doe <[email protected]>
209+
210+
# Feature including breaking change
163211
feat!: migrate to new configuration format
164212
165-
# breaking change in body
166-
BREAKING CHANGE: configuration file structure has changed
213+
The configuration file structure has been updated to YAML format.
214+
Old TOML configs are no longer supported.
215+
216+
Signed-off-by: John Doe <[email protected]>
167217
```

0 commit comments

Comments
 (0)