Skip to content
Open
Show file tree
Hide file tree
Changes from 6 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
4 changes: 4 additions & 0 deletions .changelog/5094.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
changes:
- description: Added RM118 to validate that internal scripts do not have a readme file.
type: internal
pr_number: 5094
2 changes: 2 additions & 0 deletions demisto_sdk/commands/validate/sdk_validation_config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ select = [
"RM113",
"RM114",
"RM115",
"RM118",
"CL100",
"PR101",
"CR102",
Expand Down Expand Up @@ -466,6 +467,7 @@ select = [
"RM115",
"RM116",
"RM117",
"RM118",
"CL100",
"PR101",
"CR102",
Expand Down
30 changes: 30 additions & 0 deletions demisto_sdk/commands/validate/tests/RM_validators_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@
from demisto_sdk.commands.validate.validators.RM_validators.RM117_readme_not_to_short import (
NotToShortReadmeValidator,
)
from demisto_sdk.commands.validate.validators.RM_validators.RM118_no_readme_internal_scripts import (
NoReadmeInternalScripts,
)
from TestSuite.repo import ChangeCWD


Expand Down Expand Up @@ -1177,3 +1180,30 @@ def test_ImagePathIntegrationValidator_content_assets():
content_items
)
assert result[0].message == expected


def test_NoReadmeInternalScriptsValidator():
"""
Given:
- Script object that is internal and one that is not internal
When:
- run obtain_invalid_content_items method from NoReadmeInternalScriptsValidator
Then:
- Ensure that the internal script returns a ValidationResult with the correct message
- Ensure that no error is returned for normal script and internal script without README
"""
internal_script = create_script_object(
["isInternal"], ["true"], readme_content="readme"
)
normal_script = create_script_object(readme_content="readme")
expected_message = "The script 'myScript' is an internal script. Please remove the README.md file in the content item's directory."

results = NoReadmeInternalScripts().obtain_invalid_content_items([internal_script])
assert len(results) == 1
assert results[0].message == expected_message

internal_script.readme.exist = False
results = NoReadmeInternalScripts().obtain_invalid_content_items(
[internal_script, normal_script]
)
assert len(results) == 0
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from __future__ import annotations

from typing import Iterable, List

from demisto_sdk.commands.content_graph.objects.script import Script
from demisto_sdk.commands.content_graph.parsers.related_files import RelatedFileType
from demisto_sdk.commands.validate.validators.base_validator import (
BaseValidator,
ValidationResult,
)


class NoReadmeInternalScripts(BaseValidator[Script]):
error_code = "RM118"
description = "Validates that there's no readme file for internal scripts."
rationale = "Internal scripts should not have a visible readme in xsoar.pan.dev."
error_message = "The script '{0}' is an internal script. Please remove the README.md file in the content item's directory."
related_field = "readme"
related_file_type = [RelatedFileType.README]

def obtain_invalid_content_items(
self, content_items: Iterable[Script]
) -> List[ValidationResult]:
return [
ValidationResult(
validator=self,
message=self.error_message.format(content_item.name),
content_object=content_item,
)
for content_item in content_items
if (
getattr(content_item, "is_internal", False)
or getattr(content_item, "is_llm", False)
)
and content_item.readme.exist
]
Loading