summaryrefslogtreecommitdiffstats
path: root/gitlint/rules.py
diff options
context:
space:
mode:
Diffstat (limited to 'gitlint/rules.py')
-rw-r--r--gitlint/rules.py24
1 files changed, 23 insertions, 1 deletions
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