Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit e89c6aa

Browse files
refactor(changelog): code cleanup
1 parent 49f26c4 commit e89c6aa

File tree

1 file changed

+29
-19
lines changed

1 file changed

+29
-19
lines changed

‎commitizen/changelog.py‎

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -305,27 +305,37 @@ def incremental_build(
305305
def get_smart_tag_range(
306306
tags: list[GitTag], newest: str, oldest: str | None = None
307307
) -> list[GitTag]:
308-
"""Smart because it finds the N+1 tag.
308+
"""Get a range of tags including the next tag after the oldest tag.
309309
310-
This is because we need to find until the next tag
310+
Args:
311+
tags: List of git tags
312+
newest: Name of the newest tag to include
313+
oldest: Name of the oldest tag to include. If None, same as newest.
314+
315+
Returns:
316+
List of tags from newest to oldest, plus one tag after oldest if it exists.
317+
For nonexistent end tag, returns all tags.
318+
For nonexistent start tag, returns tags starting from second tag.
319+
For nonexistent start and end tags, returns empty list.
311320
"""
312-
accumulator = []
313-
keep = False
314-
if not oldest:
315-
oldest = newest
316-
for index, tag in enumerate(tags):
317-
if tag.name == newest:
318-
keep = True
319-
if keep:
320-
accumulator.append(tag)
321-
if tag.name == oldest:
322-
keep = False
323-
try:
324-
accumulator.append(tags[index + 1])
325-
except IndexError:
326-
pass
327-
break
328-
return accumulator
321+
oldest = oldest or newest
322+
323+
names = set(tag.name for tag in tags)
324+
has_newest = newest in names
325+
has_oldest = oldest in names
326+
if not has_newest and not has_oldest:
327+
return []
328+
329+
if not has_newest:
330+
return tags[1:]
331+
332+
if not has_oldest:
333+
return tags
334+
335+
newest_idx = next(i for i, tag in enumerate(tags) if tag.name == newest)
336+
oldest_idx = next(i for i, tag in enumerate(tags) if tag.name == oldest)
337+
338+
return tags[newest_idx : oldest_idx + 2]
329339

330340

331341
def get_oldest_and_newest_rev(

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /