Skip to content

Commit 184b4e8

Browse files
BreadGenieMolkree
andauthored
ci(pre-commit): add gitlint (#1573)
Co-authored-by: Dmitry Volodin <[email protected]> Co-authored-by: Dmitry Volodin <[email protected]>
1 parent 2b04fe6 commit 184b4e8

File tree

6 files changed

+22
-3
lines changed

6 files changed

+22
-3
lines changed

.github/actions/spelling/allow.txt

+1
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ getenv
118118
gettext
119119
Giridhar
120120
github
121+
gitlint
121122
glibc
122123
gnomeshell
123124
gnupg

.github/workflows/linting.yml

+10-2
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@ jobs:
1212
strategy:
1313
fail-fast: false
1414
matrix:
15-
tool: ['isort', 'black', 'pyupgrade', 'flake8', 'format_checkers', 'bandit']
15+
tool: ['isort', 'black', 'pyupgrade', 'flake8', 'format_checkers', 'bandit', 'gitlint']
1616
steps:
1717
- uses: actions/checkout@v2
18+
with:
19+
fetch-depth: 0
1820
- uses: actions/setup-python@v2
1921
with:
2022
cache: 'pip'
@@ -29,6 +31,12 @@ jobs:
2931
run: |
3032
python -m pip install --upgrade wheel
3133
python -m pip install .
32-
- name: Run ${{ matrix.tool }}
34+
- name: Run ${{ matrix.tool }} using pre-commit
35+
if: ${{ matrix.tool != 'gitlint' }}
3336
run: |
3437
pre-commit run ${{ matrix.tool }} --all-files
38+
- name: Run gitlint
39+
if: ${{ github.event_name == 'pull_request' && matrix.tool == 'gitlint' }}
40+
run: |
41+
python -m pip install --upgrade gitlint
42+
gitlint --commits ${{ github.event.pull_request.base.sha }}..${{ github.event.pull_request.head.sha }}

.gitlint

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[general]
2+
ignore=body-is-missing
3+
contrib=contrib-title-conventional-commits

.pre-commit-config.yaml

+5
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,8 @@ repos:
3333
name: format_checkers
3434
entry: python cve_bin_tool/format_checkers.py
3535
files: "^cve_bin_tool/checkers/__init__.py"
36+
37+
- repo: https://github.com/jorisroovers/gitlint
38+
rev: v0.17.0
39+
hooks:
40+
- id: gitlint

CONTRIBUTING.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ CVE Binary Tool uses a few tools to improve code quality and readability:
162162
- `flake8` provides additional code "linting" for more complex errors like unused imports.
163163
- `pyupgrade` helps us be forward compatible with new versions of python.
164164
- `bandit` is more of a static analysis tool than a linter and helps us find potential security flaws in the code.
165+
- `gitlint` helps ensure that the commit messages follow [Conventional Commits](https://conventionalcommits.org).
165166

166167
We provide a `dev-requirements.txt` file which includes all the precise versions of tools as they'll be used in GitHub Actions. You an install them all using pip:
167168

@@ -176,7 +177,7 @@ to run isort/Black locally before you commit, you can install
176177
the hook as follows from the main `cve-bin-tool` directory:
177178

178179
```bash
179-
pre-commit install
180+
pre-commit install --hook-type pre-commit --hook-type commit-msg
180181
```
181182

182183
Once this is installed, all of those commands will run automatically when you run `git commit` and it won't let you commit until any issues are resolved. (You can also run them manually using `pre-commit` with no arguments.) This will only run on files staged for commit (e.g. things where you've already run `git add`). If you want to run on arbitrary files, see below:

dev-requirements.txt

+1
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ isort==5.10.1
33
pre-commit==2.16.0
44
flake8==4.0.1
55
bandit==1.7.1
6+
gitlint==0.17.0

0 commit comments

Comments
 (0)