summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNejc Habjan <nejc.habjan@siemens.com>2020-08-30 13:12:13 +0200
committerNejc Habjan <nejc.habjan@siemens.com>2020-08-30 14:10:24 +0200
commit82070b2d2ed99189aebb1d595430ad5567306c4c (patch)
treea9496f4181a5b3858434810269d283b4482ff1ff
parent28aa17e56df5de4f2c74c831910559387414c487 (diff)
downloadgitlab-chore/pre-commit-config.tar.gz
chore(env): add pre-commit and commit-msg hookschore/pre-commit-config
-rw-r--r--.commitlintrc.json3
-rw-r--r--.pre-commit-config.yaml22
-rw-r--r--.travis.yml9
-rw-r--r--README.rst27
4 files changed, 52 insertions, 9 deletions
diff --git a/.commitlintrc.json b/.commitlintrc.json
new file mode 100644
index 0000000..c30e5a9
--- /dev/null
+++ b/.commitlintrc.json
@@ -0,0 +1,3 @@
+{
+ "extends": ["@commitlint/config-conventional"]
+}
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
new file mode 100644
index 0000000..ef6fbac
--- /dev/null
+++ b/.pre-commit-config.yaml
@@ -0,0 +1,22 @@
+default_language_version:
+ python: python3
+
+repos:
+ - repo: https://github.com/psf/black
+ rev: 20.8b1
+ hooks:
+ - id: black
+
+ - repo: https://github.com/alessandrojcm/commitlint-pre-commit-hook
+ rev: v3.0.0
+ hooks:
+ - id: commitlint
+ additional_dependencies: ['@commitlint/config-conventional']
+ stages: [commit-msg]
+
+ - repo: https://github.com/alessandrojcm/commitlint-pre-commit-hook
+ rev: v3.0.0
+ hooks:
+ - id: commitlint-travis
+ additional_dependencies: ['@commitlint/config-conventional']
+ stages: [manual]
diff --git a/.travis.yml b/.travis.yml
index 0721218..09359b5 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -14,10 +14,13 @@ jobs:
include:
- stage: lint
name: commitlint
+ python: 3.8
script:
- - npm install -g @commitlint/cli @commitlint/config-conventional
- - 'echo "module.exports = {extends: [\"@commitlint/config-conventional\"]}" > commitlint.config.js'
- - npx commitlint --from=origin/master
+ - pip3 install pre-commit
+ - pre-commit run --hook-stage manual commitlint-travis
+ cache:
+ directories:
+ - $HOME/.cache/pre-commit
- stage: lint
name: black_lint
dist: bionic
diff --git a/README.rst b/README.rst
index c98ff31..2291242 100644
--- a/README.rst
+++ b/README.rst
@@ -99,27 +99,42 @@ You can contribute to the project in multiple ways:
* Add unit and functional tests
* Everything else you can think of
+Development workflow
+--------------------
+
+Before contributing, please make sure you have `pre-commit <https://pre-commit.com>`_
+installed and configured. This will help automate adhering to code style and commit
+message guidelines described below:
+
+.. code-block:: bash
+
+ cd python-gitlab/
+ pip3 install --user pre-commit
+ pre-commit install -t pre-commit -t commit-msg --install-hooks
+
+Please provide your patches as GitHub pull requests. Thanks!
+
+Commit message guidelines
+-------------------------
+
We enforce commit messages to be formatted using the `conventional-changelog <https://github.com/angular/angular/blob/master/CONTRIBUTING.md#-commit-message-guidelines>`_.
This leads to more readable messages that are easy to follow when looking through the project history.
-Please provide your patches as github pull requests. Thanks!
-
Code-Style
----------
We use black as code formatter, so you'll need to format your changes using the
`black code formatter
-<https://github.com/python/black>`_.
+<https://github.com/python/black>`_. Pre-commit hooks will validate/format your code
+when committing. You can then stage any changes ``black`` added if the commit failed.
-Just run
+To format your code according to our guidelines before committing, run:
.. code-block:: bash
cd python-gitlab/
pip3 install --user black
black .
-
-to format your code according to our guidelines.
Running unit tests
------------------