Skip to content

Commit 94942c6

Browse files
committed
fix: simplify output handling in PR message checks and update test assertions
1 parent dbd6305 commit 94942c6

2 files changed

Lines changed: 5 additions & 13 deletions

File tree

main.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -156,19 +156,12 @@ def run_pr_message_checks(pr_messages: list[str], result_file: TextIO) -> int:
156156
"""
157157
has_failure = False
158158
emitted_failure_output = False
159-
total_messages = len(pr_messages)
160-
for index, msg in enumerate(pr_messages, start=1):
161-
subject = msg.splitlines()[0] if msg else "<empty commit message>"
159+
for msg in pr_messages:
162160
command_args = ["--message"]
163161
if emitted_failure_output:
164162
command_args.append("--no-banner")
165163

166-
output_prefix = f"--- Commit {index}/{total_messages}: {subject}\n"
167-
if emitted_failure_output:
168-
output_prefix = (
169-
f"{COMMIT_SECTION_SEPARATOR}"
170-
f"--- Commit {index}/{total_messages}: {subject}\n"
171-
)
164+
output_prefix = COMMIT_SECTION_SEPARATOR if emitted_failure_output else None
172165

173166
return_code = run_check_command(
174167
command_args,

main_test.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,12 @@ def test_single_message_pass(self):
101101
self.assertEqual(mock_run.call_args[1]["input"], "fix: something")
102102
self.assertEqual(result_file.getvalue(), "")
103103

104-
def test_failed_message_writes_header_and_output(self):
104+
def test_failed_message_writes_output(self):
105105
mock_result = MagicMock(returncode=1, stdout="Commit rejected.\n")
106106
result_file = io.StringIO()
107107
with patch("main.subprocess.run", return_value=mock_result):
108108
rc = main.run_pr_message_checks(["fix: something"], result_file)
109109
self.assertEqual(rc, 1)
110-
self.assertIn("--- Commit 1/1: fix: something", result_file.getvalue())
111110
self.assertIn("Commit rejected.", result_file.getvalue())
112111

113112
def test_multiple_messages_partial_failure(self):
@@ -169,9 +168,9 @@ def test_later_failure_prefix_uses_short_separator_without_extra_blank_lines(sel
169168
)
170169

171170
output = result_file.getvalue()
172-
self.assertIn("--- Commit 2/3: bad second\nCommit rejected.\n", output)
171+
self.assertIn("Commit rejected.\n", output)
173172
self.assertIn(
174-
f"{main.COMMIT_SECTION_SEPARATOR}--- Commit 3/3: bad third\n",
173+
f"{main.COMMIT_SECTION_SEPARATOR}Type subject_imperative check failed ==> bad third\n",
175174
output,
176175
)
177176
self.assertNotIn(

0 commit comments

Comments
 (0)