diff --git a/pontos/version/helper.py b/pontos/version/helper.py index 993e23c60..a596d4625 100644 --- a/pontos/version/helper.py +++ b/pontos/version/helper.py @@ -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 @@ -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 diff --git a/tests/version/test_helper.py b/tests/version/test_helper.py index 27d39ce68..5ca0acdca 100644 --- a/tests/version/test_helper.py +++ b/tests/version/test_helper.py @@ -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, @@ -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) @@ -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):