Skip to content

Commit eea3bb8

Browse files
yjawLee-W
authored andcommitted
fix(commit): fix some code and test according to suggestions
1 parent be40510 commit eea3bb8

8 files changed

Lines changed: 15 additions & 14 deletions

commitizen/cli.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,6 @@ def __call__(
168168
{
169169
"name": ["--body-length-limit"],
170170
"type": int,
171-
"default": 0,
172171
"help": "Set the length limit of the commit body. Commit message in body will be rewrapped to this length; 0 for no limit.",
173172
},
174173
{

commitizen/commands/commit.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
import shutil
66
import subprocess
77
import tempfile
8-
from pathlib import Path
98
import textwrap
109
from itertools import chain
10+
from pathlib import Path
1111
from typing import TYPE_CHECKING, TypedDict
1212

1313
import questionary
@@ -106,7 +106,7 @@ def _validate_subject_length(self, message: str) -> None:
106106

107107
def _wrap_body(self, message: str) -> str:
108108
"""
109-
Wrap the body of the commit message to the specified length.
109+
Wrap the body of the commit message to the --body-length-limit length.
110110
"""
111111

112112
body_length_limit = self.arguments.get(
@@ -120,11 +120,11 @@ def _wrap_body(self, message: str) -> str:
120120
if len(lines) < 3:
121121
return message
122122

123-
# First line is subject, second is blank line, rest is body
124-
wrapped_body_lines = [
123+
# First line is subject, second is blank line, rest are body lines
124+
wrapped_body_lines = chain.from_iterable(
125125
textwrap.wrap(line, width=body_length_limit) for line in lines[2:]
126-
]
127-
return "\n".join(chain(lines[:2], chain.from_iterable(wrapped_body_lines)))
126+
)
127+
return "\n".join(chain(lines[:2], wrapped_body_lines))
128128

129129
def manual_edit(self, message: str) -> str:
130130
editor = git.get_core_editor()

tests/commands/test_commit_command.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -386,8 +386,8 @@ def test_commit_command_with_config_message_length_limit(
386386
id="wrapping",
387387
),
388388
pytest.param(
389-
"Line1 that is very long and exceeds the limit\nLine2 that is very long and exceeds the limit\nLine3 that is very long and exceeds the limit",
390-
72,
389+
"Line1 is shorter than the limit but has newline\nLine2 is shorter than the limit but has newline\nLine3 is shorter than the limit but has newline",
390+
100,
391391
id="preserves_line_breaks",
392392
),
393393
pytest.param(
@@ -409,6 +409,7 @@ def test_commit_command_body_length_limit(
409409
success_mock: MockType,
410410
commit_mock,
411411
mocker: MockFixture,
412+
file_regression,
412413
):
413414
"""Parameterized test for body_length_limit feature with file regression."""
414415
mocker.patch(
@@ -426,6 +427,7 @@ def test_commit_command_body_length_limit(
426427
commands.Commit(config, {"body_length_limit": body_length_limit})()
427428
success_mock.assert_called_once()
428429
committed_message = commit_mock.call_args[0][0]
430+
file_regression.check(committed_message, extension=".txt")
429431

430432
lines = committed_message.split("\n")
431433
body_lines = lines[2:] # Skip subject and blank line

tests/commands/test_commit_command/test_commit_command_body_length_limit_disabled.txt renamed to tests/commands/test_commit_command/test_commit_command_body_length_limit_disabled_.txt

File renamed without changes.

tests/commands/test_commit_command/test_commit_command_body_length_limit_no_body.txt renamed to tests/commands/test_commit_command/test_commit_command_body_length_limit_no_body_.txt

File renamed without changes.

tests/commands/test_commit_command/test_commit_command_body_length_limit_preserves_line_breaks.txt

Lines changed: 0 additions & 5 deletions
This file was deleted.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
feat: add feature
2+
3+
Line1 is shorter than the limit but has newline
4+
Line2 is shorter than the limit but has newline
5+
Line3 is shorter than the limit but has newline

tests/commands/test_commit_command/test_commit_command_body_length_limit_wrapping.txt renamed to tests/commands/test_commit_command/test_commit_command_body_length_limit_wrapping_.txt

File renamed without changes.

0 commit comments

Comments
 (0)