Skip to content

Commit 53c5aa3

Browse files
JBarberUfabiobaltieri
authored andcommitted
scripts: ci: check_compliance: Fix signoff check
Use the --format flag in git rather than parsing the output of the git log. The inspiration for this change was that the previous implementation breaks if there's a ~/.gitconfig that changes the git log format. Signed-off-by: John Barbero Unenge <git@lsrkttn.com>
1 parent 60a9a20 commit 53c5aa3

File tree

1 file changed

+29
-39
lines changed

1 file changed

+29
-39
lines changed

scripts/ci/check_compliance.py

Lines changed: 29 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
import argparse
88
import collections
9-
from email.utils import parseaddr
109
from itertools import takewhile
1110
import json
1211
import logging
@@ -1446,44 +1445,35 @@ class Identity(ComplianceTest):
14461445

14471446
def run(self):
14481447
for shaidx in get_shas(COMMIT_RANGE):
1449-
commit = git("log", "--decorate=short", "--no-use-mailmap", "-n 1", shaidx)
1450-
signed = []
1451-
author = ""
1452-
sha = ""
1453-
parsed_addr = None
1454-
for line in commit.split("\n"):
1455-
match = re.search(r"^commit\s([^\s]*)", line)
1456-
if match:
1457-
sha = match.group(1)
1458-
match = re.search(r"^Author:\s(.*)", line)
1459-
if match:
1460-
author = match.group(1)
1461-
parsed_addr = parseaddr(author)
1462-
match = re.search(r"signed-off-by:\s(.*)", line, re.IGNORECASE)
1463-
if match:
1464-
signed.append(match.group(1))
1465-
1466-
error1 = f"{sha}: author email ({author}) needs to match one of " \
1467-
f"the signed-off-by entries."
1468-
error2 = f"{sha}: author email ({author}) does not follow the " \
1469-
f"syntax: First Last <email>."
1470-
error3 = f"{sha}: author email ({author}) must be a real email " \
1471-
f"and cannot end in @users.noreply.github.com"
1472-
failure = None
1473-
if author not in signed:
1474-
failure = error1
1475-
1476-
if not parsed_addr or len(parsed_addr[0].split(" ")) < 2:
1477-
if not failure:
1478-
1479-
failure = error2
1480-
else:
1481-
failure = failure + "\n" + error2
1482-
elif parsed_addr[1].endswith("@users.noreply.github.com"):
1483-
failure = error3
1484-
1485-
if failure:
1486-
self.failure(failure)
1448+
auth_name, auth_email, body = git(
1449+
'show', '-s', '--format=%an%n%ae%n%b', shaidx
1450+
).split('\n', 2)
1451+
1452+
match_signoff = re.search(r"signed-off-by:\s(.*)", body,
1453+
re.IGNORECASE)
1454+
detailed_match = re.search(r"signed-off-by:\s(.*) <(.*)>", body,
1455+
re.IGNORECASE)
1456+
1457+
failures = []
1458+
1459+
if auth_email.endswith("@users.noreply.github.com"):
1460+
failures.append(f"{shaidx}: author email ({auth_email}) must "
1461+
"be a real email and cannot end in "
1462+
"@users.noreply.github.com")
1463+
1464+
if not match_signoff:
1465+
failures.append(f'{shaidx}: Missing signed-off-by line')
1466+
elif not detailed_match:
1467+
signoff = match_signoff.group(0)
1468+
failures.append(f"{shaidx}: Signed-off-by line ({signoff}) "
1469+
"does not follow the syntax: First "
1470+
"Last <email>.")
1471+
elif (auth_name, auth_email) != detailed_match.groups():
1472+
failures.append(f"{shaidx}: author email ({auth_email}) needs "
1473+
"to match one of the signed-off-by entries.")
1474+
1475+
if failures:
1476+
self.failure('\n'.join(failures))
14871477

14881478

14891479
class BinaryFiles(ComplianceTest):

0 commit comments

Comments
 (0)