Skip to content

Commit 97d8261

Browse files
authored
Merge pull request #1162 from python-gitlab/chore/pre-commit-config
chore(env): add pre-commit and commit-msg hooks
2 parents 28aa17e + 82070b2 commit 97d8261

File tree

4 files changed

+52
-9
lines changed

4 files changed

+52
-9
lines changed

.commitlintrc.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": ["@commitlint/config-conventional"]
3+
}

.pre-commit-config.yaml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
default_language_version:
2+
python: python3
3+
4+
repos:
5+
- repo: https://github.com/psf/black
6+
rev: 20.8b1
7+
hooks:
8+
- id: black
9+
10+
- repo: https://github.com/alessandrojcm/commitlint-pre-commit-hook
11+
rev: v3.0.0
12+
hooks:
13+
- id: commitlint
14+
additional_dependencies: ['@commitlint/config-conventional']
15+
stages: [commit-msg]
16+
17+
- repo: https://github.com/alessandrojcm/commitlint-pre-commit-hook
18+
rev: v3.0.0
19+
hooks:
20+
- id: commitlint-travis
21+
additional_dependencies: ['@commitlint/config-conventional']
22+
stages: [manual]

.travis.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,13 @@ jobs:
1414
include:
1515
- stage: lint
1616
name: commitlint
17+
python: 3.8
1718
script:
18-
- npm install -g @commitlint/cli @commitlint/config-conventional
19-
- 'echo "module.exports = {extends: [\"@commitlint/config-conventional\"]}" > commitlint.config.js'
20-
- npx commitlint --from=origin/master
19+
- pip3 install pre-commit
20+
- pre-commit run --hook-stage manual commitlint-travis
21+
cache:
22+
directories:
23+
- $HOME/.cache/pre-commit
2124
- stage: lint
2225
name: black_lint
2326
dist: bionic

README.rst

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,27 +99,42 @@ You can contribute to the project in multiple ways:
9999
* Add unit and functional tests
100100
* Everything else you can think of
101101

102+
Development workflow
103+
--------------------
104+
105+
Before contributing, please make sure you have `pre-commit <https://pre-commit.com>`_
106+
installed and configured. This will help automate adhering to code style and commit
107+
message guidelines described below:
108+
109+
.. code-block:: bash
110+
111+
cd python-gitlab/
112+
pip3 install --user pre-commit
113+
pre-commit install -t pre-commit -t commit-msg --install-hooks
114+
115+
Please provide your patches as GitHub pull requests. Thanks!
116+
117+
Commit message guidelines
118+
-------------------------
119+
102120
We enforce commit messages to be formatted using the `conventional-changelog <https://github.com/angular/angular/blob/master/CONTRIBUTING.md#-commit-message-guidelines>`_.
103121
This leads to more readable messages that are easy to follow when looking through the project history.
104122

105-
Please provide your patches as github pull requests. Thanks!
106-
107123
Code-Style
108124
----------
109125

110126
We use black as code formatter, so you'll need to format your changes using the
111127
`black code formatter
112-
<https://github.com/python/black>`_.
128+
<https://github.com/python/black>`_. Pre-commit hooks will validate/format your code
129+
when committing. You can then stage any changes ``black`` added if the commit failed.
113130

114-
Just run
131+
To format your code according to our guidelines before committing, run:
115132

116133
.. code-block:: bash
117134
118135
cd python-gitlab/
119136
pip3 install --user black
120137
black .
121-
122-
to format your code according to our guidelines.
123138
124139
Running unit tests
125140
------------------

0 commit comments

Comments
 (0)