gitlint: screen userid from Signed-off-by
It is a common issue for new users to have a git-config that has a
user id (either from their system or github) rather than a legal name
matching an entry in their associated CLA. Screen these out in the
gitlint check, so maintainers do not need to check this manually.
Some individuals decide to go by a one word name. Provide an exception
for this.
Tested:
```
-: UC3 Signed-off-by user has too few words; likely user id instead of legal name?: "Signed-off-by: foo <foo@nobody.com>"
-: UC3 Invalid Signed-off-by format: "Signed-off-by: bar"
```
Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
Change-Id: Ie87d640db8f0d223912f7c3b77545347020255ee
diff --git a/config/gitlint/bad_signedoffby.py b/config/gitlint/bad_signedoffby.py
new file mode 100644
index 0000000..83a8eae
--- /dev/null
+++ b/config/gitlint/bad_signedoffby.py
@@ -0,0 +1,40 @@
+import re
+
+from gitlint.rules import CommitRule, RuleViolation
+
+
+class BadSignedOffBy(CommitRule):
+ name = "bad-signed-off-by"
+ id = "UC3"
+
+ # These are individuals, by email address, who chose to go by a one-word name.
+ exceptions = ["anthonyhkf@google.com"]
+
+ def validate(self, commit):
+ violations = []
+
+ sobs = [
+ x for x in commit.message.body if x.startswith("Signed-off-by:")
+ ]
+ for sob in sobs:
+ match = re.search("Signed-off-by: (.*) <(.*)>", sob)
+ if not match:
+ violations.append(
+ RuleViolation(self.id, "Invalid Signed-off-by format", sob)
+ )
+ continue
+
+ if (
+ len(match.group(1).split()) <= 1
+ and match.group(2) not in self.exceptions
+ ):
+ violations.append(
+ RuleViolation(
+ self.id,
+ "Signed-off-by user has too few words; likely user id instead of legal name?",
+ sob,
+ )
+ )
+ continue
+
+ return violations