Skip to content

Commit

Permalink
added new
Browse files Browse the repository at this point in the history
  • Loading branch information
moishce committed Jun 2, 2024
1 parent cdbcdc5 commit 2145491
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
2 changes: 2 additions & 0 deletions demisto_sdk/commands/validate/validate_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ def run_validations(self) -> int:
logger.info("Starting validate items.")
for validator in self.validators:
logger.debug(f"Starting execution for {validator.error_code} validator.")
if self.validate_all:
validator.running_on_all_files_mode = True
if filtered_content_objects_for_validator := list(
filter(
lambda content_object: validator.should_run(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,44 @@ class DuplicatedScriptNameValidator(BaseValidator[ContentTypes]):
)
related_field = "name"
is_auto_fixable = False
running_on_all_files_mode = False


def is_valid(self, content_items: Iterable[ContentTypes]) -> List[ValidationResult]:
"""
Validate that there are no duplicate names of scripts
when the script name included `alert`.
"""
if self.running_on_all_files_mode:
return self.is_valid_all_files()
else:
return self.is_valid_list_files(content_items)

def is_valid_all_files(self) -> List[ValidationResult]:
"""
Validate that there are no duplicate names of scripts
when the script name included `alert`.
"""
print('all')
query_results = self.graph.get_duplicate_script_name_included_incident()

return [
ValidationResult(
validator=self,
message=self.error_message.format(
replace_incident_to_alert(script_name), script_name
),
content_object=file_path,
)
for script_name, file_path in query_results.items()
]

def is_valid_list_files(self, content_items: Iterable[ContentTypes]) -> List[ValidationResult]:
"""
Validate that there are no duplicate names of scripts
when the script name included `alert`.
"""
print('list')
file_paths_to_objects = {
str(content_item.path.relative_to(CONTENT_PATH)): content_item
for content_item in content_items
Expand All @@ -52,4 +84,4 @@ def is_valid(self, content_items: Iterable[ContentTypes]) -> List[ValidationResu
)
for script_name, file_path in query_results.items()
if file_path in file_paths_to_objects
]
]
2 changes: 2 additions & 0 deletions demisto_sdk/commands/validate/validators/base_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ class BaseValidator(ABC, BaseModel, Generic[ContentTypes]):
is_auto_fixable: ClassVar[bool] = False
graph_interface: ClassVar[ContentGraphInterface] = None
related_file_type: ClassVar[Optional[List[RelatedFileType]]] = None
running_on_all_files_mode = False

def get_content_types(self):
args = (get_args(self.__orig_bases__[0]) or get_args(self.__orig_bases__[1]))[0] # type: ignore
Expand Down Expand Up @@ -134,6 +135,7 @@ def should_run(
not is_support_level_support_validation(
self.error_code, support_level_dict, content_item.support_level
),

]
)

Expand Down

0 comments on commit 2145491

Please sign in to comment.