Skip to content

Commit

Permalink
Fix: Ignore invalid versions in tag when determining last release
Browse files Browse the repository at this point in the history
Not all tags may be valid versions. Therefore don't fail to determine
the last release version when showing release information and creating
a release.
  • Loading branch information
bjoernricks committed Jan 12, 2024
1 parent 415878e commit 5ec3b88
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
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

0 comments on commit 5ec3b88

Please sign in to comment.