Skip to content
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

Fix: Ignore invalid versions in tag when determining last release #956

Merged
merged 1 commit into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
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
8 changes: 7 additions & 1 deletion pontos/version/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from pontos.git import Git, TagSort
from pontos.git.git import DEFAULT_TAG_SORT_SUFFIX
from pontos.version.errors import VersionError

from .version import ParseVersionFuncType, Version

Expand Down Expand Up @@ -40,7 +41,12 @@ def get_last_release_versions(
for tag in tag_list:
last_release_version = tag.strip(git_tag_prefix)

version = parse_version(last_release_version)
try:
version = parse_version(last_release_version)
except VersionError:
# be safe and ignore invalid versions
continue

if version.is_pre_release and ignore_pre_releases:
continue

Expand Down
26 changes: 16 additions & 10 deletions tests/version/test_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from unittest.mock import patch

from pontos.git.git import Git
from pontos.version.errors import VersionError
from pontos.version.helper import (
get_last_release_version,
get_last_release_versions,
Expand Down Expand Up @@ -116,11 +115,18 @@ def test_invalid_version(self, git_mock):
]

it = get_last_release_versions(SemanticVersioningScheme.parse_version)
next(it)

with self.assertRaisesRegex(
VersionError, "3.55a1 is not valid SemVer string"
):
version = next(it)
self.assertEqual(
version, SemanticVersioningScheme.parse_version("2.0.0")
)

version = next(it)
self.assertEqual(
version, SemanticVersioningScheme.parse_version("1.0.0")
)

with self.assertRaises(StopIteration):
next(it)


Expand Down Expand Up @@ -192,12 +198,12 @@ def test_get_last_release_version_tag_name(self, git_mock):
@patch("pontos.version.helper.Git", spec=Git)
def test_invalid_version(self, git_mock):
git_interface = git_mock.return_value
git_interface.list_tags.return_value = ["1", "2", "3.55a1"]
git_interface.list_tags.return_value = ["1.0.0", "2.0.0", "3.55a1"]

with self.assertRaisesRegex(
VersionError, "3.55a1 is not valid SemVer string"
):
get_last_release_version(SemanticVersioningScheme.parse_version)
self.assertEqual(
get_last_release_version(SemanticVersioningScheme.parse_version),
SemanticVersioningScheme.parse_version("2.0.0"),
)

@patch("pontos.version.helper.Git", spec=Git)
def test_success_with_invalid_version(self, git_mock):
Expand Down