diff --git a/.gitlint b/.gitlint index 80fc7a9eec6..4d55e50ad7c 100644 --- a/.gitlint +++ b/.gitlint @@ -19,6 +19,9 @@ max-line-count=200 [title-max-length] line-length=72 +[title-starts-with-subsystem] +regex = ^(([^:]+):)(\s([^:]+):)*\s(.+)$ + [title-must-not-contain-word] # Comma-separated list of words that should not occur in the title. Matching is case # insensitive. It's fine if the keyword occurs as part of a larger word (so "WIPING" diff --git a/scripts/gitlint/zephyr_commit_rules.py b/scripts/gitlint/zephyr_commit_rules.py index f6006ff3921..982587cc34e 100644 --- a/scripts/gitlint/zephyr_commit_rules.py +++ b/scripts/gitlint/zephyr_commit_rules.py @@ -1,5 +1,5 @@ -from gitlint.rules import CommitRule, RuleViolation -from gitlint.options import IntOption +from gitlint.rules import CommitRule, RuleViolation, TitleRegexMatches, CommitMessageTitle, LineRule +from gitlint.options import IntOption, BoolOption, StrOption, ListOption import re """ @@ -33,7 +33,6 @@ class BodyMaxLineCount(CommitRule): message = "Body contains too many lines ({0} > {1})".format(line_count, max_line_count) return [RuleViolation(self.id, message, line_nr=1)] - class SignedOffBy(CommitRule): """ This rule will enforce that each commit contains a "Signed-Off-By" line. We keep things simple here and just check whether the commit body contains a line that starts with "Signed-Off-By". @@ -55,3 +54,17 @@ class SignedOffBy(CommitRule): else: return return [RuleViolation(self.id, "Body does not contain a 'Signed-Off-By' line", line_nr=1)] + + +class TitleStartsWithSubsystem(LineRule): + name = "title-starts-with-subsystem" + id = "UC3" + target = CommitMessageTitle + options_spec = [StrOption('regex', ".*", "Regex the title should match")] + + def validate(self, title, _commit): + regex = self.options['regex'].value + pattern = re.compile(regex, re.UNICODE) + violation_message = "Title does not follow : " + if not pattern.search(title): + return [RuleViolation(self.id, violation_message, title)]