lint: Allow revert commit messages in gitlint.

Fixes #8145.
This commit is contained in:
Shubham Padia 2018-02-13 07:31:22 +05:30 committed by Tim Abbott
parent ddf83f65ce
commit e1f943913a
2 changed files with 25 additions and 3 deletions

View File

@ -1,9 +1,9 @@
[general]
ignore=title-trailing-punctuation, body-min-length, body-is-missing
ignore=title-trailing-punctuation, body-min-length, body-is-missing, title-imperative-mood
# extra-path=tools/lib/gitlint-rules.py
extra-path=tools/lib/gitlint-rules.py
[title-match-regex]
[title-match-regex-allow-exception]
regex=^(.+:\ )?[A-Z].+\.$
[title-max-length]

View File

@ -2,6 +2,8 @@ from typing import Text, List
import gitlint
from gitlint.rules import LineRule, RuleViolation, CommitMessageTitle
from gitlint.options import StrOption
import re
# Word list from https://github.com/m1foley/fit-commit
# Copyright (c) 2015 Mike Foley
@ -141,3 +143,23 @@ class ImperativeMood(LineRule):
violations.append(violation)
return violations
class TitleMatchRegexAllowException(LineRule):
"""Allows revert commits contrary to the built-in title-match-regex rule"""
name = 'title-match-regex-allow-exception'
id = 'Z2'
target = CommitMessageTitle
options_spec = [StrOption('regex', ".*", "Regex the title should match")]
def validate(self, title, commit):
# type: (Text, gitlint.commit) -> List[RuleViolation]
regex = self.options['regex'].value
pattern = re.compile(regex, re.UNICODE)
if not pattern.search(title) and not title.startswith("Revert \""):
violation_msg = u"Title does not match regex ({0})".format(regex)
return [RuleViolation(self.id, violation_msg, title)]
return []