Refactor: Add pre-commit config and update tox
[ci-management.git] / tox.ini
diff --git a/tox.ini b/tox.ini
index e33d587..5dad540 100644 (file)
--- a/tox.ini
+++ b/tox.ini
@@ -1,16 +1,52 @@
 [tox]
 minversion = 1.6
-envlist = coala
+envlist = pre-commit
 skipsdist = true
 
-[testenv:coala]
+[testenv:jenkins-jobs]
+deps =
+    jenkins-job-builder=={env:JJB_VERSION:5.0.2}
+commands =
+    jenkins-jobs {posargs:--help}
+
+
+[testenv:pre-commit-install]
 basepython = python3
+deps = pre-commit
+commands =
+    pre-commit install
+    pre-commit install --hook-type commit-msg
+
+[testenv:pre-commit-uninstall]
+basepython = python3
+deps = pre-commit
+commands =
+    pre-commit uninstall
+    pre-commit uninstall --hook-type commit-msg
+
+[testenv:pre-commit]
+description = Precommit checks for black, gitlint, etc.
+allowlist_externals =
+    /bin/sh
 deps =
-    coala==0.11
-    coala-bears==0.11
-    nodeenv~=1.3.0
+    pre-commit
+passenv = HOME
 commands =
-    nodeenv -p
-    npm install --global write-good
-    python3 -m nltk.downloader punkt maxent_treebank_pos_tagger averaged_perceptron_tagger
-    coala --non-interactive
+    pre-commit run --all-files --show-diff-on-failure
+    /bin/sh -c 'if ! git config --get user.name > /dev/null; then \
+        git config --global --add user.name "CI"; \
+        touch .git/REMOVE_USERNAME; fi'
+    /bin/sh -c 'if ! git config --get user.email > /dev/null; then \
+        git config --global --add user.email "ci@example.org"; \
+        touch .git/REMOVE_USEREMAIL; fi'
+    /bin/sh -c "if [ -f .git/COMMIT_EDITMSG ]; then \
+        cp .git/COMMIT_EDITMSG .git/COMMIT_MSGTOX; else \
+        git log HEAD -n1 --pretty=%B > .git/COMMIT_MSGTOX; fi"
+    pre-commit run gitlint --hook-stage commit-msg --commit-msg-filename .git/COMMIT_MSGTOX
+    /bin/sh -c "rm -f .git/COMMIT_MSGTOX"
+    /bin/sh -c "if [ -f .git/REMOVE_USERNAME ]; then \
+        git config --global --unset user.name; \
+        rm -f .git/REMOVE_USERNAME; fi"
+    /bin/sh -c "if [ -f .git/REMOVE_USEREMAIL ]; then \
+        git config --global --unset user.email; \
+        rm -f .git/REMOVE_USEREMAIL; fi"