From b8d423e7d13686d6627571d6c4adf12661d82147 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 13 Oct 2021 07:34:54 +0200 Subject: Adding upstream version 0.16.0. Signed-off-by: Daniel Baumann --- gitlint/rules.py | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'gitlint/rules.py') diff --git a/gitlint/rules.py b/gitlint/rules.py index db21e56..1c5a618 100644 --- a/gitlint/rules.py +++ b/gitlint/rules.py @@ -141,7 +141,7 @@ class LineMustNotContainWord(LineRule): strings = self.options['words'].value violations = [] for string in strings: - regex = re.compile(r"\b%s\b" % string.lower(), re.IGNORECASE | re.UNICODE) + regex = re.compile(rf"\b{string.lower()}\b", re.IGNORECASE | re.UNICODE) match = regex.search(line.lower()) if match: violations.append(RuleViolation(self.id, self.violation_message.format(string), line)) @@ -416,3 +416,25 @@ class IgnoreBodyLines(ConfigurationRule): commit.message.body = new_body commit.message.full = "\n".join([commit.message.title] + new_body) + + +class IgnoreByAuthorName(ConfigurationRule): + name = "ignore-by-author-name" + id = "I4" + options_spec = [RegexOption('regex', None, "Regex matching the author name of commits this rule should apply to"), + StrOption('ignore', "all", "Comma-separated list of rules to ignore")] + + def apply(self, config, commit): + # If no regex is specified, immediately return + if not self.options['regex'].value: + return + + if self.options['regex'].value.match(commit.author_name): + config.ignore = self.options['ignore'].value + + message = (f"Commit Author Name '{commit.author_name}' matches the regex " + f"'{self.options['regex'].value.pattern}', ignoring rules: {self.options['ignore'].value}") + + self.log.debug("Ignoring commit because of rule '%s': %s", self.id, message) + # No need to check other lines if we found a match + return -- cgit v1.2.3