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
4 changes: 4 additions & 0 deletions .changelog/4275.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
changes:
- description: Combined RN103 and RN104 into the new validation format. Validates that the pack contains a full and valid release note file.
type: internal
pr_number: 4275
1 change: 1 addition & 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", "DS107",
"SC100", "SC105", "SC106", "SC109",
"RM104", "RM105", "RM106", "RM109", "RM113", "RM114",
"RN103",
"CL100",
"GF100", "GF101", "GF102",
"IF100", "IF101", "IF102", "IF103", "IF104", "IF105", "IF106", "IF116",
Expand Down
74 changes: 74 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,74 @@
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 complete the release notes and ensure all placeholders are filled in."
"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,58 @@
from __future__ import annotations

import re
from typing import Iterable, List

from demisto_sdk.commands.common.constants import GitStatuses
from demisto_sdk.commands.content_graph.objects.pack import Pack
from demisto_sdk.commands.content_graph.parsers.related_files import RelatedFileType
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."
rationale = "Meaningful, complete documentations make it easier for users to use the content."
error_message = (
"Please complete the release notes and ensure all placeholders are filled in."
"For common troubleshooting steps, please 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
expected_git_statuses = [GitStatuses.ADDED]

@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 (
rn_stripped_content := self.strip_exclusion_tag(
content_item.release_note.file_content
)
)
or any(
note in rn_stripped_content
for note in ["%%UPDATE_RN%%", "%%XSIAM_VERSION%%"]
)
]
Loading