1import re 2 3from gitlint.rules import CommitRule, RuleViolation 4 5 6class BadSignedOffBy(CommitRule): 7 name = "bad-signed-off-by" 8 id = "UC3" 9 10 # These are individuals, by email address, who chose to go by a one-word name. 11 exceptions = ["anthonyhkf@google.com"] 12 13 def validate(self, commit): 14 violations = [] 15 16 sobs = [ 17 x for x in commit.message.body if x.startswith("Signed-off-by:") 18 ] 19 for sob in sobs: 20 match = re.search("Signed-off-by: (.*) <(.*)>", sob) 21 if not match: 22 violations.append( 23 RuleViolation(self.id, "Invalid Signed-off-by format", sob) 24 ) 25 continue 26 27 if ( 28 len(match.group(1).split()) <= 1 29 and match.group(2) not in self.exceptions 30 ): 31 violations.append( 32 RuleViolation( 33 self.id, 34 "Signed-off-by user has too few words; likely user id instead of legal name?", 35 sob, 36 ) 37 ) 38 continue 39 40 return violations 41