Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix handle values bug [Google Sheets] #30500

Merged
merged 9 commits into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 27 additions & 8 deletions Packs/GoogleSheets/Integrations/GoogleSheets/GoogleSheets.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import ast
import demistomock as demisto # noqa: F401
from CommonServerPython import * # noqa: F401
import json
Expand Down Expand Up @@ -105,15 +106,33 @@ def handle_values_input(values: str) -> list:
Returns:
(list) A list of lists of the values for this example [[1,2,3],[4,5,6]...]
"""
if not values:
raise ValueError('Wrong format of values entered, please check the documentation')
split_by_brackets = re.findall("\[(.*?)\]", values)
res_for_values_req = []
for element in split_by_brackets:
res_for_values_req.append(element.split(","))

if not res_for_values_req:
raise ValueError('Wrong format of values entered, please check the documentation')
# Validate that the user has entered valid values
if not values or not re.findall("\[(.*?)\]", values):
raise ValueError(
"Wrong format of values entered, please check the documentation"
)

# Converting the values the user entered into an array of arrays
values_as_array = ast.literal_eval(values)

# Checks whether the given values are a singular empty list, such as "[]".
# if that's the case, it will convert it to [[]] (a list of lists).
if isinstance(values_as_array, list) and len(values_as_array) == 0:
values_as_array = [values_as_array]

# Checks whether the given values are a single non-empty list, e.g., "[1,2,3]".
# in such a case, it will convert it to [[1,2,3]] (a list of lists).
elif not all(isinstance(item, list) for item in values_as_array):
values_as_array = [values_as_array]

# Handling all values including the `None` value to be string
res_for_values_req = []
for element in values_as_array:
if not element:
res_for_values_req.append([""])
continue
res_for_values_req.append([str(value) for value in element])

return res_for_values_req

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,12 @@ def test_create_list_id_title():

handle_values_input_parametrized = [
("[1,2,3],[4,5,6]", [['1', '2', '3'], ['4', '5', '6']]),
("[1,'test, for test',3],[4,5,6]", [['1', 'test, for test', '3'], ['4', '5', '6']]),
("[1,[2],3],[4,5,6]", [['1', '[2]', '3'], ['4', '5', '6']]),
("[1,2]", [['1', '2']]),
("[1]", [['1']]),
("[]", [['']])
("[]", [['']]),
("[[1,2,3],[4,5,6]]", [['1', '2', '3'], ['4', '5', '6']])
]


Expand Down
6 changes: 6 additions & 0 deletions Packs/GoogleSheets/ReleaseNotes/1_0_36.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

#### Integrations

##### Google Sheets
- Updated the Docker image to: *demisto/googleapi-python3:1.0.0.78508*.
- Fixed an issue where the ***google-sheets-value-append*** command incorrectly appended values to a spreadsheet.
2 changes: 1 addition & 1 deletion Packs/GoogleSheets/pack_metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "Google Sheets",
"description": "The Google Sheets API is a RESTful interface that lets you read and modify a spreadsheet's data. The most common uses of this API include the following tasks- create spreadsheets, read and write spreadsheets cells, update spreadsheet formatting",
"support": "xsoar",
"currentVersion": "1.0.35",
"currentVersion": "1.0.36",
"author": "Cortex XSOAR",
"url": "https://www.paloaltonetworks.com/cortex",
"email": "",
Expand Down
Loading