Skip to content
31 changes: 9 additions & 22 deletions dojo/jira/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -1223,29 +1223,16 @@ def get_jira_issue_from_jira(find):
return None


def issue_from_jira_is_active(issue_from_jira):
# "resolution":{
# "self":"http://www.testjira.com/rest/api/2/resolution/11",
# "id":"11",
# "description":"Cancelled by the customer.",
# "name":"Cancelled"
# },

# or
# "resolution": null

# or
# "resolution": "None"

if not hasattr(issue_from_jira.fields, "resolution"):
logger.debug(vars(issue_from_jira))
return True
def issue_status_category_is_done(status_category_key: str | None) -> bool:
return status_category_key == "done"

if not issue_from_jira.fields.resolution:
return True

# some kind of resolution is present that is not null or None
return issue_from_jira.fields.resolution == "None"
def issue_from_jira_is_active(issue_from_jira):
try:
statusCategoryKey = issue_from_jira.fields.status.statusCategory.key
except AttributeError:
statusCategoryKey = None
return not issue_status_category_is_done(statusCategoryKey)


def push_status_to_jira(obj, jira_instance, jira, issue, *, save=False):
Expand Down Expand Up @@ -1930,7 +1917,7 @@ def process_resolution_from_jira(
# classify "done" issues as risk-accepted, false-positive, or the
# default mitigated category (see jira_instance.accepted_resolutions
# and .false_positive_resolutions below).
resolved = status_category_key == "done"
resolved = issue_status_category_is_done(status_category_key)
jira_instance = get_jira_instance(finding)

if resolved:
Expand Down
31 changes: 31 additions & 0 deletions unittests/test_jira_helper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import logging
from unittest import TestCase
from unittest.mock import Mock

import dojo.jira.helper as jira_helper

logger = logging.getLogger(__name__)


class JIRAHelperTest(TestCase):
def _make_issue(self, status_category_key):
issue = Mock()
issue.fields.status.statusCategory.key = status_category_key
return issue

def test_issue_from_jira_is_active_with_new_status(self):
self.assertTrue(jira_helper.issue_from_jira_is_active(self._make_issue("new")))

def test_issue_from_jira_is_active_with_indeterminate_status(self):
self.assertTrue(jira_helper.issue_from_jira_is_active(self._make_issue("indeterminate")))

def test_issue_from_jira_is_active_with_done_status(self):
self.assertFalse(jira_helper.issue_from_jira_is_active(self._make_issue("done")))

def test_issue_from_jira_is_active_with_unknown_status(self):
"""Any key that is not 'done' is treated as active."""
self.assertTrue(jira_helper.issue_from_jira_is_active(self._make_issue("custom_status")))

def test_issue_from_jira_is_active_defaults_to_active_on_missing_attribute(self):
"""AttributeError anywhere in the fields.status.statusCategory.key chain defaults to active."""
self.assertTrue(jira_helper.issue_from_jira_is_active(Mock(spec=[])))
Loading