Skip to content

Commit 269dc9f

Browse files
committed
Refactor is_keep_in_sync_with_jira function to improve JIRA issue detection and sync logic
1 parent e2365c0 commit 269dc9f

1 file changed

Lines changed: 12 additions & 8 deletions

File tree

dojo/jira_link/helper.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -146,14 +146,18 @@ def _safely_get_obj_status_for_jira(obj: Finding | Finding_Group, *, isenforced:
146146

147147

148148
def is_keep_in_sync_with_jira(obj: Finding | Finding_Group, prefetched_jira_instance: JIRA_Instance = None):
149-
keep_in_sync_enabled = False
150-
if obj.has_jira_issue:
151-
# Determine if any automatic sync should occur
152-
jira_instance = prefetched_jira_instance or get_jira_instance(obj)
153-
if jira_instance:
154-
keep_in_sync_enabled = jira_instance.finding_jira_sync
155-
156-
return keep_in_sync_enabled
149+
"""Determine if any automatic sync should occur"""
150+
jira_issue_exists = False
151+
# Check for a jira issue on each type of object
152+
if isinstance(obj, Finding):
153+
jira_issue_exists = obj.has_jira_issue or (obj.finding_group and obj.finding_group.has_jira_issue)
154+
elif isinstance(obj, Finding_Group):
155+
jira_issue_exists = obj.has_jira_issue
156+
# Now determine if we need to pull the jira instance to check if sync is enabled
157+
# but only if there is a jira issue that would need syncing
158+
if jira_issue_exists and (jira_instance := prefetched_jira_instance or get_jira_instance(obj)) is not None:
159+
return jira_instance.finding_jira_sync
160+
return False
157161

158162

159163
# checks if a finding can be pushed to JIRA

0 commit comments

Comments
 (0)