File tree Expand file tree Collapse file tree 5 files changed +87
-0
lines changed Expand file tree Collapse file tree 5 files changed +87
-0
lines changed Original file line number Diff line number Diff line change 1
1
---
2
2
repos :
3
+ - repo : ./
4
+ rev : master
5
+ hooks :
6
+ - id : commit-message-validator
7
+ stages : [commit-msg]
8
+ args : [--no-jira, --allow-temp]
9
+
3
10
- repo : https://github.com/adrienverge/yamllint.git
4
11
rev : v1.24.2
5
12
hooks :
Original file line number Diff line number Diff line change
1
+ ---
2
+ - id : commit-message-validator
3
+ name : Commit Message Validator
4
+ description : Checks that commit messages are compliant with Lumapps rules.
5
+ entry : check_message.sh
6
+ language : script
Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ pre-commit=./venv/bin/pre-commit
13
13
venv :
14
14
python3.7 -m venv venv
15
15
$(pip ) install pre-commit
16
+ $(pre-commit ) install -t commit-msg
16
17
17
18
lint :
18
19
$(pre-commit ) run --all-files
Original file line number Diff line number Diff line change @@ -247,6 +247,30 @@ jobs:
247
247
- if ` no_jira` is not empty, no validation is done on JIRA refs.
248
248
- if `allow_temp` is not empty, no validation is done on `fixup!` and `squash!` commits.
249
249
250
+ # # Add pre-commit plugin
251
+
252
+ If you are using [pre-commit](https://pre-commit.com/) in you repository, you can add this to your configuration so commit messages are checked locally :
253
+
254
+ Into `.pre-commit-config.yaml` :
255
+ ` ` ` yaml
256
+ ...
257
+ repos:
258
+ ...
259
+ - repo: https://github.com/lumapps/commit-message-validator
260
+ rev: master
261
+ hooks:
262
+ - id: commit-message-validator
263
+ stages: [commit-msg]
264
+ args: [--allow-temp]
265
+ ...
266
+ ` ` `
267
+ Then run `pre-commit install --hook-type commit-msg` to install the `commit-message-validator`
268
+
269
+ # ## OPTIONS
270
+
271
+ - if `no_jira` is set, no validation is done on JIRA refs.
272
+ - if `allow_temp` is set, no validation is done on `fixup!` and `squash!` commits.
273
+
250
274
<!-- ROADMAP -->
251
275
252
276
# # Roadmap
Original file line number Diff line number Diff line change
1
+ #! /usr/bin/env bash
2
+
3
+ set -eu
4
+
5
+ OPTIONS=$( getopt --long no-jira allow-temp -- " $@ " )
6
+ [ $? -eq 0 ] || {
7
+ echo " Incorrect options provided"
8
+ exit 1
9
+ }
10
+
11
+ COMMIT_VALIDATOR_ALLOW_TEMP=
12
+ COMMIT_VALIDATOR_NO_JIRA=
13
+
14
+ while true ; do
15
+ case " $1 " in
16
+ --no-jira ) COMMIT_VALIDATOR_NO_JIRA=1; shift ;;
17
+ --allow-temp ) COMMIT_VALIDATOR_ALLOW_TEMP=1; shift ;;
18
+ -- ) shift ; break ;;
19
+ * ) break ;;
20
+ esac
21
+ done
22
+
23
+ DIR=" $( cd " $( dirname " ${BASH_SOURCE[0]} " ) " > /dev/null 2>&1 && pwd ) "
24
+ # shellcheck source=validator.sh
25
+ source " $DIR /validator.sh"
26
+
27
+
28
+ if [[ " $1 " == * MERGE_MSG ]]
29
+ then
30
+ # ignore merge message (merge with --no-ff without conflict)
31
+ exit
32
+ fi
33
+
34
+ MESSAGE=$( < " $1 " )
35
+
36
+ FIRST_WORD=${MESSAGE%% * }
37
+ if [[ " ${FIRST_WORD,,} " == merge ]]
38
+ then
39
+ # ignore merge commits (merge after conflict resolution)
40
+ exit
41
+
42
+ fi
43
+
44
+ # print message so you don't lose it in case of errors
45
+ # (in case you are not using `-m` option)
46
+ echo " Options: JIRA=$COMMIT_VALIDATOR_NO_JIRA , TEMP=$COMMIT_VALIDATOR_ALLOW_TEMP "
47
+ printf " checking commit message:\n\n#BEGIN#\n%s\n#END#\n\n" " $( grep -v " #" <<< " $MESSAGE" ) "
48
+
49
+ validate " $MESSAGE "
You can’t perform that action at this time.
0 commit comments