1- from gitlint .rules import CommitRule , RuleViolation
2- from gitlint .options import IntOption
1+ from gitlint .rules import CommitRule , RuleViolation , TitleRegexMatches , CommitMessageTitle , LineRule
2+ from gitlint .options import IntOption , BoolOption , StrOption , ListOption
33import re
44
55"""
@@ -33,7 +33,6 @@ def validate(self, commit):
3333 message = "Body contains too many lines ({0} > {1})" .format (line_count , max_line_count )
3434 return [RuleViolation (self .id , message , line_nr = 1 )]
3535
36-
3736class SignedOffBy (CommitRule ):
3837 """ This rule will enforce that each commit contains a "Signed-Off-By" line.
3938 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 @@ def validate(self, commit):
5554 else :
5655 return
5756 return [RuleViolation (self .id , "Body does not contain a 'Signed-Off-By' line" , line_nr = 1 )]
57+
58+
59+ class TitleStartsWithSubsystem (LineRule ):
60+ name = "title-starts-with-subsystem"
61+ id = "UC3"
62+ target = CommitMessageTitle
63+ options_spec = [StrOption ('regex' , ".*" , "Regex the title should match" )]
64+
65+ def validate (self , title , _commit ):
66+ regex = self .options ['regex' ].value
67+ pattern = re .compile (regex , re .UNICODE )
68+ violation_message = "Title does not follow <subsystem>: <subject>"
69+ if not pattern .search (title ):
70+ return [RuleViolation (self .id , violation_message , title )]
0 commit comments