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

RN103 + RN104 to the new format validation #4275

Merged
merged 13 commits into from
Jun 4, 2024
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 @@ -34,6 +34,7 @@ select = [
"DS100",
"SC100", "SC105", "SC106", "SC109",
"RM104", "RM105", "RM109", "RM113", "RM114",
"RN103",
"CL100",
"GF100", "GF101", "GF102",
"IF100", "IF101", "IF102", "IF103", "IF104", "IF105", "IF106", "IF116",
Expand All @@ -60,6 +61,7 @@ select = [
"DO100", "DO101", "DO102", "DO103", "DO104",
"SC100", "SC105", "SC106", "SC109",
"RM104", "RM105", "RM113", "RM114",
"RN103",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think RN validations are necessary when not running in -g

"CL100",
"GF100", "GF101",
"IF100", "IF101", "IF102", "IF103", "IF104", "IF105", "IF106", "IF116",
Expand Down
72 changes: 72 additions & 0 deletions demisto_sdk/commands/validate/tests/RN_validators_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import pytest

from demisto_sdk.commands.validate.tests.test_tools import (
create_pack_object,
)
from demisto_sdk.commands.validate.validators.RN_validators.RN103_is_release_notes_filled_out import \
IsReleaseNotesFilledOutValidator


@pytest.mark.parametrize(
"content_items, expected_number_of_failures, expected_msgs",
[
(
[
create_pack_object(
paths=["version"],
values=["2.0.5"],
release_note_content="This is a valid rn.",

), # valid release_note
create_pack_object(
paths=["version"],
values=["2.0.5"],
release_note_content="",
), # empty release_note
create_pack_object(
paths=["version"],
values=["2.0.5"],
release_note_content="This is an invalid release note %%UPDATE_RN%%",
), # shouldn't pass as it has an invalid release note
create_pack_object(
paths=["version"],
values=["2.0.5"],
release_note_content="This is an invalid release note %%XSIAM_VERSION%%",
), # shouldn't pass as it has an invalid release note
],
3,
["Please finish filling out the release notes. For common troubleshooting steps, please "
"review the documentation found here: "
"https://xsoar.pan.dev/docs/integrations/changelog#common-troubleshooting-tips"],
),
],
)
def test_release_note_filled_out_validator(
content_items,
expected_number_of_failures,
expected_msgs,
):
"""
Given:
- content_items.
- Case 1: Four pack_metadatas:
- 1 pack with valid release note.
- 1 pack with an invalid empty release note.
- 1 pack with invalid release note.
- 1 pack with invalid release note.

When:
- Calling the IsReleaseNotesFilledOutValidator is_valid function.

Then:
- Make sure the right amount of pack metadatas failed, and that the right error message is returned.
"""

results = IsReleaseNotesFilledOutValidator().is_valid(content_items)
assert len(results) == expected_number_of_failures
assert all(
[
result.message == expected_msg
for result, expected_msg in zip(results, expected_msgs)
]
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
from __future__ import annotations

import re
from typing import Iterable, List

from demisto_sdk.commands.content_graph.parsers.related_files import RelatedFileType
from demisto_sdk.commands.content_graph.objects.pack import Pack
from demisto_sdk.commands.validate.validators.base_validator import (
BaseValidator,
ValidationResult,
)

ContentTypes = Pack


class IsReleaseNotesFilledOutValidator(BaseValidator[ContentTypes]):
error_code = "RN103"
description = "Validate that the pack contains a full release note file. "
bziser marked this conversation as resolved.
Show resolved Hide resolved
rationale = "Meaningful, complete documentations make it easier for users to use the content."
error_message = "Please finish filling out the release notes. For common troubleshooting steps, please "\
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's also make sure to tip about removing the placeholders.

"review the documentation found here: "\
"https://xsoar.pan.dev/docs/integrations/changelog#common-troubleshooting-tips"
related_field = "release_note"
is_auto_fixable = False
related_file_type = [RelatedFileType.RELEASE_NOTE]
bziser marked this conversation as resolved.
Show resolved Hide resolved

@staticmethod
def strip_exclusion_tag(release_notes_comments):
"""
Strips the exclusion tag (<!-- -->) from the release notes since release notes should never
be empty as this is poor user experience.
Return:
str. Cleaned notes with tags and contained notes removed.
"""
return re.sub(r"<!--.*?-->", "", release_notes_comments, flags=re.DOTALL)

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 not self.strip_exclusion_tag(content_item.release_note.file_content)
or any(
note in self.strip_exclusion_tag(content_item.release_note.file_content)
for note in ["%%UPDATE_RN%%", "%%XSIAM_VERSION%%"]
)
bziser marked this conversation as resolved.
Show resolved Hide resolved
]
Loading