Skip to content

Commit c116a18

Browse files
committed
fix looking for previous version
1 parent 3911547 commit c116a18

1 file changed

Lines changed: 12 additions & 8 deletions

File tree

changelog-analysis/get_change_log.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,18 +69,22 @@ def version_key(tag: str) -> tuple:
6969

7070
def get_base_tag(head_tag: str, owner: str = OWNER, repo: str = REPO,
7171
prefix: str = TAG_PREFIX) -> str:
72-
"""Return the release tag immediately before head_tag by version."""
72+
"""Return the latest released tag with a lower version than head_tag."""
7373
tags = get_all_release_tags(owner, repo, prefix)
7474

75-
try:
76-
idx = tags.index(head_tag)
77-
except ValueError:
78-
raise ValueError(f"Tag '{head_tag}' not found in {owner}/{repo}")
75+
def version_tuple(tag: str) -> tuple:
76+
try:
77+
return tuple(int(p) for p in tag.removeprefix(prefix).split("."))
78+
except ValueError:
79+
return (0,)
80+
81+
head_version = version_tuple(head_tag)
7982

80-
if idx + 1 >= len(tags):
81-
raise ValueError(f"No tag before '{head_tag}' found in {owner}/{repo}")
83+
for tag in tags: # already sorted descending
84+
if version_tuple(tag) < head_version:
85+
return tag
8286

83-
return tags[idx + 1]
87+
raise ValueError(f"No released tag before '{head_tag}' found in {owner}/{repo}")
8488

8589

8690
def is_ignored_path(path: str) -> bool:

0 commit comments

Comments
 (0)