Skip to content

Commit

Permalink
Merge branch 'master' into ds-fix-ambig-upload-log
Browse files Browse the repository at this point in the history
  • Loading branch information
dorschw authored Dec 24, 2024
2 parents 1bc98f1 + ff1f244 commit 5c62f97
Show file tree
Hide file tree
Showing 26 changed files with 404 additions and 27 deletions.
4 changes: 4 additions & 0 deletions .changelog/4670.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
changes:
- description: Added validation to ensure every silent trigger points to a silent playbook, and vice versa.
type: feature
pr_number: 4670
4 changes: 4 additions & 0 deletions .changelog/4717.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
changes:
- description: Fixed an issue where RM114 falsely failed when it concatenated "Packs/" twice to the file path.
type: fix
pr_number: 4717
4 changes: 4 additions & 0 deletions .changelog/4720.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
changes:
- description: Exclude silent items from release notes validation.
type: feature
pr_number: 4720
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
4 changes: 4 additions & 0 deletions .changelog/4726.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
changes:
- description: Added support for Silent-Playbooks in the old-validate.
type: feature
pr_number: 4726
4 changes: 4 additions & 0 deletions .changelog/4728.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
changes:
- description: Changed the isSilent key to be lower case.
type: fix
pr_number: 4728
Original file line number Diff line number Diff line change
Expand Up @@ -699,6 +699,8 @@ def validate_readme_exists(self, validate_all: bool = False):
path_split = file_path.split(os.sep)
file_type = find_type(self.file_path, _dict=self.current_file, file_type="yml")
if file_type == FileType.PLAYBOOK:
if self.current_file.get("issilent"):
return True
to_replace = os.path.splitext(path_split[-1])[-1]
readme_path = file_path.replace(to_replace, "_README.md")
elif file_type in {FileType.SCRIPT, FileType.INTEGRATION}:
Expand Down
7 changes: 7 additions & 0 deletions demisto_sdk/commands/common/hook_validations/release_notes.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,16 @@ def are_release_notes_complete(self):

if find_type(file) in SKIP_RELEASE_NOTES_FOR_TYPES:
continue

