diff --git a/.changelog/4058.yml b/.changelog/4058.yml new file mode 100644 index 0000000000..b5bfbe25b4 --- /dev/null +++ b/.changelog/4058.yml @@ -0,0 +1,4 @@ +changes: +- description: Fixed an issue where the *init* command sometimes failed in the dialogue when enter was pressed and not explicitly written false. + type: fix +pr_number: 4058 diff --git a/demisto_sdk/commands/common/files/file.py b/demisto_sdk/commands/common/files/file.py index 5606f19e5a..b1246d8cb9 100644 --- a/demisto_sdk/commands/common/files/file.py +++ b/demisto_sdk/commands/common/files/file.py @@ -282,7 +282,7 @@ def read_from_git_path( def __read_git_file(self, tag: str, from_remote: bool = True) -> Any: try: return self.load( - self._git_util.read_file_content( + self.git_util().read_file_content( self.path, commit_or_branch=tag, from_remote=from_remote ) ) diff --git a/demisto_sdk/commands/content_graph/objects/pack.py b/demisto_sdk/commands/content_graph/objects/pack.py index 2c7a3d78da..8641757fe5 100644 --- a/demisto_sdk/commands/content_graph/objects/pack.py +++ b/demisto_sdk/commands/content_graph/objects/pack.py @@ -584,3 +584,7 @@ def get_related_content(self) -> Dict[RelatedFileType, Dict]: @property def readme(self) -> str: return self.get_related_text_file(RelatedFileType.README) + + @property + def author_image_path(self) -> Path: + return Path(self.related_content[RelatedFileType.AUTHOR_IMAGE]["path"][0]) diff --git a/demisto_sdk/commands/init/initiator.py b/demisto_sdk/commands/init/initiator.py index 12f2f43b61..5635b3634e 100644 --- a/demisto_sdk/commands/init/initiator.py +++ b/demisto_sdk/commands/init/initiator.py @@ -551,7 +551,7 @@ def pack_init(self) -> bool: create_integration = str( input("\nDo you want to create an integration in the pack? Y/N ") ).lower() - if string_to_bool(create_integration): + if string_to_bool(create_integration, default_when_empty=False): if not self.marketplace == MarketplaceVersions.MarketplaceV2: is_same_category = str( input( diff --git a/demisto_sdk/commands/validate/tests/IM_validators_test.py b/demisto_sdk/commands/validate/tests/IM_validators_test.py new file mode 100644 index 0000000000..419b4e6636 --- /dev/null +++ b/demisto_sdk/commands/validate/tests/IM_validators_test.py @@ -0,0 +1,45 @@ +import pytest + +from demisto_sdk.commands.validate.tests.test_tools import ( + create_metadata_object, +) +from demisto_sdk.commands.validate.validators.IM_validators.IM108_author_image_is_empty import ( + AuthorImageIsEmptyValidator, +) + + +@pytest.mark.parametrize( + "content_items, expected_number_of_failures, expected_msgs", + [ + ([create_metadata_object()], 0, []), + ( + [create_metadata_object(image="")], + 1, + ["The author image should not be empty. Please provide a relevant image."], + ), + ], +) +def test_AuthorImageIsEmptyValidator_is_valid( + content_items, expected_number_of_failures, expected_msgs +): + """ + Given + content_items. + - Case 1: Author image not empty. + - Case 2: Author image is empty. + + When + - Calling the AuthorImageIsEmptyValidator is_valid function. + Then + - Make sure the right amount of pack author image failed, and that the right error message is returned. + - Case 1: Shouldn't fail. + - Case 2: Should fail. + """ + results = AuthorImageIsEmptyValidator().is_valid(content_items) + assert len(results) == expected_number_of_failures + assert all( + [ + result.message == expected_msg + for result, expected_msg in zip(results, expected_msgs) + ] + ) diff --git a/demisto_sdk/commands/validate/tests/test_tools.py b/demisto_sdk/commands/validate/tests/test_tools.py index dfe9e6b79d..3707f5f740 100644 --- a/demisto_sdk/commands/validate/tests/test_tools.py +++ b/demisto_sdk/commands/validate/tests/test_tools.py @@ -187,6 +187,7 @@ def create_metadata_object( values: Optional[List[Any]] = None, fields_to_delete: Optional[List[str]] = None, readme_text: str = "", + image: Optional[str] = None, ) -> PackMetadata: """Creating an pack_metadata object with altered fields from a default pack_metadata json structure. @@ -204,6 +205,8 @@ def create_metadata_object( PackParser.parse_ignored_errors = MagicMock(return_value={}) pack.pack_metadata.write_json(json_content) pack.readme.write_text(readme_text) + if image is not None: + pack.author_image.write(image) return BaseContent.from_path(Path(pack.path)) diff --git a/demisto_sdk/commands/validate/validators/IM_validators/IM108_author_image_is_empty.py b/demisto_sdk/commands/validate/validators/IM_validators/IM108_author_image_is_empty.py new file mode 100644 index 0000000000..c30f10c026 --- /dev/null +++ b/demisto_sdk/commands/validate/validators/IM_validators/IM108_author_image_is_empty.py @@ -0,0 +1,34 @@ +from __future__ import annotations + +from typing import Iterable, List + +from demisto_sdk.commands.common.constants import RelatedFileType +from demisto_sdk.commands.content_graph.objects.pack import Pack +from demisto_sdk.commands.validate.validators.base_validator import ( + BaseValidator, + ValidationResult, +) + +ContentTypes = Pack + + +class AuthorImageIsEmptyValidator(BaseValidator[ContentTypes]): + error_code = "IM108" + description = "Checks that the author image file is not empty" + error_message = ( + "The author image should not be empty. Please provide a relevant image." + ) + related_field = "image" + is_auto_fixable = False + related_file_type = [RelatedFileType.AUTHOR_IMAGE] + + def is_valid(self, content_items: Iterable[ContentTypes]) -> List[ValidationResult]: + return [ + ValidationResult( + validator=self, + message=self.error_message, + content_object=content_item, + ) + for content_item in content_items + if (content_item.author_image_path.stat().st_size == 0) + ]