Skip to content

Commit

Permalink
validation RM106 (#4295)
Browse files Browse the repository at this point in the history
* validation RM106

* pre commit

* remove DS107

* adding to changelog

* fix space

* fixes

* remove pytest.mark.parametrize

* adding new line at end of file

* fixing build

* Apply suggestions from code review

Co-authored-by: Yuval Hayun <70104171+YuvHayun@users.noreply.github.com>

* cr fixes

* cr fixes

* cr fixes

* chageing it to git add and modiefied

* removing from path based validation to yuval request

* Update 4295.yml

---------

Co-authored-by: Yuval Hayun <70104171+YuvHayun@users.noreply.github.com>
  • Loading branch information
maimorag and YuvHayun committed May 27, 2024
1 parent fb05d37 commit 1929525
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 1 deletion.
4 changes: 4 additions & 0 deletions .changelog/4295.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
changes:
- description: ֹ"Converted the RM106 validation to the new format. The validation verifies that README doesn't contain the word 'demisto'".
type: feature
pr_number: 4295
2 changes: 1 addition & 1 deletion demisto_sdk/commands/validate/sdk_validation_config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ select = [
"DO100", "DO101", "DO102", "DO103", "DO104", "DO105", "DO106",
"DS100",
"SC100", "SC105", "SC106", "SC109",
"RM104", "RM105", "RM109", "RM113", "RM114",
"RM104", "RM105", "RM106", "RM109", "RM113", "RM114",
"CL100",
"GF100", "GF101", "GF102",
"IF100", "IF101", "IF102", "IF103", "IF104", "IF105", "IF106", "IF116",
Expand Down
51 changes: 51 additions & 0 deletions demisto_sdk/commands/validate/tests/RM_validators_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
from demisto_sdk.commands.validate.validators.RM_validators.RM105_is_pack_readme_not_equal_pack_description import (
IsPackReadmeNotEqualPackDescriptionValidator,
)
from demisto_sdk.commands.validate.validators.RM_validators.RM106_is_contain_demisto_word import (
IsContainDemistoWordValidator,
)
from demisto_sdk.commands.validate.validators.RM_validators.RM109_is_readme_exists import (
IsReadmeExistsValidator,
)
Expand Down Expand Up @@ -314,3 +317,51 @@ def test_IsReadmeExistsValidator_is_valid(
for result, expected_msg in zip(results, expected_msgs)
]
)


def test_IsContainDemistoWordValidator_is_valid():
"""
Given
content_items.
- Two valid pack_metadatas:
- 1 pack with valid readme text.
- 1 pack with an empty readme. When
- Calling the IsContainDemistoWordValidator is_valid function.
Then
- Make sure that the pack isn't failing.
- Should pass all.
"""
content_items = [
create_pack_object(readme_text="This is a valid readme."),
create_pack_object(readme_text=""),
]
results = IsContainDemistoWordValidator().is_valid(content_items)
expected_msg = []
assert len(results) == 0
assert all(
[
result.message == expected_msg
for result, expected_msg in zip(results, expected_msg)
]
)


def test_IsContainDemistoWordValidator_is_invalid():
"""
Given
content_items.
- One invalid pack_metadata with a readme that contains the word 'demisto'.
When
- Calling the IsContainDemistoWordValidator is_valid function.
Then
- Make sure the right amount of pack failed, and that the right error message is returned.
"""
content_items = [
create_pack_object(
readme_text="Invalid readme contains the word demistomock\ndemisto \ndemisto \ndemisto.\n mockdemisto."
)
]
expected_msg = "Invalid keyword 'demisto' was found in lines: 1, 2, 3, 4, 5. For more information about the README See https://xsoar.pan.dev/docs/documentation/readme_file."
results = IsContainDemistoWordValidator().is_valid(content_items)
assert len(results) == 1
assert results[0].message == expected_msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
from __future__ import annotations

from typing import Iterable, List, Union

from demisto_sdk.commands.common.constants import GitStatuses
from demisto_sdk.commands.common.tools import check_text_content_contain_sub_text
from demisto_sdk.commands.content_graph.objects.integration import Integration
from demisto_sdk.commands.content_graph.objects.pack import Pack
from demisto_sdk.commands.content_graph.objects.playbook import Playbook
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,
)

ContentTypes = Union[Pack, Integration, Script, Playbook]


class IsContainDemistoWordValidator(BaseValidator[ContentTypes]):
error_code = "RM106"
description = (
"Validate that none of the readme lines contains the the word 'demisto'."
)
rationale = (
"Ensure that the current name of the product is used rather than the old one."
)
error_message = "Invalid keyword 'demisto' was found in lines: {0}. For more information about the README See https://xsoar.pan.dev/docs/documentation/readme_file."
related_field = "readme"
is_auto_fixable = False
related_file_type = [RelatedFileType.README]
expected_git_statuses = [GitStatuses.ADDED, GitStatuses.MODIFIED]

def is_valid(self, content_items: Iterable[ContentTypes]) -> List[ValidationResult]:
return [
ValidationResult(
validator=self,
message=self.error_message.format(", ".join(lines_contain_demsito)),
content_object=content_item,
)
for content_item in content_items
if (
lines_contain_demsito := check_text_content_contain_sub_text(
sub_text_list=["demisto"],
is_lower=True,
text=content_item.readme.file_content,
)
)
]

0 comments on commit 1929525

Please sign in to comment.