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

Validate silent-Playbook do not have a README file #4723

Merged
merged 10 commits into from
Dec 22, 2024
4 changes: 4 additions & 0 deletions .changelog/4723.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
changes:
- description: Added the **PB132** validation to ensure that silent playbooks do not have a README file.
type: feature
pr_number: 4723
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 @@ -147,6 +147,7 @@ select = [
"PB127",
"PB130",
"PB131",
"PB132",
"PB114",
"BA100",
"BA101",
Expand Down Expand Up @@ -336,6 +337,7 @@ select = [
"PB127",
"PB130",
"PB131",
"PB132",
"BC100",
"BC101",
"BC102",
Expand Down
29 changes: 29 additions & 0 deletions demisto_sdk/commands/validate/tests/PB_validators_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@
from demisto_sdk.commands.validate.validators.PB_validators.PB131_is_silent_playbook_relationships import (
IsSilentPlaybookRelationshipsValidator,
)
from demisto_sdk.commands.validate.validators.PB_validators.PB132_no_readme_for_silent_playbook import (
NoReadmeForSilentPlaybook,
)


@pytest.mark.parametrize(
Expand Down Expand Up @@ -1582,3 +1585,29 @@ def test_IsSilentTriggerRelationshipsValidator(
)
)
assert result_len == len(invalid_content_items)


def test_NoReadmeForSilentPlaybook():
"""
Given:
a silent playbook with/without a readme file.

When:
- calling NoReadmeForSilentPlaybook.obtain_invalid_content_items.

Then:
- Checks that it fails only when there is a readme.
"""
playbook = create_playbook_object()
playbook.is_silent = True
playbook.readme.exist = True
moishce marked this conversation as resolved.
Show resolved Hide resolved
invalid_content_items = NoReadmeForSilentPlaybook().obtain_invalid_content_items(
[playbook]
)
assert len(invalid_content_items) == 1

playbook.readme.exist = False
invalid_content_items = NoReadmeForSilentPlaybook().obtain_invalid_content_items(
[playbook]
)
assert len(invalid_content_items) == 0
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from __future__ import annotations

from typing import Iterable, List

from demisto_sdk.commands.content_graph.objects.playbook import Playbook
from demisto_sdk.commands.validate.validators.base_validator import (
BaseValidator,
ValidationResult,
)

ContentTypes = Playbook


class NoReadmeForSilentPlaybook(BaseValidator[ContentTypes]):
error_code = "PB132"
description = "A silent playbook is not allowed to have a README file."
rationale = "To ensure that silent playbooks do not appears in the documentation."
error_message = "A silent playbook is not allowed to have a README file."
related_field = "isSilent"
is_auto_fixable = False

def obtain_invalid_content_items(
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_silent and content_item.readme.exist
]
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@ def obtain_invalid_content_items(
content_object=content_item,
)
for content_item in content_items
if (not content_item.readme.exist)
if (not content_item.readme.exist) and (not content_item.is_silent)
]
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ def obtain_invalid_content_items(
)
for content_item in content_items
if (
not content_item.image.exist
or "doc_files" not in str(content_item.image.file_path)
(
not content_item.image.exist
or "doc_files" not in str(content_item.image.file_path)
)
and not content_item.is_silent
)
]
Loading