Skip to content

Commit

Permalink
Add function to define latest released version on Jira project
Browse files Browse the repository at this point in the history
  • Loading branch information
atarutin committed May 8, 2024
1 parent 436e043 commit b994d1e
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 0 deletions.
24 changes: 24 additions & 0 deletions integration/jira.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from jira import JIRA, JIRAError
from jira.resources import Component, Issue
from jira.client import ResultList
from jira.resources import Version

import jira_utils as ju

Expand Down Expand Up @@ -98,6 +99,29 @@ def can_release_version(self, project_code: str, version_name: str) -> bool:
return False
return True

def get_latest_released_version(self, project_code: str) -> Version:
"""
Get the latest version of a project been released.
Hotfixes are excluded.
:param project_code: project code
:return: latest version
"""
versions = sorted(
filter(
lambda v: not ju.is_jira_hotfix_version(v)
and ju.is_jira_released_version(v),
self.__j.project_versions(project_code),
),
key=lambda v: v.releaseDate,
reverse=True,
)

if len(versions) == 0:
raise ValueError("No versions found")

return versions[0]

def transition_issue(
self, task_name: str, status: str, comment: str = ""
) -> str:
Expand Down
21 changes: 21 additions & 0 deletions jira_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from validators.url import url
from jira.resources import Issue
from jira.resources import Version

from core.cvs import CodeRepository, GitCloudService
from core.nova_component import NovaComponent, NovaEmptyComponent
Expand Down Expand Up @@ -147,3 +148,23 @@ def filter_jira_issue(jira_issue, component_name) -> bool:
nova_name = component_name.strip().lower()

return jira_name == nova_name


def is_jira_released_version(version: Version) -> bool:
"""
Filter Jira version by release status.
:param version: Jira version.
:return: True if version was released, False otherwise.
"""
return version.released


def is_jira_hotfix_version(version: Version) -> bool:
"""
Filter Jira version by hotfix status.
:param version: Jira version.
:return: True if version is a hotfix, False otherwise.
"""
return "hotfix" in version.name.lower()
24 changes: 24 additions & 0 deletions tests/test_jira_hotfix_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
"""
"""

from unittest.mock import Mock
import pytest
from jira_utils import is_jira_hotfix_version


@pytest.mark.parametrize(
"version_name",
[
"hotfix-1.0.0",
"1.0.0-hotfix",
"1.0.0-hotfix-1",
"1.0.0-hotfix-2",
"1.0.0-hotfix-3",
"1.0.0-HoTfIx-4",
"hotfiX",
],
)
def test_when_version_name_contains_hotfix(version_name):
version = Mock()
version.name = version_name
assert is_jira_hotfix_version(version)
19 changes: 19 additions & 0 deletions tests/test_jira_released_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
"""
This module contains tests for the jira_utils module functions
which are used to work with versions.
"""

from unittest.mock import Mock
from jira_utils import is_jira_released_version


def test_when_version_is_not_released():
version = Mock()
version.released = False
assert not is_jira_released_version(version)


def test_when_version_is_released():
version = Mock()
version.released = True
assert is_jira_released_version(version)

0 comments on commit b994d1e

Please sign in to comment.