-
Notifications
You must be signed in to change notification settings - Fork 76
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
Changes from 4 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
76c79ae
added rn103
bziser 5c3ed2f
added tests
bziser bc2a6d7
sdk_validation_config
bziser 005e3f3
Merge remote-tracking branch 'origin/master' into RN103+RN104_refactor
bziser 9b2a032
Merge remote-tracking branch 'origin/master' into RN103+RN104_refactor
bziser 1ae75fd
Apply suggestions from code review
bziser 503f187
Merge remote-tracking branch 'origin/master' into RN103+RN104_refactor
bziser f2b5ca8
Merge remote-tracking branch 'origin/RN103+RN104_refactor' into RN103…
bziser 358bf1f
code review changes
bziser f4960dd
changelog
bziser 014aff9
precommit
bziser cd7302b
Merge remote-tracking branch 'origin/master' into RN103+RN104_refactor
bziser db6b4f2
cr
bziser File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
] | ||
) |
50 changes: 50 additions & 0 deletions
50
demisto_sdk/commands/validate/validators/RN_validators/RN103_is_release_notes_filled_out.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 "\ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
|
||
] |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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