Skip to content

Commit

Permalink
copy_fix_version_supports_versions_accross_projects (#18)
Browse files Browse the repository at this point in the history
* apply fix version as per name
* fix doc builder
  • Loading branch information
studioj authored Oct 27, 2021
1 parent 9f492d2 commit 940ec03
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 40 deletions.
1 change: 0 additions & 1 deletion .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ jobs:
- uses: ammaraskar/sphinx-action@master
with:
docs-folder: "docs/"
pre-build-command: "apt-get update && apt-get install -y git && pip install . pip install sphinx_rtd_theme"

build:

Expand Down
2 changes: 2 additions & 0 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
sphinx
sphinx_rtd_theme
8 changes: 3 additions & 5 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
# import sys
# sys.path.insert(0, os.path.abspath('.'))

import jira_agile_toolbox

# -- Project information -----------------------------------------------------

project = "jira-agile-toolbox"
Expand Down Expand Up @@ -54,6 +52,6 @@
html_style = "css/custom_width.css"
html_theme_options = {"body_max_width": "50%"}

version = jira_agile_toolbox.__version__
# The full version, including alpha/beta/rc tags.
release = version
# version = jira_agile_toolbox.__version__
# # The full version, including alpha/beta/rc tags.
# release = version
6 changes: 3 additions & 3 deletions jira_agile_toolbox/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ def _input_validation_labels(self, labels):
def copy_fix_version_from_epic_to_all_items_in_epic(self, epic, keep_already_present=True, jql_query=""):
"""
copies fixVersions from the epic to all 'Issues in Epic'
also applies to different projects as long as the version name is the same it works
:param epic: and epic key as a string or the epic as a jira.Issue
:type epic: str jira.Issue
Expand All @@ -286,11 +287,10 @@ def copy_fix_version_from_epic_to_all_items_in_epic(self, epic, keep_already_pre
[<JIRA Version: name='0.0.10', id='31063'>]
"""
jira_epic = epic if isinstance(epic, jira.Issue) else self._jira_client.issue(epic)
versions = [version.raw for version in jira_epic.fields.fixVersions]
versions = [{"name": version.name} for version in jira_epic.fields.fixVersions]
for issue in self.get_all_issues_in_epic(jira_epic, fields=["fixVersions"], jql_query=jql_query):

if keep_already_present:
for version in versions:
issue.add_field_value("fixVersions", version)
issue.add_field_value("fixVersions", {"name": version["name"]})
else:
issue.update(fields={"fixVersions": versions})
48 changes: 17 additions & 31 deletions tests/test_epic_interactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ def test_get_issues_from_epic_searches_for_the_right_epic_key(self):

# Then
self.assertEqual(self.jira_client.search_issues.return_value, result)
self.jira_client.search_issues.assert_called_with(f"'Epic Link' = PROJ001-001", maxResults=0)
self.jira_client.search_issues.assert_called_with("'Epic Link' = PROJ001-001", maxResults=0)

def test_get_issues_from_epic_can_filter_on_the_fields_to_retrieve_to_reduce_data_retrieval(self):
# Given
Expand All @@ -271,7 +271,7 @@ def test_get_issues_from_epic_can_filter_on_the_fields_to_retrieve_to_reduce_dat
jat.get_all_issues_in_epic("PROJ001-001", fields=["a_specific_field"])

# Then
self.jira_client.search_issues.assert_called_with(f"'Epic Link' = PROJ001-001", fields=["a_specific_field"], maxResults=0)
self.jira_client.search_issues.assert_called_with("'Epic Link' = PROJ001-001", fields=["a_specific_field"], maxResults=0)

def test_get_issues_from_epic_takes_a_string_field_or_a_list_of_fields(self):
# Given
Expand All @@ -288,7 +288,7 @@ def test_get_issues_from_epic_takes_a_string_field_or_a_list_of_fields(self):
jat.get_all_issues_in_epic("PROJ001-001", fields="a_specific_field")

# Then
self.jira_client.search_issues.assert_called_with(f"'Epic Link' = PROJ001-001", fields=["a_specific_field"], maxResults=0)
self.jira_client.search_issues.assert_called_with("'Epic Link' = PROJ001-001", fields=["a_specific_field"], maxResults=0)

def test_get_issues_from_epic_allows_to_filter_an_extra_jql_query(self):
# Given
Expand All @@ -306,7 +306,7 @@ def test_get_issues_from_epic_allows_to_filter_an_extra_jql_query(self):

# Then
self.jira_client.search_issues.assert_called_with(
f"'Epic Link' = PROJ001-001 AND project in (PROJ001,PROJ002)", fields=["a_specific_field"], maxResults=0
"'Epic Link' = PROJ001-001 AND project in (PROJ001,PROJ002)", fields=["a_specific_field"], maxResults=0
)


Expand All @@ -318,7 +318,7 @@ def test_copy_fix_version_from_epic_to_all_items_in_epic(self):
# Given
sub_issue1 = MockedJiraIssue(story_points=0)
version1 = Mock(spec=jira.resources.Version)
version1.raw = VERSION_RAW
version1.name = "JAT 0.0.9"
epic = MockedJiraIssue()
epic.fields.fixVersions = [version1]
epic.key = "PROJ001-001"
Expand All @@ -329,13 +329,13 @@ def test_copy_fix_version_from_epic_to_all_items_in_epic(self):
jat.copy_fix_version_from_epic_to_all_items_in_epic(epic)

# Then
sub_issue1.add_field_value.assert_called_with("fixVersions", version1.raw)
sub_issue1.add_field_value.assert_called_with("fixVersions", {"name": version1.name})

def test_copy_fix_version_from_epic_to_all_items_in_epic_searches_for_the_epic(self):
# Given
sub_issue1 = MockedJiraIssue(story_points=0)
version1 = Mock(spec=jira.resources.Version)
version1.raw = VERSION_RAW
version1.name = "JAT 0.0.9"
epic = MockedJiraIssue()
epic.fields.fixVersions = [version1]
epic.key = "PROJ001-001"
Expand All @@ -352,7 +352,7 @@ def test_copy_fix_version_from_epic_to_all_items_in_epic_searches_for_the_epic_a
# Given
sub_issue1 = MockedJiraIssue(story_points=0)
version1 = Mock(spec=jira.resources.Version)
version1.raw = VERSION_RAW
version1.name = "JAT 0.0.9"
epic = MockedJiraIssue()
epic.fields.fixVersions = [version1]
epic.key = "PROJ001-001"
Expand All @@ -370,16 +370,9 @@ def test_copy_fix_version_from_epic_to_all_items_in_epic_for_multiple_versions(s
# Given
sub_issue1 = MockedJiraIssue(story_points=0)
version1 = Mock(spec=jira.resources.Version)
version1.raw = VERSION_RAW
version1.name = "JAT 0.0.9"
version2 = Mock(spec=jira.resources.Version)
version2.raw = {
"self": "https://atlassian-jira.com/rest/api/2/version/31064",
"id": "31064",
"description": "",
"name": "JAT 0.0.10",
"archived": False,
"released": False,
}
version2.name = "JAT 0.0.10"
epic = MockedJiraIssue()
epic.fields.fixVersions = [version1, version2]
epic.key = "PROJ001-001"
Expand All @@ -390,22 +383,15 @@ def test_copy_fix_version_from_epic_to_all_items_in_epic_for_multiple_versions(s
jat.copy_fix_version_from_epic_to_all_items_in_epic(epic)

# Then
sub_issue1.add_field_value.assert_any_call("fixVersions", version1.raw)
sub_issue1.add_field_value.assert_any_call("fixVersions", version2.raw)
sub_issue1.add_field_value.assert_any_call("fixVersions", {"name": version1.name})
sub_issue1.add_field_value.assert_any_call("fixVersions", {"name": version2.name})

def test_copy_fix_version_from_epic_to_multiple_items_in_epic(self):
# Given
sub_issue1 = MockedJiraIssue()
sub_issue2 = MockedJiraIssue()
version1 = Mock(spec=jira.resources.Version)
version1.raw = {
"self": "https://atlassian-jira.com/rest/api/2/version/31063",
"id": "31063",
"description": "",
"name": "JAT 0.0.9",
"archived": False,
"released": True,
}
version1.name = "JAT 0.0.9"
epic = MockedJiraIssue()
epic.fields.fixVersions = [version1]
epic.key = "PROJ001-001"
Expand All @@ -416,14 +402,14 @@ def test_copy_fix_version_from_epic_to_multiple_items_in_epic(self):
jat.copy_fix_version_from_epic_to_all_items_in_epic(epic)

# Then
sub_issue1.add_field_value.assert_called_with("fixVersions", version1.raw)
sub_issue2.add_field_value.assert_called_with("fixVersions", version1.raw)
sub_issue1.add_field_value.assert_called_with("fixVersions", {"name": version1.name})
sub_issue2.add_field_value.assert_called_with("fixVersions", {"name": version1.name})

def test_copy_fix_version_from_epic_to_all_items_in_epic_dont_keep_already_present(self):
# Given
sub_issue1 = MockedJiraIssue(story_points=0)
version1 = Mock(spec=jira.resources.Version)
version1.raw = VERSION_RAW
version1.name = "JAT 0.0.9"
epic = MockedJiraIssue()
epic.fields.fixVersions = [version1]
epic.key = "PROJ001-001"
Expand All @@ -434,4 +420,4 @@ def test_copy_fix_version_from_epic_to_all_items_in_epic_dont_keep_already_prese
jat.copy_fix_version_from_epic_to_all_items_in_epic(epic, keep_already_present=False)

# Then
sub_issue1.update.assert_called_with(fields={"fixVersions": [version1.raw]})
sub_issue1.update.assert_called_with(fields={"fixVersions": [{"name": version1.name}]})

0 comments on commit 940ec03

Please sign in to comment.