From 0833669a8470b0c3cc6ccec64f4dce5e6259f004 Mon Sep 17 00:00:00 2001 From: Yashasvi Nancherla Date: Thu, 9 Apr 2026 13:10:41 +0530 Subject: [PATCH 1/2] Add changes to consider different trailer keywords Action was only considering signed-off-key before, this change will enable it to consider different keywords as valid trailers Signed-off-by: Yashasvi Nancherla --- check_commits.py | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/check_commits.py b/check_commits.py index df7d3c2..d602d22 100644 --- a/check_commits.py +++ b/check_commits.py @@ -6,6 +6,13 @@ import argparse import subprocess +TRAILER_PREFIXES = ( + "signed-off-by:", + "co-authored-by:", + "reviewed-by:", + "acked-by:", + "tested-by:", +) def parse_arguments(): parser = argparse.ArgumentParser( @@ -83,7 +90,7 @@ def validate_body(lines, n, body_char_limit, check_blank_line): body = [ line.strip() for line in lines[body_index:n] - if line.strip() and not line.lower().startswith("signed-off-by") + if line.strip() and not line.lower().startswith(TRAILER_PREFIXES) ] if len(body) == 0: errors.append("Commit message is missing a body!") @@ -94,15 +101,23 @@ def validate_body(lines, n, body_char_limit, check_blank_line): return errors, body -def validate_signoff(lines, n, body, check_blank_line): - """Validate the Signed-off-by line.""" +def validate_trailers(lines, body, check_blank_line): errors = [] - signed_off = lines[-1] if n > 0 and "signed-off-by" in lines[-1].lower() else "" + trailer_indices = [ + i for i, line in enumerate(lines) + if line.lower().startswith(TRAILER_PREFIXES) + ] + + first_trailer_index = 0 + if trailer_indices: + first_trailer_index = trailer_indices[0] - if check_blank_line.lower() == "true" and body and signed_off: - if n >= 2 and lines[-2].strip() != "": - errors.append("Body and Signed-off-by must be separated by a blank line") + if check_blank_line.lower() == "true" and body: + if first_trailer_index > 0 and lines[first_trailer_index - 1].strip() != "": + errors.append( + "Body and trailers must be separated by a blank line" + ) return errors @@ -117,9 +132,9 @@ def validate_commit_message(commit, sub_char_limit, body_char_limit, check_blank errors = [] subject_errors = validate_subject(subject, sub_char_limit) body_errors, body = validate_body(lines, n, body_char_limit, check_blank_line) - signed_off_errors = validate_signoff(lines, n, body, check_blank_line) + trailer_errors = validate_trailers(lines, body, check_blank_line) - errors.extend(subject_errors + body_errors + signed_off_errors) + errors.extend(subject_errors + body_errors + trailer_errors) return sha, errors From 00b8ddfaca6bfe5edf6051cbf8987fee36ff08a7 Mon Sep 17 00:00:00 2001 From: Yashasvi Nancherla Date: Thu, 9 Apr 2026 13:14:18 +0530 Subject: [PATCH 2/2] Reformat check_commits.py script Signed-off-by: Yashasvi Nancherla --- check_commits.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/check_commits.py b/check_commits.py index d602d22..2e2a188 100644 --- a/check_commits.py +++ b/check_commits.py @@ -14,6 +14,7 @@ "tested-by:", ) + def parse_arguments(): parser = argparse.ArgumentParser( description="Validate commit messages using local Git history (no API/token)." @@ -105,8 +106,7 @@ def validate_trailers(lines, body, check_blank_line): errors = [] trailer_indices = [ - i for i, line in enumerate(lines) - if line.lower().startswith(TRAILER_PREFIXES) + i for i, line in enumerate(lines) if line.lower().startswith(TRAILER_PREFIXES) ] first_trailer_index = 0 @@ -115,9 +115,7 @@ def validate_trailers(lines, body, check_blank_line): if check_blank_line.lower() == "true" and body: if first_trailer_index > 0 and lines[first_trailer_index - 1].strip() != "": - errors.append( - "Body and trailers must be separated by a blank line" - ) + errors.append("Body and trailers must be separated by a blank line") return errors