Skip to content

Commit

Permalink
Validation ds106 (#4357)
Browse files Browse the repository at this point in the history
* DS106

* pre commit

* added changelog

* revert

* fixed cr comment

* pre commit

* revert

* revert

* revert
  • Loading branch information
moishce authored Jun 17, 2024
1 parent b33df35 commit 2fa7ee2
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 1 deletion.
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","PB103","PB104", "PB105", "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)
]

0 comments on commit 2fa7ee2

Please sign in to comment.