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

Update to highest toversion applicable to the current marketplace #4208

Merged
merged 9 commits into from
Apr 9, 2024
4 changes: 4 additions & 0 deletions .changelog/4208.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
changes:
- description: Fix metadata (i.e. description) for XSOAR6 marketplace.
type: fix
pr_number: 4208
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from pytest import MonkeyPatch

from demisto_sdk.commands.common.constants import (
DEFAULT_CONTENT_ITEM_TO_VERSION,
PACKS_DIR,
XSOAR_AUTHOR,
XSOAR_SUPPORT,
Expand All @@ -24,6 +25,9 @@
PackContentItems,
)
from demisto_sdk.commands.content_graph.objects.pack_metadata import PackMetadata
from demisto_sdk.commands.content_graph.tests.create_content_graph_test import (
mock_integration,
)
from TestSuite.test_tools import ChangeCWD, str_in_call_args_list

TEST_DATA = src_root() / "tests" / "test_files"
Expand Down Expand Up @@ -448,3 +452,81 @@ def test__enhance_pack_properties__internal_and_external(
content_items=PackContentItems(), # type: ignore
)
assert my_instance.version_info == expected


@pytest.mark.parametrize(
"marketplace_version, current_fromversion, new_fromversion, current_toversion, new_toversion, expected_toversion",
[
(MarketplaceVersions.XSOAR, "5.5.0", "8.0.0", "7.9.9", "8.2.0", "7.9.9"),
(MarketplaceVersions.XSOAR, "5.5.0", "6.5.0", "7.2.0", "7.9.9", "7.9.9"),
(
MarketplaceVersions.XSOAR,
"5.5.0",
"6.5.0",
"7.9.9",
DEFAULT_CONTENT_ITEM_TO_VERSION,
"",
),
(MarketplaceVersions.XSOAR_SAAS, "5.5.0", "8.0.0", "6.2.0", "8.5.0", "8.5.0"),
],
)
def test_replace_item_if_has_higher_toversion(
marketplace_version,
current_fromversion,
new_fromversion,
current_toversion,
new_toversion,
expected_toversion,
):
"""Tests the _replace_item_if_has_higher_toversion
updates to the highest version supported by the MarketplaceVersions.XSOAR
ARGS:
marketplace_version: MarketplaceVersions the flow is running on.
current_fromversion: current fromversion of content item in the pack metadata
new_fromversion: the fromversion of content item in the pack metadata
current_toversion: current toversion of content item in the pack metadata
new_toversion: a new toversion of content item
expected_toversion
Given:
- a Pack Metadata and an integration uploading to MarketplaceVersions.XSOAR
When:
- Calling the _replace_item_if_has_higher_toversion method.
Then:
- Verify that the content_item_metadata toversion is set correctly.
Scenario 1: On MarketplaceVersions.XSOAR should not update the metadata to a version higher than 7.9.9
Scenario 2: On MarketplaceVersions.XSOAR should update to higher version while still lower than the max 7.9.9
Scenario 3: On all marketplaces will update the metdata of content item toversion to empty if new toversion is DEFAULT_CONTENT_ITEM_TO_VERSION
Scenario 4: On MarketplaceVersions.XSOAR_SAAS should update metadata to the highest version.
"""
content_item_metadata = {
"fromversion": current_fromversion,
"toversion": current_toversion,
}
marketplace = marketplace_version
my_instance = PackMetadata(
name="test",
display_name="",
description="",
created="",
legacy=False,
support="",
url="",
email="",
eulaLink="",
price=0,
hidden=False,
commit="",
downloads=0,
keywords=[],
searchRank=0,
excludedDependencies=[],
videos=[],
modules=[],
) # type: ignore
integration = mock_integration()
integration.toversion = new_toversion
integration.fromversion = new_fromversion
my_instance._replace_item_if_has_higher_toversion(
integration, content_item_metadata, integration.summary(), marketplace
)
assert content_item_metadata["toversion"] == expected_toversion
16 changes: 15 additions & 1 deletion demisto_sdk/commands/content_graph/objects/pack_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ def _add_item_to_metadata_list(
)

self._replace_item_if_has_higher_toversion(
content_item, content_item_metadata, content_item_summary
content_item, content_item_metadata, content_item_summary, marketplace
)

else:
Expand Down Expand Up @@ -448,6 +448,7 @@ def _replace_item_if_has_higher_toversion(
content_item: ContentItem,
content_item_metadata: dict,
content_item_summary: dict,
marketplace: MarketplaceVersions,
):
"""
Replaces the content item metadata object in the content items metadata list
Expand All @@ -457,7 +458,20 @@ def _replace_item_if_has_higher_toversion(
content_item (ContentItem): The current content item to check.
content_item_metadata (dict): The existing content item metadata object in the list.
content_item_summary (dict): The current content item summary to update if needed.
marketplace (MarketplaceVersions): The marketplace to prepare the pack to upload.
"""
if marketplace == MarketplaceVersions.XSOAR:
if parse(content_item.fromversion) > Version("7.9.9"):
logger.debug(
f"Content_item: {content_item.name} has a fromversion {content_item.fromversion} higher than applicable for XSOAR6 marketplace. Skipping metadata update."
)
return
if parse(content_item_metadata["fromversion"]) >= Version("8.0.0"):
logger.debug(
f'Content item:{content_item_metadata["name"]} fromversion: {content_item_metadata["fromversion"]} is not compatible with XSOAR6 marketplace. Replacing'
)
content_item_metadata.update(content_item_summary)
self._set_empty_toversion_if_default(content_item_metadata)
if parse(content_item.toversion) > parse(
content_item_metadata["toversion"] or DEFAULT_CONTENT_ITEM_TO_VERSION
):
Expand Down