-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
115 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
45 changes: 45 additions & 0 deletions
45
demisto_sdk/commands/validate/validators/BC_validators/BC103_have_the_args_changed.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,45 @@ | ||
from __future__ import annotations | ||
|
||
from typing import Iterable, List | ||
|
||
from demisto_sdk.commands.common.constants import GitStatuses | ||
from demisto_sdk.commands.content_graph.objects.script import Script | ||
from demisto_sdk.commands.validate.tools import compare_lists | ||
from demisto_sdk.commands.validate.validators.base_validator import ( | ||
BaseValidator, | ||
ValidationResult, | ||
) | ||
|
||
ContentTypes = Script | ||
|
||
|
||
class HaveTheArgsChangedValidator(BaseValidator[ContentTypes]): | ||
error_code = "BC103" | ||
description = "Check if the argument name has been changed." | ||
rationale = "If an existing argument has been renamed, it will break backward compatibility." | ||
error_message = ( | ||
"Possible backward compatibility break: Your updates to this file contain changes " | ||
"to the names of the following existing arguments: {args}. Please undo the changes." | ||
) | ||
related_field = "args.name" | ||
is_auto_fixable = False | ||
expected_git_statuses = [GitStatuses.MODIFIED] | ||
|
||
def is_valid(self, content_items: Iterable[ContentTypes]) -> List[ValidationResult]: | ||
results: List[ValidationResult] = [] | ||
for content_item in content_items: | ||
|
||
current_args = [arg.name for arg in content_item.args] | ||
old_args = [arg.name for arg in content_item.old_base_content_object.args] # type: ignore | ||
args_diff = compare_lists(sub_list=old_args, main_list=current_args) | ||
|
||
if args_diff: | ||
results.append( | ||
ValidationResult( | ||
validator=self, | ||
message=self.error_message.format(args=", ".join(args_diff)), | ||
content_object=content_item, | ||
) | ||
) | ||
|
||
return results |