Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin' into YR/fix-playbook-validation…
Browse files Browse the repository at this point in the history
…/CIAC-7105
  • Loading branch information
RosenbergYehuda committed Dec 21, 2023
2 parents 09e3cf7 + c34587a commit caea592
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 6 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog
## Unreleased
* Fixed an issue where the build number was incorrectly shown in XSOAR marketplace when using the **upload** command on external repositories via GitLab Pipelines.

## 1.25.0
* Added support to detect automatically the playground-id when running cli commands in xsoar-6.
* Added support to return war-room entries when running cli commands.
* Added support to automatically detect the correct file model by file path when reading files.
Expand Down
10 changes: 7 additions & 3 deletions demisto_sdk/commands/common/clients/xsoar/xsoar_api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1201,6 +1201,10 @@ def poll_playbook_state(
time.sleep(interval)
elapsed_time = int(time.time() - start_time)

raise RuntimeError(
f"status of the playbook {playbook_id} running in incident {incident_id} is {playbook_state}"
)
error = f"status of the playbook {playbook_id} running in incident {incident_id} is {playbook_state}"
if playbook_state == InvestigationPlaybookState.FAILED:
error = (
f"{error}, reason: {self.get_incident_playbook_failure(incident_id)}"
)

raise RuntimeError(error)
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,23 @@

import pytest
from packaging.version import parse
from pytest import MonkeyPatch

from demisto_sdk.commands.common.constants import (
PACKS_DIR,
XSOAR_AUTHOR,
XSOAR_SUPPORT,
XSOAR_SUPPORT_URL,
MarketplaceVersions,
)
from demisto_sdk.commands.common.content.objects.pack_objects import PackMetaData
from demisto_sdk.commands.common.content.objects.pack_objects.pack import Pack
from demisto_sdk.commands.common.content.objects_factory import path_to_pack_object
from demisto_sdk.commands.common.tools import src_root
from demisto_sdk.commands.content_graph.objects.pack_content_items import (
PackContentItems,
)
from demisto_sdk.commands.content_graph.objects.pack_metadata import PackMetadata
from TestSuite.test_tools import ChangeCWD

logger = logging.getLogger("demisto-sdk")
Expand Down Expand Up @@ -390,3 +396,50 @@ def test_load_user_metadata_bad_pack_metadata_file(repo, monkeypatch, caplog):
pack_1_metadata.load_user_metadata("Pack1", "Pack Number 1", pack_1.path, logger)

assert "Failed loading Pack Number 1 user metadata." in caplog.text


@pytest.mark.parametrize("is_external, expected", [(True, ""), (False, "123")])
def test__enhance_pack_properties__internal_and_external(
mocker, is_external, expected, monkeypatch: MonkeyPatch
):
"""Tests the _enhance_pack_properties method for internal and external packs.
Given:
- Pack object.
When:
- Calling the _enhance_pack_properties method.
Then:
- Verify that the version_info is set correctly.
Scenario 1: When the pack is external than the version_info should be empty.
Scenario 2: When the pack is internal than the version_info should be set to the CI_PIPELINE_ID env variable.
"""
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
mocker.patch(
"demisto_sdk.commands.content_graph.objects.pack_metadata.is_external_repository",
return_value=is_external,
)
monkeypatch.setenv("CI_PIPELINE_ID", "123")
my_instance._enhance_pack_properties(
marketplace=MarketplaceVersions.XSOAR,
pack_id="9",
content_items=PackContentItems(), # type: ignore
)
assert my_instance.version_info == expected
7 changes: 5 additions & 2 deletions demisto_sdk/commands/content_graph/objects/pack_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
)
from demisto_sdk.commands.common.handlers import JSON_Handler
from demisto_sdk.commands.common.logger import logger
from demisto_sdk.commands.common.tools import get_json
from demisto_sdk.commands.common.tools import get_json, is_external_repository
from demisto_sdk.commands.content_graph.common import ContentType, PackTags
from demisto_sdk.commands.content_graph.objects.content_item import ContentItem
from demisto_sdk.commands.content_graph.objects.pack import PackContentItems
Expand Down Expand Up @@ -85,7 +85,10 @@ def _enhance_pack_properties(
"""
self.tags = self._get_pack_tags(marketplace, pack_id, content_items)
self.author = self._get_author(self.author, marketplace)
self.version_info = os.environ.get("CI_PIPELINE_ID", "")
# We want to add the pipeline_id only if this is called within our repo.
self.version_info = (
"" if is_external_repository() else os.environ.get("CI_PIPELINE_ID", "")
)

def _format_metadata(
self,
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "demisto-sdk"
version = "1.24.0"
version = "1.25.0"
description = "\"A Python library for the Demisto SDK\""
authors = ["Demisto"]
license = "MIT"
Expand Down

0 comments on commit caea592

Please sign in to comment.