Skip to content

Commit

Permalink
Better handling of null values from SC. Corrected float conversion er…
Browse files Browse the repository at this point in the history
…rors #291
  • Loading branch information
SteveMcGrath committed Aug 13, 2024
1 parent b34c558 commit 9e59a7d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ __pycache__
.coverage
*.egg-info
/dist
/mapping.db
/base_config_tsc.toml
12 changes: 4 additions & 8 deletions tenb2jira/jira/field.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ def parse_value(self, finding: dict) -> Any:

# fetch the value using the defined attribute
value = finding.get(self.attribute)
if not value or value == '':
return None

# Next we will perform some formatting based on the expected values
# that Jira expects in the API.
Expand All @@ -148,21 +150,17 @@ def parse_value(self, finding: dict) -> Any:
case 'labels':
if isinstance(value, list):
return [str(i) for i in value]
elif value is None:
return []
else:
return [v.strip() for v in str(value).split(',')]

# float values should always be returned as a float.
case 'float':
return float(value) if value is not None else 0.0
return str(float(value))

# datetime values should be returned in a specific format. Here
# we attempt to normalize both timestamp and ISO formatted values
# info the Jira-specified format.
case 'datetime':
if value is None:
return None
try:
return arrow.get(value).format(DATETIME_FMT)
except arrow.parser.ParserError:
Expand All @@ -172,8 +170,6 @@ def parse_value(self, finding: dict) -> Any:
# we attempt to normalize both timestamp and ISO formatted values
# info the Jira-specified format.
case 'datepicker':
if value is None:
return None
try:
return arrow.get(value).format(DATE_FMT)
except arrow.parser.ParserError:
Expand All @@ -199,7 +195,7 @@ def parse_jql(self, value: Any) -> str:
# statement looking for any of the values. If there is only a single
# value, then we have to return a normal "contains" statement using
# the only item in the list.
if isinstance(value, list):
if isinstance(value, list) and len(value) > 0:
if len(value) > 1:
operator = 'in'
vals = [f'"{str(i)}"' for i in value]
Expand Down

0 comments on commit 9e59a7d

Please sign in to comment.