Skip to content

Commit

Permalink
Merge pull request #74 from tarurar/tarurar/issue68
Browse files Browse the repository at this point in the history
Tarurar/issue68
  • Loading branch information
tarurar authored May 8, 2024
2 parents 436e043 + 11586da commit ce2dbcb
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 1 deletion.
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()
18 changes: 17 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,22 @@ def choose_component_from_release(rel: NovaRelease) -> Optional[NovaComponent]:
packages = release_repository.get_packages(
config.data["jira"]["project"]
)

if args.since:
print("Since date is specified as an argument.")
since = args.since
else:
print(
f"Since date is not specified, using latest released version date."
)
print(f"If you want to specify since date, use --since argument.")
latest_version = ji.get_latest_released_version(
config.data["jira"]["project"]
)
print(f"Latest released version detected: {latest_version.name}.")
since = latest_version.releaseDate
print(f"'Since' date to be used: {since}")

gi = GitIntegration()
all_tags_info: list[dict[str, str]] = []
counter = 0
Expand All @@ -173,7 +189,7 @@ def choose_component_from_release(rel: NovaRelease) -> Optional[NovaComponent]:
if package.repo is None:
continue

repo_all_tags = gi.list_tags(package.repo.url, args.since)
repo_all_tags = gi.list_tags(package.repo.url, since)

# filter out tags which are not related to packages, common rules
package_tags = list(
Expand Down
26 changes: 26 additions & 0 deletions tests/test_jira_hotfix_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
"""
This module contains tests for the is_jira_hotfix_version
function in the jira_utils module.
"""

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 ce2dbcb

Please sign in to comment.