Skip to content

Commit b8961db

Browse files
committed
feat: enhance commit message checks with section separators and no-banner option
1 parent 784aea0 commit b8961db

2 files changed

Lines changed: 47 additions & 2 deletions

File tree

main.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
SUCCESS_TITLE = "# Commit-Check ✔️"
1111
FAILURE_TITLE = "# Commit-Check ❌"
1212
COMMIT_MESSAGE_DELIMITER = "\x00"
13+
COMMIT_SECTION_SEPARATOR = "\n" + ("-" * 72) + "\n"
1314

1415
# Environment variables
1516
MESSAGE = os.getenv("MESSAGE", "false")
@@ -156,12 +157,23 @@ def run_pr_message_checks(pr_messages: list[str], result_file: TextIO) -> int:
156157
total_messages = len(pr_messages)
157158
for index, msg in enumerate(pr_messages, start=1):
158159
subject = msg.splitlines()[0] if msg else "<empty commit message>"
160+
command_args = ["--message"]
161+
if index > 1:
162+
command_args.append("--no-banner")
163+
164+
output_prefix = f"\n--- Commit {index}/{total_messages}: {subject}\n"
165+
if index > 1:
166+
output_prefix = (
167+
f"{COMMIT_SECTION_SEPARATOR}"
168+
f"--- Commit {index}/{total_messages}: {subject}\n"
169+
)
170+
159171
has_failure = (
160172
run_check_command(
161-
["--message"],
173+
command_args,
162174
result_file,
163175
input_text=msg,
164-
output_prefix=f"\n--- Commit {index}/{total_messages}: {subject}\n",
176+
output_prefix=output_prefix,
165177
)
166178
!= 0
167179
or has_failure

main_test.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,39 @@ def test_empty_list(self):
126126
self.assertEqual(rc, 0)
127127
mock_run.assert_not_called()
128128

129+
def test_second_and_later_messages_use_no_banner(self):
130+
results = [
131+
MagicMock(returncode=1, stdout="Commit rejected.\n"),
132+
MagicMock(returncode=1, stdout="Type subject_imperative check failed\n"),
133+
]
134+
with patch("main.subprocess.run", side_effect=results) as mock_run:
135+
main.run_pr_message_checks(["bad first", "bad second"], io.StringIO())
136+
137+
self.assertEqual(
138+
mock_run.call_args_list[0][0][0], ["commit-check", "--message"]
139+
)
140+
self.assertEqual(
141+
mock_run.call_args_list[1][0][0],
142+
["commit-check", "--message", "--no-banner"],
143+
)
144+
145+
def test_second_message_prefix_uses_separator(self):
146+
results = [
147+
MagicMock(returncode=1, stdout="Commit rejected.\n"),
148+
MagicMock(returncode=1, stdout="Type subject_imperative check failed\n"),
149+
]
150+
result_file = io.StringIO()
151+
with patch("main.subprocess.run", side_effect=results):
152+
main.run_pr_message_checks(["bad first", "bad second"], result_file)
153+
154+
output = result_file.getvalue()
155+
self.assertIn("\n--- Commit 1/2: bad first\nCommit rejected.\n", output)
156+
self.assertIn(
157+
f"{main.COMMIT_SECTION_SEPARATOR}--- Commit 2/2: bad second\n",
158+
output,
159+
)
160+
self.assertIn("Type subject_imperative check failed\n", output)
161+
129162

130163
class TestRunOtherChecks(unittest.TestCase):
131164
def test_empty_args_returns_zero(self):

0 commit comments

Comments
 (0)