Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Validate RM110 #4542

Merged
merged 7 commits into from
Sep 12, 2024
Merged
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/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
36 changes: 36 additions & 0 deletions demisto_sdk/commands/validate/tests/RM_validators_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,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 +860,36 @@ 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():
content_item = create_integration_object(
shmuel44 marked this conversation as resolved.
Show resolved Hide resolved
paths=["script.commands"],
values=[
[
{"name": "command1"},
{"name": "command2"},
]
],
readme_content="",
)
results = IsCommandsInReadmeValidator().obtain_invalid_content_items([content_item])
assert results[0].message == (
"The following commands appear in the YML file but not in the README file: command1, command2."
)
shmuel44 marked this conversation as resolved.
Show resolved Hide resolved


def test_IsCommandsInReadmeValidator_valid():
content_item = create_integration_object(
shmuel44 marked this conversation as resolved.
Show resolved Hide resolved
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