Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

refactor(changelog): shorten condition expression and early return #1541

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: v4-9-0-test
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions commitizen/changelog.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ def incremental_build(
unreleased_start = metadata.unreleased_start
unreleased_end = metadata.unreleased_end
latest_version_position = metadata.latest_version_position

skip = False
output_lines: list[str] = []
for index, line in enumerate(lines):
Expand All @@ -260,9 +261,7 @@ def incremental_build(
skip = False
if (
latest_version_position is None
or isinstance(latest_version_position, int)
and isinstance(unreleased_end, int)
and latest_version_position > unreleased_end
or latest_version_position > unreleased_end
):
continue

Expand All @@ -271,13 +270,15 @@ def incremental_build(

if index == latest_version_position:
output_lines.extend([new_content, "\n"])

output_lines.append(line)
if not isinstance(latest_version_position, int):
if output_lines and output_lines[-1].strip():
# Ensure at least one blank line between existing and new content.
output_lines.append("\n")
output_lines.append(new_content)

if latest_version_position is not None:
return output_lines

if output_lines and output_lines[-1].strip():
# Ensure at least one blank line between existing and new content.
output_lines.append("\n")
output_lines.append(new_content)
return output_lines


Expand Down