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 ds101 #4289

Merged
merged 13 commits into from
Jun 17, 2024
4 changes: 4 additions & 0 deletions .changelog/4289.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
changes:
- description: Added DS101 to the new validation format. Check if the beta disclaimer exists in the detailed description.
type: feature
pr_number: 4289
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def __init__(
super().__init__(path, pack_marketplaces, git_sha=git_sha)
self.script_info: Dict[str, Any] = self.yml_data.get("script", {})
self.category = self.yml_data["category"]
self.is_beta = self.yml_data.get("beta", False)
self.is_fetch = self.script_info.get("isfetch", False)
self.is_fetch_assets = self.script_info.get("isfetchassets", False)
self.is_fetch_events = self.script_info.get("isfetchevents", False)
Expand All @@ -43,7 +44,6 @@ def __init__(
self.is_remote_sync_in = self.script_info.get("isremotesyncin", False)
self.is_fetch_samples = self.script_info.get("isFetchSamples", False)
self.is_feed = self.script_info.get("feed", False)
self.is_beta = self.script_info.get("beta", False)
self.long_running = self.script_info.get("longRunning", False)
self.is_long_running = self.script_info.get("longRunning", False)
self.commands: List[CommandParser] = []
Expand Down
4 changes: 2 additions & 2 deletions 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", "DS107",
"DS100", "DS101", "DS107",
"SC100", "SC105", "SC106", "SC109",
"RM101", "RN103", "RM104", "RM105", "RM106", "RM109", "RM113", "RM114",
"CL100",
Expand All @@ -54,7 +54,7 @@ select = [
"LO107",
"PB100", "PB101","PB104", "PB123",
"BA100", "BA101", "BA105", "BA106", "BA110", "BA111", "BA113", "BA116", "BA118", "BA119", "BA126",
"DS100",
"DS100", "DS101",
"PA100", "PA101", "PA102", "PA103", "PA104", "PA105", "PA107", "PA108", "PA109", "PA111", "PA113", "PA115", "PA117", "PA118", "PA119", "PA120",
"PA121", "PA123", "PA125", "PA127", "PA130", "PA131", "PA132",
"DO100", "DO101", "DO102", "DO103", "DO104",
Expand Down
52 changes: 52 additions & 0 deletions demisto_sdk/commands/validate/tests/DS_validators_test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import pytest

from demisto_sdk.commands.common.constants import BETA_INTEGRATION_DISCLAIMER
from demisto_sdk.commands.validate.tests.test_tools import (
create_integration_object,
)
Expand Down Expand Up @@ -105,3 +106,54 @@ def test_IsDescriptionContainsDemistoWordValidator_is_invalid():
is_valid[0].message
== "Invalid keyword 'demisto' was found in lines: 1, 2, 4. For more information about the description file See: https://xsoar.pan.dev/docs/documentation/integration-description."
)


@pytest.mark.parametrize(
"is_beta_integration, description_file_content, result_len",
[
(
False,
"",
0,
),
(
True,
"",
1,
),
(
True,
BETA_INTEGRATION_DISCLAIMER,
0,
),
],
)
def test_IsValidBetaDescriptionValidator_is_valid(
is_beta_integration,
description_file_content,
result_len,
):
"""
Given
content_items iterables.
- Case 1: Not a beta integration, and no beta disclaimer.
- Case 3: A beta integration, and no beta disclaimer.
- Case 4: A beta integration, with a beta disclaimer.
When
- Calling the IsValidBetaDescriptionValidator is valid function.
Then
- Make sure that the validation is implemented correctly for beta integrations.
- Case 1: Shouldn't fail.
- Case 2: Should fail.
- Case 3: Shouldn't fail.
"""
from demisto_sdk.commands.validate.validators.DS_validators.DS101_is_valid_beta_description import (
IsValidBetaDescriptionValidator,
)

integration = create_integration_object()
integration.is_beta = is_beta_integration
integration.description_file.file_content_str = description_file_content

is_valid = IsValidBetaDescriptionValidator().is_valid([integration])
assert result_len == len(is_valid)
26 changes: 13 additions & 13 deletions demisto_sdk/commands/validate/tests/IN_validators_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -715,11 +715,11 @@ def test_IsValidCategoryValidator_is_valid(
(
[
create_integration_object(
paths=["commonfields.id", "script.beta"],
paths=["commonfields.id", "beta"],
values=["contain_beta", False],
),
create_integration_object(
paths=["commonfields.id", "script.beta"], values=["test", True]
paths=["commonfields.id", "beta"], values=["test", True]
),
],
0,
Expand All @@ -728,10 +728,10 @@ def test_IsValidCategoryValidator_is_valid(
(
[
create_integration_object(
paths=["commonfields.id", "script.beta"], values=["beta_test", True]
paths=["commonfields.id", "beta"], values=["beta_test", True]
),
create_integration_object(
paths=["commonfields.id", "script.beta"], values=["test beta", True]
paths=["commonfields.id", "beta"], values=["test beta", True]
),
],
2,
Expand Down Expand Up @@ -783,7 +783,7 @@ def test_IsIdContainBetaValidator_fix():
- Make sure the right ID was fixed correctly and that the right ID was returned.
"""
content_item = create_integration_object(
paths=["commonfields.id", "script.beta"], values=["test beta", True]
paths=["commonfields.id", "beta"], values=["test beta", True]
)
assert content_item.object_id == "test beta"
assert (
Expand All @@ -799,10 +799,10 @@ def test_IsIdContainBetaValidator_fix():
(
[
create_integration_object(
paths=["name", "script.beta"], values=["contain_beta", False]
paths=["name", "beta"], values=["contain_beta", False]
),
create_integration_object(
paths=["name", "script.beta"], values=["test", True]
paths=["name", "beta"], values=["test", True]
),
],
0,
Expand All @@ -811,10 +811,10 @@ def test_IsIdContainBetaValidator_fix():
(
[
create_integration_object(
paths=["name", "script.beta"], values=["beta_test", True]
paths=["name", "beta"], values=["beta_test", True]
),
create_integration_object(
paths=["name", "script.beta"], values=["test beta", True]
paths=["name", "beta"], values=["test beta", True]
),
],
2,
Expand Down Expand Up @@ -866,7 +866,7 @@ def test_IsNameContainBetaValidator_fix():
- Make sure the right ID was fixed correctly and that the right name was returned.
"""
content_item = create_integration_object(
paths=["name", "script.beta"], values=["test beta", True]
paths=["name", "beta"], values=["test beta", True]
)
assert content_item.name == "test beta"
assert (
Expand All @@ -882,10 +882,10 @@ def test_IsNameContainBetaValidator_fix():
(
[
create_integration_object(
paths=["display", "script.beta"], values=["contain beta", True]
paths=["display", "beta"], values=["contain beta", True]
),
create_integration_object(
paths=["display", "script.beta"], values=["test", False]
paths=["display", "beta"], values=["test", False]
),
],
0,
Expand All @@ -894,7 +894,7 @@ def test_IsNameContainBetaValidator_fix():
(
[
create_integration_object(
paths=["display", "script.beta"], values=["should fail", True]
paths=["display", "beta"], values=["should fail", True]
),
],
1,
Expand Down
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 (
BETA_INTEGRATION_DISCLAIMER,
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 IsValidBetaDescriptionValidator(BaseValidator[ContentTypes]):
error_code = "DS101"
description = "Check if beta disclaimer exists in detailed description"
rationale = "Need a disclaimer for beta integrations."
error_message = (
f"No beta disclaimer note was found. "
f"Please make sure the description file (<integration_name>_description.md)"
f" includes the beta disclaimer note. "
f"Add the following to the detailed description:\n{BETA_INTEGRATION_DISCLAIMER}"
)
related_field = "beta"
is_auto_fixable = False
expected_git_statuses = [GitStatuses.ADDED, GitStatuses.MODIFIED]
related_file_type = [RelatedFileType.DESCRIPTION_File]

def is_valid(self, content_items: Iterable[ContentTypes]) -> List[ValidationResult]:
return [
ValidationResult(
validator=self,
message=self.error_message,
content_object=content_item,
)
for content_item in content_items
if content_item.is_beta
and BETA_INTEGRATION_DISCLAIMER
not in content_item.description_file.file_content
]
Loading