gitlint: check for bad authors
Similar to how we expect Signed-off-by to be legal names matching
something from a CLA, it is helpful if the Author is formatted
similarly. Often, a new user especially, we fix their git-config and
the Signed-off-by but leave the author as a username-like. This leads
to the SRCREV bump script creating a commit message referencing a
[likely non-public] username instead of the proper name of the author.
Tested:
```
Running commit_gitlint (0.19.1)
-: UC4 Author user has too few words; likely user id instead of legal name?: "joe-bob"
```
Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
Change-Id: I6a3da5b27cd57de5758ba9277ae5d8b2e0570a5e
diff --git a/config/gitlint/bad_signedoffby.py b/config/gitlint/bad_signedoffby.py
index 83a8eae..00849e9 100644
--- a/config/gitlint/bad_signedoffby.py
+++ b/config/gitlint/bad_signedoffby.py
@@ -2,14 +2,14 @@
from gitlint.rules import CommitRule, RuleViolation
+# These are individuals, by email address, who chose to go by a one-word name.
+allowed_singlename_emails = ["anthonyhkf@google.com"]
+
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 = []
@@ -26,7 +26,7 @@
if (
len(match.group(1).split()) <= 1
- and match.group(2) not in self.exceptions
+ and match.group(2) not in allowed_singlename_emails
):
violations.append(
RuleViolation(
@@ -38,3 +38,23 @@
continue
return violations
+
+
+class BadAuthoredBy(CommitRule):
+ name = "bad-authored-by"
+ id = "UC4"
+
+ def validate(self, commit):
+ if commit.author_email in allowed_singlename_emails:
+ return None
+
+ if len(commit.author_name.split()) <= 1:
+ return [
+ RuleViolation(
+ self.id,
+ "Author user has too few words; likely user id instead of legal name?",
+ commit.author_name,
+ )
+ ]
+
+ return None