Skip to content

Commit f9fe1e4

Browse files
synaretemergify[bot]
authored andcommitted
makefile: run gitlint via make rule
Use gitlint[1] tool to check validity for latest commit messages. Added special makefile rule "check-gitlint" to run gitlint on last commits from master branch to HEAD. Expects the gitlint utility to be present in PATH. [1] https://github.com/jorisroovers/gitlint Signed-off-by: Shachar Sharon <[email protected]>
1 parent 199419a commit f9fe1e4

File tree

2 files changed

+129
-0
lines changed

2 files changed

+129
-0
lines changed

.gitlint

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
# Edit this file as you like.
2+
#
3+
# All these sections are optional. Each section with the exception of [general] represents
4+
# one rule and each key in it is an option for that specific rule.
5+
#
6+
# Rules and sections can be referenced by their full name or by id. For example
7+
# section "[body-max-line-length]" could also be written as "[B1]". Full section names are
8+
# used in here for clarity.
9+
#
10+
[general]
11+
# Ignore certain rules, this example uses both full name and id
12+
# ignore=title-trailing-punctuation, T3
13+
14+
# verbosity should be a value between 1 and 3, the commandline -v flags take precedence over this
15+
verbosity=3
16+
17+
# By default gitlint will ignore merge, revert, fixup and squash commits.
18+
ignore-merge-commits=true
19+
# ignore-revert-commits=true
20+
# ignore-fixup-commits=true
21+
# ignore-squash-commits=true
22+
23+
# Ignore any data send to gitlint via stdin
24+
# ignore-stdin=true
25+
26+
# Fetch additional meta-data from the local repository when manually passing a
27+
# commit message to gitlint via stdin or --commit-msg. Disabled by default.
28+
# staged=true
29+
30+
# Enable debug mode (prints more output). Disabled by default.
31+
# debug=true
32+
33+
# Enable community contributed rules
34+
# See http://jorisroovers.github.io/gitlint/contrib_rules for details
35+
# contrib=contrib-body-requires-signed-off-by
36+
37+
# Set the extra-path where gitlint will search for user defined rules
38+
# See http://jorisroovers.github.io/gitlint/user_defined_rules for details
39+
# extra-path=examples/
40+
41+
# This is an example of how to configure the "title-max-length" rule and
42+
# set the line-length it enforces to 80
43+
[title-max-length]
44+
line-length=72
45+
46+
# Conversely, you can also enforce minimal length of a title with the
47+
# "title-min-length" rule:
48+
# [title-min-length]
49+
# min-length=5
50+
51+
[title-must-not-contain-word]
52+
# Comma-separated list of words that should not occur in the title. Matching is case
53+
# insensitive. It's fine if the keyword occurs as part of a larger word (so "WIPING"
54+
# will not cause a violation, but "WIP: my title" will.
55+
words=wip,WIP
56+
57+
[title-match-regex]
58+
# python-style regex that the commit-msg title must match
59+
# Note that the regex can contradict with other rules if not used correctly
60+
# (e.g. title-must-not-contain-word).
61+
regex=^.*
62+
63+
# [body-max-line-length]
64+
# line-length=72
65+
66+
# [body-min-length]
67+
# min-length=5
68+
69+
# [body-is-missing]
70+
# Whether to ignore this rule on merge commits (which typically only have a title)
71+
# default = True
72+
# ignore-merge-commits=false
73+
74+
# [body-changed-file-mention]
75+
# List of files that need to be explicitly mentioned in the body when they are changed
76+
# This is useful for when developers often erroneously edit certain files or git submodules.
77+
# By specifying this rule, developers can only change the file when they explicitly reference
78+
# it in the commit message.
79+
# files=gitlint/rules.py,README.md
80+
81+
# [body-match-regex]
82+
# python-style regex that the commit-msg body must match.
83+
# E.g. body must end in My-Commit-Tag: foo
84+
# regex=My-Commit-Tag: foo$
85+
86+
# [author-valid-email]
87+
# python-style regex that the commit author email address must match.
88+
# For example, use the following regex if you only want to allow email addresses from foo.com
89+
# regex=[^@][email protected]
90+
91+
# [ignore-by-title]
92+
# Ignore certain rules for commits of which the title matches a regex
93+
# E.g. Match commit titles that start with "Release"
94+
# regex=^Release(.*)
95+
96+
# Ignore certain rules, you can reference them by their id or by their full name
97+
# Use 'all' to ignore all rules
98+
# ignore=T1,body-min-length
99+
100+
# [ignore-by-body]
101+
# Ignore certain rules for commits of which the body has a line that matches a regex
102+
# E.g. Match bodies that have a line that that contain "release"
103+
# regex=(.*)release(.*)
104+
#
105+
# Ignore certain rules, you can reference them by their id or by their full name
106+
# Use 'all' to ignore all rules
107+
# ignore=T1,body-min-length
108+
109+
# [ignore-body-lines]
110+
# Ignore certain lines in a commit body that match a regex.
111+
# E.g. Ignore all lines that start with 'Co-Authored-By'
112+
# regex=^Co-Authored-By
113+
114+
# This is a contrib rule - a community contributed rule. These are disabled by default.
115+
# You need to explicitly enable them one-by-one by adding them to the "contrib" option
116+
# under [general] section above.
117+
# [contrib-title-conventional-commits]
118+
# Specify allowed commit types. For details see: https://www.conventionalcommits.org/
119+
# types = bugfix,user-story,epic

Makefile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,9 @@ check-yaml:
227227
check-gosec: gosec
228228
$(GOSEC) -quiet -exclude=G101 -fmt json ./...
229229

230+
check-gitlint: gitlint
231+
$(GITLINT) -C .gitlint --commits master.. lint
232+
230233
# find or download auxiliary build tools
231234
.PHONY: build-tools controller-gen kustomize revive golangci-lint yq
232235
build-tools: controller-gen kustomize revive golangci-lint yq
@@ -307,3 +310,10 @@ GOSEC=$(GOBIN_ALT)/gosec
307310
else
308311
GOSEC=$(shell command -v gosec ;)
309312
endif
313+
314+
gitlint:
315+
ifeq (, $(shell command -v gitlint ;))
316+
$(error "gitlint not found in PATH")
317+
else
318+
GITLINT=$(shell command -v gitlint ;)
319+
endif

0 commit comments

Comments
 (0)