-
Notifications
You must be signed in to change notification settings - Fork 100
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add regex for commit title that skips body checks, if matches #57
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A new test case would be nice.
gitlint/files/gitlint
Outdated
@@ -44,6 +44,8 @@ | |||
|
|||
# [body-min-length] | |||
# min-length=5 | |||
# ignore-body-checks-regex='' | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unnecessary empty line
@@ -79,14 +81,14 @@ def __eq__(self, other): | |||
return equal | |||
|
|||
def __str__(self): | |||
return sstr(self) # pragma: no cover | |||
return self.__unicode__() # pragma: no cover |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you use self.__unicode__()
? Does this work with Python 2 too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this works also with python 2 (Tested on python 2.7.14)
gitlint/rules.py
Outdated
@@ -243,14 +245,23 @@ def validate(self, commit): | |||
if first_line != "": | |||
return [RuleViolation(self.id, "Second line is not empty", first_line, 2)] | |||
|
|||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please restore the newline. Otherwise pep8 will complain.
gitlint/rules.py
Outdated
|
||
def validate(self, commit): | ||
min_length = self.options['min-length'].value | ||
regex = self.options['ignore-body-checks-regex'].value | ||
regex_valid = True if (self.options['ignore-body-checks-regex'].value) else False |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
regex_valid is not needed (see below).
gitlint/rules.py
Outdated
regex = self.options['ignore-body-checks-regex'].value | ||
regex_valid = True if (self.options['ignore-body-checks-regex'].value) else False | ||
|
||
if regex_valid and re.search(regex, commit.message.title): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can directly check for regex:
if regex and re.search(regex, commit.message.title):
gitlint/rules.py
Outdated
|
||
def validate(self, commit): | ||
regex = self.options['ignore-body-checks-regex'].value | ||
regex_valid = True if (self.options['ignore-body-checks-regex'].value) else False |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above.
gitlint/rules.py
Outdated
options_spec = [BoolOption('ignore-merge-commits', True, "Ignore merge commits")] | ||
# This needs to come from the real options | ||
options_spec = [BoolOption('ignore-merge-commits', True, "Ignore merge commits"), | ||
StrOption('ignore-body-checks-regex', '^Release', 'Ignore body checks for tiles matching regex')] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The default of ignore-body-checks-regex
should be empty.
gitlint/rules.py
Outdated
if regex_valid and re.search(regex, commit.message.title): | ||
logmsg = "Skipping %s (%s), because ignore-body-checks-regex matches." % (self.id, self.name) | ||
LOG.info(logmsg) | ||
return [] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be consistent, just return nothing.
gitlint/tests/test_body_rules.py
Outdated
@@ -77,12 +77,12 @@ def test_body_min_length(self): | |||
commit = self.gitcommit("Title\n\nThis is the second body line\n") | |||
|
|||
violations = rule.validate(commit) | |||
self.assertIsNone(violations) | |||
self.assertIn(violations, [[],None]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change is not needed if you return None.
gitlint/tests/test_body_rules.py
Outdated
|
||
# assert no error - no body | ||
commit = self.gitcommit(u"Tïtle\n") | ||
violations = rule.validate(commit) | ||
self.assertIsNone(violations) | ||
self.assertIn(violations, [[], None]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change is not needed if you return None.
gitlint/cli.py
Outdated
@@ -122,14 +122,15 @@ def stdin_has_data(): | |||
help="Verbosity, more v's for more verbose output (e.g.: -v, -vv, -vvv). [default: -vvv]", ) | |||
@click.option('-s', '--silent', help="Silent mode (no output). Takes precedence over -v, -vv, -vvv.", is_flag=True) | |||
@click.option('-d', '--debug', help="Enable debugging output.", is_flag=True) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
--debug
should be either removed or mapped to loglevel=debug
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This breaks even more tests and is not what we want to achieve here. Rejected.
commit = self.gitcommit(u"Release foo-bar-baz 0.12.3") | ||
violations = rule.validate(commit) | ||
self.assertIsNone(violations) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That test should go into a separate test method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, Done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The benefit of separate test cases is that it easier to spot which part breaks and it prevents hiding failures (the test will abort on the first assertion error).
commit = self.gitcommit(u"Release foo-bar-baz 0.12.3") | ||
violations = rule.validate(commit) | ||
self.assertIsNone(violations) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That test should go into a separate test method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See above
Some commits don't need a body. This adds an option (B5.ignore-body-checks-regex) to specify a regex. If this regex matches commit.message.title, further body checks are skipped. refs #39774 Signed-off-by: Steffen Kockel <steffen.kockel@profitbricks.com>
Signed-off-by: Steffen Kockel <steffen.kockel@profitbricks.com>
It doesn't entirely sit right with me is that this is being implemented as an option for specific rules. IMO the solution should be generic. More something along the lines of:
There's several hours of work involved with implementing this I think (and like usually, the majority of time spent on tests and docs). Interested to hear your thoughts. Let me know if you intend on working on this, if not, I can probably look at it at some point (today, next month, later this year, really depends on when I find/make time). |
Put some more thought into this, I think I've got a better solution. We can introduce a new type of rule The nice thing about this approach is that it's generic and that other users can easily extend it by building their own custom Gitlint would then just implement a couple of built-in ignore-rules that are set to ignore nothing by default, but can be configured like so:
I'll work on this :-) |
Added a new IgnoreByTitle rule that is based on a new more generic rule construct called ConfigurationRule. ConfigurationRules can modify gitlint configuration (and therefore behavior) on a per commit basis. Added some tests and docs, more docs and integration tests to follow in additional commits. This is part of #54 and #57.
This was actually my first contact with this code. Thanks for incorporating the requested feature. No bad feelings here. 👍 |
We needed a possibility to exclude release commits from our rigorous gitlint-checks.
This pull requests has the following to offer
-d
and-v[vvv]