-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* new format * casefold moved * renamed * first run * add release notes to packs * a tiny bit prettier * added tests for ba125 * readme_content for tests * added ContentTypes pack * added path for the error message * format * fixed conflict * format * format * conflict fixed * added BA125 to use_git * Update demisto_sdk/commands/validate/validators/BA_validators/BA125_customer_facing_docs_disallowed_terms.py Co-authored-by: Yuval Hayun <70104171+YuvHayun@users.noreply.github.com> * Update demisto_sdk/commands/validate/validators/BA_validators/BA125_customer_facing_docs_disallowed_terms.py Co-authored-by: Yuval Hayun <70104171+YuvHayun@users.noreply.github.com> * Update demisto_sdk/commands/validate/tests/test_tools.py Co-authored-by: Yuval Hayun <70104171+YuvHayun@users.noreply.github.com> * mypy --------- Co-authored-by: dorschw <81086590+dorschw@users.noreply.github.com> Co-authored-by: Yuval Hayun <70104171+YuvHayun@users.noreply.github.com>
- Loading branch information
1 parent
f33937b
commit d2ce3b5
Showing
4 changed files
with
164 additions
and
1 deletion.
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
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
80 changes: 80 additions & 0 deletions
80
...commands/validate/validators/BA_validators/BA125_customer_facing_docs_disallowed_terms.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,80 @@ | ||
from __future__ import annotations | ||
|
||
from typing import Iterable, List, Union | ||
|
||
from demisto_sdk.commands.common.constants import GitStatuses | ||
from demisto_sdk.commands.content_graph.objects.integration import Integration | ||
from demisto_sdk.commands.content_graph.objects.pack import Pack | ||
from demisto_sdk.commands.content_graph.objects.playbook import Playbook | ||
from demisto_sdk.commands.content_graph.objects.script import Script | ||
from demisto_sdk.commands.content_graph.parsers.related_files import RelatedFileType | ||
from demisto_sdk.commands.validate.validators.base_validator import ( | ||
BaseValidator, | ||
ValidationResult, | ||
) | ||
|
||
ContentTypes = Union[Integration, Script, Playbook, Pack] | ||
|
||
disallowed_terms = [ # These terms are checked regardless for case (case-insensitive) | ||
"test-module", | ||
"test module", | ||
"long-running-execution", | ||
] | ||
|
||
|
||
class CustomerFacingDocsDisallowedTermsValidator(BaseValidator[ContentTypes]): | ||
error_code = "BA125" | ||
description = "Validate that customer facing docs and fields don't contain any internal terms that aren't clear for customers." | ||
rationale = "Ensure customer-facing docs avoid internal terms for clarity." | ||
error_message = ( | ||
"Found internal terms in a customer-facing documentation: found {terms}" | ||
) | ||
related_field = "" | ||
is_auto_fixable = False | ||
related_file_type = [ | ||
RelatedFileType.README, | ||
RelatedFileType.DESCRIPTION_File, | ||
RelatedFileType.RELEASE_NOTE, | ||
] | ||
expected_git_statuses = [GitStatuses.MODIFIED, GitStatuses.ADDED] | ||
|
||
def is_valid(self, content_items: Iterable[ContentTypes]) -> List[ValidationResult]: | ||
found_terms: dict[str, str] = {} | ||
return [ | ||
ValidationResult( | ||
validator=self, | ||
message=self.error_message.format( | ||
terms=self.format_error_message(found_terms) | ||
), | ||
content_object=content_item, | ||
) | ||
for content_item in content_items | ||
if self.find_disallowed_terms( | ||
self.get_related_files(content_item), found_terms | ||
) | ||
] | ||
|
||
def format_error_message(self, found_terms): | ||
return "\n".join( | ||
f"{', '.join(found_terms[file])} in {file}" for file in found_terms | ||
) | ||
|
||
def find_disallowed_terms(self, related_files, found_terms): | ||
for file in related_files: | ||
file_content = file.file_content.casefold() | ||
terms = [term for term in disallowed_terms if term in file_content] | ||
if terms: | ||
# Extract the filename from the file path | ||
filename = "/".join( | ||
file.file_path.parts[file.file_path.parts.index("Packs") :] | ||
) | ||
found_terms[f"{filename}"] = terms | ||
return found_terms | ||
|
||
def get_related_files(self, content_item): | ||
related_files = [content_item.readme] | ||
if isinstance(content_item, Integration): | ||
related_files.append(content_item.description_file) | ||
elif isinstance(content_item, Pack): | ||
related_files.append(content_item.release_note) | ||
return related_files |