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

Validation ds106 #4357

Merged
merged 10 commits into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from all 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/4357.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
changes:
- description: Added DS106 to the new validation format. "Check if the description file exist and the name is valid"
type: feature
pr_number: 4357
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 @@ -31,7 +31,7 @@ select = [
"IN161", "IN162",
"PB100", "PB101","PB104","PB118", "PB123",
"DO100", "DO101", "DO102", "DO103", "DO104", "DO105", "DO106",
"DS100", "DS101", "DS105", "DS107",
"DS100", "DS101", "DS105", "DS106", "DS107",
"SC100", "SC105", "SC106", "SC109",
"RM101", "RN103", "RM104", "RM105", "RM106", "RM109", "RM113", "RM114",
"CL100",
Expand Down
40 changes: 40 additions & 0 deletions demisto_sdk/commands/validate/tests/DS_validators_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,3 +197,43 @@ def test_IsDescriptionContainsContribDetailsValidator_is_valid(

is_valid = IsDescriptionContainsContribDetailsValidator().is_valid([integration])
assert result_len == len(is_valid)


@pytest.mark.parametrize(
"is_file_exist, result_len",
[
(
True,
0,
),
(
False,
1,
),
],
)
def test_IsValidDescriptionNameValidator_is_valid(
is_file_exist,
result_len,
):
"""
Given
content_items iterables.
- Case 1: the description file exist.
- Case 2: the description file not exist.
When
- Calling the IsValidDescriptionNameValidator is valid function.
Then
- Make sure that the description file exist.
- Case 1: Shouldn't fail.
- Case 2: Should fail.
"""
from demisto_sdk.commands.validate.validators.DS_validators.DS106_is_valid_description_name import (
IsValidDescriptionNameValidator,
)

integration = create_integration_object()
integration.description_file.exist = is_file_exist

is_valid = IsValidDescriptionNameValidator().is_valid([integration])
assert result_len == len(is_valid)
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
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


class IsValidDescriptionNameValidator(BaseValidator[ContentTypes]):
error_code = "DS106"
description = "Check if the description file exist and the name is valid."
rationale = (
"We want to make sure all integrations have all required documentation"
" and that the file name is according to our standards."
)
error_message = (
"The description's file is missing or the file name is invalid - "
"make sure the name looks like the following: {0}."
)

is_auto_fixable = False
expected_git_statuses = [GitStatuses.RENAMED, GitStatuses.ADDED]
related_file_type = [RelatedFileType.DESCRIPTION_File]

def is_valid(self, content_items: Iterable[ContentTypes]) -> List[ValidationResult]:
return [
ValidationResult(
validator=self,
message=self.error_message.format(
content_item.description_file.file_path.name
),
content_object=content_item,
)
for content_item in content_items
if (not content_item.description_file.exist)
]