Skip to content

Commit

Permalink
New Validate RM110 (#4542)
Browse files Browse the repository at this point in the history
* rm110

* changelog

* added to config

* remove UT

* added the UT

* added docstring
  • Loading branch information
shmuel44 authored Sep 12, 2024
1 parent 2ccb4cd commit cf084fe
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .changelog/4542.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
changes:
- description: Moved RM110 validation to the new format. Ensuring all commands are documented in the README.
type: feature
pr_number: 4542
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 @@ -192,6 +192,7 @@ select = [
"RM104",
"RM105",
"RM107",
"RM110",
"RM113",
"RM114",
"CL100",
Expand Down Expand Up @@ -414,6 +415,7 @@ select = [
"RM106",
"RM107",
"RM109",
"RM110",
"RM113",
"RM114",
"CL100",
Expand Down
49 changes: 49 additions & 0 deletions demisto_sdk/commands/validate/tests/RM_validators_test.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import more_itertools
import pytest

from demisto_sdk.commands.common.tools import find_pack_folder
Expand Down Expand Up @@ -36,6 +37,9 @@
from demisto_sdk.commands.validate.validators.RM_validators.RM109_is_readme_exists import (
IsReadmeExistsValidator,
)
from demisto_sdk.commands.validate.validators.RM_validators.RM110_is_commands_in_readme import (
IsCommandsInReadmeValidator,
)
from demisto_sdk.commands.validate.validators.RM_validators.RM113_is_contain_copy_right_section import (
IsContainCopyRightSectionValidator,
)
Expand Down Expand Up @@ -857,3 +861,48 @@ def test_get_command_context_path_from_readme_file_multiple_commands():
"command2:\nThe following outputs are missing from yml: Test.Path3\nThe following outputs are missing from readme: Test.Path4\n"
in results[0].message
)


def test_IsCommandsInReadmeValidator_not_valid():
"""
Given: An integration object with commands 'command1' and 'command2'
When: The README content is empty
Then: The IsCommandsInReadmeValidator should return a single result with a message
indicating that the commands are missing from the README file
"""
content_item = create_integration_object(
paths=["script.commands"],
values=[
[
{"name": "command1"},
{"name": "command2"},
]
],
readme_content="",
)
results = IsCommandsInReadmeValidator().obtain_invalid_content_items([content_item])
assert more_itertools.one(results), "The validator should return a single result"
assert results[0].message == (
"The following commands appear in the YML file but not in the README file: command1, command2."
)


def test_IsCommandsInReadmeValidator_valid():
"""
Given: An integration object with commands 'command1' and 'command2'
When: The README content includes both command names
Then: The IsCommandsInReadmeValidator should not report any invalid content items
"""
content_item = create_integration_object(
paths=["script.commands"],
values=[
[
{"name": "command1"},
{"name": "command2"},
]
],
readme_content="command1, command2",
)
assert not IsCommandsInReadmeValidator().obtain_invalid_content_items(
[content_item]
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
from __future__ import annotations

from typing import Iterable, List

from demisto_sdk.commands.common.constants import GitStatuses
from demisto_sdk.commands.content_graph.objects.integration import Integration
from demisto_sdk.commands.content_graph.parsers.related_files import RelatedFileType
from demisto_sdk.commands.validate.validators.base_validator import (
BaseValidator,
ValidationResult,
)

ContentTypes = Integration
COMMANDS_EXCLUDED_FROM_README_DOCUMENTATION = [
"get-mapping-fields",
"xsoar-search-incidents",
"xsoar-get-incident",
"get-remote-data",
"update-remote-data",
"get-modified-remote-data",
"update-remote-system",
]


class IsCommandsInReadmeValidator(BaseValidator[ContentTypes]):
error_code = "RM110"
description = "Validates that all commands are mentioned in the README file"
rationale = "Ensuring all commands are documented in the README helps users understand the available functionality"
error_message = (
"The following commands appear in the YML file but not in the README file: {}."
)
related_field = "commands"
is_auto_fixable = False
related_file_type = [RelatedFileType.README]
expected_git_statuses = [GitStatuses.ADDED, GitStatuses.MODIFIED]

def obtain_invalid_content_items(
self, content_items: Iterable[ContentTypes]
) -> List[ValidationResult]:
results = []
for content_item in content_items:
undocumented_commands = [
command.name
for command in content_item.commands
if command.name not in content_item.readme.file_content
and command.name not in COMMANDS_EXCLUDED_FROM_README_DOCUMENTATION
and not command.deprecated
and not command.name.endswith("get-indicators")
]
if undocumented_commands:
results.append(
ValidationResult(
validator=self,
message=self.error_message.format(
", ".join(undocumented_commands)
),
content_object=content_item,
)
)
return results

0 comments on commit cf084fe

Please sign in to comment.