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>
This commit is contained in:
John Barbero Unenge 2025-03-10 09:57:25 +01:00 committed by Fabio Baltieri
commit 53c5aa3bb0

View file

@ -6,7 +6,6 @@
import argparse import argparse
import collections import collections
from email.utils import parseaddr
from itertools import takewhile from itertools import takewhile
import json import json
import logging import logging
@ -1446,44 +1445,35 @@ class Identity(ComplianceTest):
def run(self): def run(self):
for shaidx in get_shas(COMMIT_RANGE): for shaidx in get_shas(COMMIT_RANGE):
commit = git("log", "--decorate=short", "--no-use-mailmap", "-n 1", shaidx) auth_name, auth_email, body = git(
signed = [] 'show', '-s', '--format=%an%n%ae%n%b', shaidx
author = "" ).split('\n', 2)
sha = ""
parsed_addr = None
for line in commit.split("\n"):
match = re.search(r"^commit\s([^\s]*)", line)
if match:
sha = match.group(1)
match = re.search(r"^Author:\s(.*)", line)
if match:
author = match.group(1)
parsed_addr = parseaddr(author)
match = re.search(r"signed-off-by:\s(.*)", line, re.IGNORECASE)
if match:
signed.append(match.group(1))
error1 = f"{sha}: author email ({author}) needs to match one of " \ match_signoff = re.search(r"signed-off-by:\s(.*)", body,
f"the signed-off-by entries." re.IGNORECASE)
error2 = f"{sha}: author email ({author}) does not follow the " \ detailed_match = re.search(r"signed-off-by:\s(.*) <(.*)>", body,
f"syntax: First Last <email>." re.IGNORECASE)
error3 = f"{sha}: author email ({author}) must be a real email " \
f"and cannot end in @users.noreply.github.com"
failure = None
if author not in signed:
failure = error1
if not parsed_addr or len(parsed_addr[0].split(" ")) < 2: failures = []
if not failure:
failure = error2 if auth_email.endswith("@users.noreply.github.com"):
else: failures.append(f"{shaidx}: author email ({auth_email}) must "
failure = failure + "\n" + error2 "be a real email and cannot end in "
elif parsed_addr[1].endswith("@users.noreply.github.com"): "@users.noreply.github.com")
failure = error3
if failure: if not match_signoff:
self.failure(failure) failures.append(f'{shaidx}: Missing signed-off-by line')
elif not detailed_match:
signoff = match_signoff.group(0)
failures.append(f"{shaidx}: Signed-off-by line ({signoff}) "
"does not follow the syntax: First "
"Last <email>.")
elif (auth_name, auth_email) != detailed_match.groups():
failures.append(f"{shaidx}: author email ({auth_email}) needs "
"to match one of the signed-off-by entries.")
if failures:
self.failure('\n'.join(failures))
class BinaryFiles(ComplianceTest): class BinaryFiles(ComplianceTest):