Skip to content

Commit

Permalink
JiraV3 Mirror Out (demisto#35790)
Browse files Browse the repository at this point in the history
* the fix

* updated release notes

* pre-commit fixes

* changed solution

* changed solution

* fixed cr notes
  • Loading branch information
AradCarmi authored Aug 8, 2024
1 parent 0d04698 commit 00e0e44
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
21 changes: 14 additions & 7 deletions Packs/Jira/Integrations/JiraV3/JiraV3.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import demistomock as demisto # noqa: F401
from CommonServerPython import * # noqa: F401


from abc import ABCMeta
from collections.abc import Callable
from collections import defaultdict
Expand All @@ -10,6 +9,7 @@
import hashlib
from copy import deepcopy
from mimetypes import guess_type

# Note: time.time_ns() is used instead of time.time() to avoid the precision loss caused by the float type.
# Source: https://docs.python.org/3/library/time.html#time.time_ns

Expand Down Expand Up @@ -1189,19 +1189,19 @@ def get_ticket_link_context(issue_data: Dict[str, Any]) -> Dict[str, str]:
@staticmethod
def get_assignee_context(issue_data: Dict[str, Any]) -> Dict[str, str]:
assignee = demisto.get(issue_data, 'fields.assignee', {}) or {}
return {'Assignee': f'{assignee.get("displayName","")}({assignee.get("emailAddress", "")})'
return {'Assignee': f'{assignee.get("displayName", "")}({assignee.get("emailAddress", "")})'
if assignee else ''}

@staticmethod
def get_creator_context(issue_data: Dict[str, Any]) -> Dict[str, str]:
creator = demisto.get(issue_data, 'fields.creator', {}) or {}
return {'Creator': f'{creator.get("displayName","")}({creator.get("emailAddress", "")})'
return {'Creator': f'{creator.get("displayName", "")}({creator.get("emailAddress", "")})'
if creator else ''}

@staticmethod
def get_reporter_context(issue_data: Dict[str, Any]) -> Dict[str, str]:
reporter = demisto.get(issue_data, 'fields.reporter', {}) or {}
return {'Reporter': f'{reporter.get("displayName","")}({reporter.get("emailAddress", "")})'
return {'Reporter': f'{reporter.get("displayName", "")}({reporter.get("emailAddress", "")})'
if reporter else ''}

@staticmethod
Expand Down Expand Up @@ -1531,11 +1531,18 @@ def create_issue_fields(client: JiraBaseClient, issue_args: Dict[str, str],
parsed_value = [{"name": component} for component in argToList(value)]
elif issue_arg in ['description', 'environment']:
parsed_value = text_to_adf(value) if isinstance(client, JiraCloudClient) else value
elif not (isinstance(value, dict | list)):
# If the value is not a list or a dictionary, we will try to parse it as a json object.
try:
parsed_value = json.loads(value)
except (json.JSONDecodeError, TypeError):
pass # Some values should not be in a JSON format so it maks sense for them to fail parsing.
dotted_string = issue_fields_mapper.get(issue_arg, '')
if not dotted_string and issue_arg.startswith('customfield'):
# This is used to deal with the case when the user creates a custom incident field, using
# the custom fields of Jira.
dotted_string = f'fields.{issue_arg}'

issue_fields |= create_fields_dict_from_dotted_string(
issue_fields=issue_fields, dotted_string=dotted_string, value=parsed_value or value)
return issue_fields
Expand Down Expand Up @@ -2622,8 +2629,8 @@ def get_id_by_attribute_command(client: JiraBaseClient, args: Dict[str, str]) ->

elif len(account_ids) > 1:
return CommandResults(readable_output=f'Multiple account IDs were found for attribute: {attribute}.\n'
f'Please try to provide the other attributes available - Email or DisplayName'
' (and Name in the case of Jira OnPrem).')
f'Please try to provide the other attributes available - Email or DisplayName'
' (and Name in the case of Jira OnPrem).')
# If reached here, that means there is only one entry in account_ids that holds the right id for the given attribute
outputs['AccountId'] = account_ids[0]
return CommandResults(
Expand Down Expand Up @@ -3281,7 +3288,7 @@ def fetch_incidents(client: JiraBaseClient, issue_field_to_fetch_from: str, fetc
' "Issue index to start fetching incidents from" parameter.'
if smallest_issue_id
else 'The id that was configured does not exist in the Jira instance, '
'and the fetch query returned no results, therefore, could not start fetching.'
'and the fetch query returned no results, therefore, could not start fetching.'
) from e
# If we did no progress in terms of time (the created, or updated time stayed the same as the last fetch), we should keep the
# ids of the last fetch until progress is made, so we exclude them in the next fetch.
Expand Down
6 changes: 6 additions & 0 deletions Packs/Jira/ReleaseNotes/3_2_3.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

#### Integrations

##### Atlassian Jira v3

Fixed an issue where the mirroring out process incorrectly parsed custom fields.
2 changes: 1 addition & 1 deletion Packs/Jira/pack_metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "Atlassian Jira",
"description": "Use the Jira integration to manage issues and create Cortex XSOAR incidents from Jira projects.",
"support": "xsoar",
"currentVersion": "3.2.2",
"currentVersion": "3.2.3",
"author": "Cortex XSOAR",
"url": "https://www.paloaltonetworks.com/cortex",
"email": "",
Expand Down

0 comments on commit 00e0e44

Please sign in to comment.