elif (
checked_file_pack_name and checked_file_pack_name == self.pack_name
):
try:
_dict, file_type = get_dict_from_file(file)
if _dict.get("issilent"):
continue
except Exception:
pass
# Refer image and description file paths to the corresponding yml files
file = UpdateRN.change_image_or_desc_file_path(file)
update_rn_util = UpdateRN(
Expand Down
2 changes: 1 addition & 1 deletion demisto_sdk/commands/common/schemas/playbook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ mapping:
type: bool
deprecated:
type: bool
isSilent:
issilent:
type: bool
starttaskid:
type: str
Expand Down
2 changes: 1 addition & 1 deletion demisto_sdk/commands/common/schemas/trigger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ mapping:
description:
type: str
required: true
isSilent:
issilent:
type: bool
suggestion_reason:
type: str
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,4 @@ def version(self) -> int:

@property
def is_silent(self) -> bool:
return get_value(self.json_data, "isSilent", False)
return get_value(self.json_data, "issilent", False)
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def deprecated(self) -> bool:

@property
def is_silent(self) -> bool:
return get_value(self.yml_data, "isSilent", False)
return get_value(self.yml_data, "issilent", False)

@property
def description(self) -> Optional[str]:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,4 +291,4 @@ class StrictPlaybook(BaseStrictModel):
tests: Optional[List[str]] = None
role_name: Optional[List[str]] = Field(None, alias="rolename")
marketplaces: Optional[List[MarketplaceVersions]] = None
is_silent: Optional[bool] = Field(alias="isSilent")
is_silent: Optional[bool] = Field(alias="issilent")
4 changes: 4 additions & 0 deletions demisto_sdk/commands/validate/sdk_validation_config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ select = [
"PB126",
"PB127",
"PB130",
"PB131",
"PB132",
"PB114",
"BA100",
"BA101",
Expand Down Expand Up @@ -334,6 +336,8 @@ select = [
"PB119",
"PB127",
"PB130",
"PB131",
"PB132",
"BC100",
"BC101",
"BC102",
Expand Down
206 changes: 197 additions & 9 deletions demisto_sdk/commands/validate/tests/PB_validators_test.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import pytest

from demisto_sdk.commands.content_graph.objects.base_playbook import TaskConfig
from demisto_sdk.commands.content_graph.objects.pack_content_items import (
PackContentItems,
)
from demisto_sdk.commands.content_graph.objects.playbook import Playbook
from demisto_sdk.commands.validate.tests.test_tools import (
create_playbook_object,
create_trigger_object,
)
from demisto_sdk.commands.validate.validators.PB_validators.PB100_is_no_rolename import (
IsNoRolenameValidator,
Expand Down Expand Up @@ -66,6 +70,12 @@
from demisto_sdk.commands.validate.validators.PB_validators.PB130_is_silent_playbook import (
IsSilentPlaybookValidator,
)
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 @@ -1399,14 +1409,14 @@ def test_MarketplaceKeysHaveDefaultValidator(
def test_IsSilentPlaybookValidator(name, id, is_silent, result_len):
"""
Given:
case 1: isSilent = False, and name/id do not contain silent prefix.
case 2: isSilent = True, and name/id contain silent prefix.
case 3: isSilent = True, name contain and id do not contain silent prefix.
case 4: isSilent = True, id contain and name do not contain silent prefix.
case 5: isSilent = False, and name/id contain silent prefix.
case 6: isSilent = False, name contain and id do not contain silent prefix.
case 7: isSilent = False, id contain and name do not contain silent prefix.
case 8: isSilent = True, and name/id do not contain silent prefix.
case 1: issilent = False, and name/id do not contain silent prefix.
case 2: issilent = True, and name/id contain silent prefix.
case 3: issilent = True, name contain and id do not contain silent prefix.
case 4: issilent = True, id contain and name do not contain silent prefix.
case 5: issilent = False, and name/id contain silent prefix.
case 6: issilent = False, name contain and id do not contain silent prefix.
case 7: issilent = False, id contain and name do not contain silent prefix.
case 8: issilent = True, and name/id do not contain silent prefix.
When:
- calling IsSilentPlaybookValidator.obtain_invalid_content_items.
Expand All @@ -1417,9 +1427,187 @@ def test_IsSilentPlaybookValidator(name, id, is_silent, result_len):
playbook = create_playbook_object()
playbook.data["id"] = id
playbook.data["name"] = name
playbook.data["isSilent"] = is_silent
playbook.data["issilent"] = is_silent

invalid_content_items = IsSilentPlaybookValidator().obtain_invalid_content_items(
[playbook]
)
assert result_len == len(invalid_content_items)


class Pack:
content_items = PackContentItems()


@pytest.mark.parametrize(
"playbook_id, playbook_is_silent, trigger_playbook_id, trigger_is_silent, result_len",
[
(
"test",
True,
"test",
False,
1,
),
(
"test",
True,
"test",
True,
0,
),
(
"test1",
True,
"test2",
False,
1,
),
(
"test1",
True,
"test2",
True,
1,
),
(
"test1",
False,
"test1",
True,
0,
),
],
)
def test_IsSilentPlaybookRelationshipsValidator(
playbook_id, playbook_is_silent, trigger_playbook_id, trigger_is_silent, result_len
):
"""
Given:
- case 1: A silent trigger that points on a non-silent playbook.
- case 2: A silent trigger that points on a silent playbook.
- case 3: A silent trigger that points on a non-silent playbook that is not found.
- case 4: A silent trigger that points on a silent playbook that is not found.
- case 5: A non-silent trigger that points on a silent playbook.
When:
- Calling IsSilentPlaybookRelationshipsValidator for playbooks.
Then:
- Validate that only invalid items are returned.
"""
playbook_item = create_playbook_object()
playbook_item.pack = Pack()
playbook_item.pack.content_items.trigger.extend([create_trigger_object()])

playbook_item.data["id"] = playbook_id
playbook_item.is_silent = playbook_is_silent

playbook_item.pack.content_items.trigger[0].data["playbook_id"] = (
trigger_playbook_id
)
playbook_item.pack.content_items.trigger[0].is_silent = trigger_is_silent

invalid_content_items = (
IsSilentPlaybookRelationshipsValidator().obtain_invalid_content_items(
[playbook_item]
)
)
assert result_len == len(invalid_content_items)


@pytest.mark.parametrize(
"trigger_playbook_id, trigger_is_silent, playbook_id, playbook_is_silent, result_len",
[
(
"test",
True,
"test",
False,
1,
),
(
"test",
True,
"test",
True,
0,
),
(
"test1",
True,
"test2",
False,
1,
),
(
"test1",
True,
"test2",
True,
1,
),
(
"test1",
False,
"test1",
True,
0,
),
],
)
def test_IsSilentTriggerRelationshipsValidator(
trigger_playbook_id, trigger_is_silent, playbook_id, playbook_is_silent, result_len
):
"""
Given:
- case 1: A silent playbook that corresponds to a non-silent trigger.
- case 2: A silent playbook that corresponds to a silent trigger.
- case 3: A silent playbook that corresponds to a non-silent trigger that is not found.
- case 4: A silent playbook that corresponds to a silent trigger that is not found.
- case 5: A non-silent playbook that corresponds to a silent trigger.
When:
- Calling IsSilentPlaybookRelationshipsValidator for playbooks.
Then:
- Validate that only invalid items are returned.
"""
trigger_item = create_trigger_object()
trigger_item.pack = Pack()
trigger_item.pack.content_items.playbook.extend([create_playbook_object()])

trigger_item.data["playbook_id"] = trigger_playbook_id
trigger_item.is_silent = trigger_is_silent

trigger_item.pack.content_items.playbook[0].data["id"] = playbook_id
trigger_item.pack.content_items.playbook[0].is_silent = playbook_is_silent

invalid_content_items = (
IsSilentPlaybookRelationshipsValidator().obtain_invalid_content_items(
[trigger_item]
)
)
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
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
Loading

0 comments on commit 5c62f97

Please sign in to comment.