From 22217a92d57b530003989f1b8502c435934e6b89 Mon Sep 17 00:00:00 2001
From: Thomas Lambert <t.lambert@uliege.be>
Date: Fri, 15 Apr 2022 14:59:32 +0200
Subject: [PATCH] ci: add miss_hit checks to CI

---
 .gitlab-ci.yml          | 18 ++++++++++++++++++
 .pre-commit-config.yaml | 24 ++++++++++++++++++++++++
 CHANGELOG.md            |  2 ++
 CONTRIBUTING.md         | 17 +++++++++++++++++
 requirements.txt        |  2 ++
 5 files changed, 63 insertions(+)
 create mode 100644 .gitlab-ci.yml
 create mode 100644 .pre-commit-config.yaml
 create mode 100644 requirements.txt

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
new file mode 100644
index 0000000..d87e41c
--- /dev/null
+++ b/.gitlab-ci.yml
@@ -0,0 +1,18 @@
+---
+# Using the official Python Docker image as default
+image: python
+
+# Columns of the pipeline
+stages:
+  - static analysis
+
+# Static code analysis job via MISS_HIT
+static analysis:
+  stage: static analysis
+  before_script:
+    - pip install miss_hit
+  script:
+    - mh_style . --fix
+    - mh_metric . --ci
+    - mh_lint .
+  allow_failure: false
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
new file mode 100644
index 0000000..822060b
--- /dev/null
+++ b/.pre-commit-config.yaml
@@ -0,0 +1,24 @@
+---
+repos:
+  - repo: local
+    hooks:
+      - id: mh_style
+        entry: mh_style
+        name: mh_style
+        args: [--process-slx, --fix]
+        files: ^(.*\.(m|slx))$
+        language: python
+        additional_dependencies: [miss_hit_core]
+      - id: mh_metric
+        name: mh_metric
+        entry: mh_metric
+        args: [--ci]
+        files: ^(.*\.(m|slx))$
+        language: python
+        additional_dependencies: [miss_hit_core]
+      - id: mh_lint
+        name: mh_lint
+        entry: mh_lint
+        files: ^(.*\.(m|slx))$
+        language: python
+        additional_dependencies: [miss_hit]
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 6a6eb21..69e56b8 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -10,6 +10,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 ### Added
 
 - Start using MISS_HIT for style and code analysis.
+- ci: Add MISS_HIT job in pipeline
+- ci: Add pre-commit hook for miss_hit
 
 ### Changed
 
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 941a97d..3bdd25e 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -140,6 +140,22 @@ errors.
 mh_lint .
 ```
 
+A more convenient way to use MISS_HIT is to include it in a pre-commit hook.
+This can be done with [pre-commit][pre-commit-site]. To install both
+dependencies just run:
+
+```bash
+pip3 install -r requirements.txt
+```
+
+The install the pre-commit hooks using:
+
+```bash
+pre-commit install
+```
+
+Now the three MISS_HIT checks will be run every time you make a commit.
+
 #### Other
 
 Some other conventions can not be currently enforced by MISS_HIT. They should
@@ -172,5 +188,6 @@ The following naming convention is adopted:
 5. Ensure MISS_HIT is happy
 6. Submit your Merge Request.
 
+[pre-commit-site]: https://pre-commit.com/
 [miss_hit]: https://github.com/florianschanda/miss_hit
 [miss_hit_cfg]: https://gitlab.uliege.be/am-dept/matlab_airfoil_toolbox/-/blob/master/miss_hit.cfgj:w
diff --git a/requirements.txt b/requirements.txt
new file mode 100644
index 0000000..25b12e3
--- /dev/null
+++ b/requirements.txt
@@ -0,0 +1,2 @@
+miss_hit
+pre-commit
-- 
GitLab