Skip to content

Commit

Permalink
Change: Update get_last_release_version for tag_name filtering
Browse files Browse the repository at this point in the history
Allow to filter specific tags to get the last release version for a new
release.
  • Loading branch information
bjoernricks committed Apr 5, 2023
1 parent 2dfc162 commit 7ac71e1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
6 changes: 4 additions & 2 deletions pontos/version/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,22 @@ def get_last_release_version(
*,
git_tag_prefix: Optional[str] = "",
ignore_pre_releases: Optional[bool] = False,
tag_name: Optional[str] = None,
) -> Optional[Version]:
"""Get the last released Version from git.
Args:
git_tag_prefix: Git tag prefix to consider
ignore_pre_release: Ignore pre releases and only consider non pre
releases. Default is False.
tag_name: A pattern for filtering the tags. For example: "1.2.*"
Returns:
Last released git-tag as Version if tags were found
Last released git tag as Version if tags were found
or None
"""

tag_list = Git().list_tags(sort=TagSort.VERSION)
tag_list = Git().list_tags(sort=TagSort.VERSION, tag_name=tag_name)

while tag_list:
last_release_version = tag_list[-1]
Expand Down
12 changes: 12 additions & 0 deletions tests/version/test_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,15 @@ def test_get_last_release_version_no_non_pre_release(self, git_mock):
self.assertIsNone(
get_last_release_version(parse_version, ignore_pre_releases=True)
)

@patch("pontos.version.helper.Git", spec=Git)
def test_get_last_release_version_tag_name(self, git_mock):
git_interface = git_mock.return_value
git_interface.list_tags.return_value = [
"4.0.0rc1",
"4.0.1b1",
]
self.assertEqual(
get_last_release_version(parse_version, tag_name="4.0.*"),
Version("4.0.1b1"),
)

0 comments on commit 7ac71e1

Please sign in to comment.