1import re 2 3from gitlint.rules import CommitRule, RuleViolation 4 5# These are individuals, by email address, who chose to go by a one-word name. 6allowed_singlename_emails = ["anthonyhkf@google.com"] 7 8 9class BadSignedOffBy(CommitRule): 10 name = "bad-signed-off-by" 11 id = "UC3" 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 allowed_singlename_emails 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 42 43class BadAuthoredBy(CommitRule): 44 name = "bad-authored-by" 45 id = "UC4" 46 47 def validate(self, commit): 48 if commit.author_email in allowed_singlename_emails: 49 return None 50 51 if len(commit.author_name.split()) <= 1: 52 return [ 53 RuleViolation( 54 self.id, 55 "Author user has too few words; likely user id instead of legal name?", 56 commit.author_name, 57 ) 58 ] 59 60 return None 61