Skip to content

Commit

Permalink
add diff level to meta changes (#425)
Browse files Browse the repository at this point in the history
* add diff level to meta changes
  • Loading branch information
AllyW authored Jan 2, 2024
1 parent 8a07397 commit c1ceceb
Show file tree
Hide file tree
Showing 7 changed files with 139 additions and 63 deletions.
5 changes: 5 additions & 0 deletions azure-cli-diff-tool/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
Release History
===============
0.0.5
++++++
* Add `DiffLevel` to meta comparison
* Downgrade change level according to warn list

0.0.4
++++++
* Add meta change parameter update warn list
Expand Down
2 changes: 1 addition & 1 deletion azure-cli-diff-tool/azure_cli_diff_tool/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
extract_module_name_from_meta_file, export_meta_changes_to_csv, export_meta_changes_to_json, \
export_meta_changes_to_dict

__VERSION__ = '0.0.4'
__VERSION__ = '0.0.5'

logger = logging.getLogger(__name__)

Expand Down
25 changes: 19 additions & 6 deletions azure-cli-diff-tool/azure_cli_diff_tool/_const.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,35 @@
BREAKING_CHANE_RULE_LINK_URL_PREFIX = "https://github.com/Azure/azure-cli/blob/dev/doc/breaking_change_rules/"
BREAKING_CHANE_RULE_LINK_URL_SUFFIX = ".md"

CMD_REMOVE_SUFFIX_WARN_LIST = ["wait"]

CMD_PROPERTY_REMOVE_BREAK_LIST = []
CMD_PROPERTY_REMOVE_WARN_LIST = []

CMD_PROPERTY_ADD_BREAK_LIST = ["confirmation"]
CMD_PROPERTY_ADD_WARN_LIST = []

CMD_PROPERTY_UPDATE_BREAK_LIST = []
CMD_PROPERTY_UPDATE_WARN_LIST = []

CMD_PROPERTY_IGNORED_LIST = ["is_aaz", "supports_no_wait"]

PARA_PROPERTY_REMOVE_BREAK_LIST = ["options", "id_part", "nargs"]
PARA_PROPERTY_ADD_BREAK_LIST = ["required", "choices"]
PARA_PROPERTY_UPDATE_BREAK_LIST = ["default", "aaz_default", "type", "aaz_type"]
PARA_PROPERTY_UPDATE_WARN_LIST = ["type", "aaz_type"]
PARA_PROPERTY_REMOVE_BREAK_LIST = ["options"]
PARA_PROPERTY_REMOVE_WARN_LIST = ["id_part", "nargs"]

PARA_PROPERTY_ADD_BREAK_LIST = ["required"]
PARA_PROPERTY_ADD_WARN_LIST = ["choices"]

PARA_PROPERTY_UPDATE_BREAK_LIST = ["default", "aaz_default"]
PARA_PROPERTY_UPDATE_WARN_LIST = ["type", "aaz_type", "choices", "nargs"]

PARA_NAME_IGNORED_LIST = ["force_string"]
PARA_PROPERTY_IGNORED_LIST = []
PARA_VALUE_IGNORED_LIST = ["generic_update_set", "generic_update_add", "generic_update_remove",
"generic_update_force_string"]

EXPORTED_CSV_META_HEADER = ["module", "cmd_name", "rule_id", "rule_name", "is_break", "rule_link_url",
"rule_message", "suggest_message"]
EXPORTED_CSV_META_HEADER = ["module", "cmd_name", "rule_id", "rule_name", "is_break", "diff_level",
"rule_link_url", "rule_message", "suggest_message"]

CHANGE_RULE_MESSAGE_MAPPING = {
"1000": "default Message",
Expand Down
69 changes: 42 additions & 27 deletions azure-cli-diff-tool/azure_cli_diff_tool/meta_change.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,128 +4,137 @@
# license information.
# -----------------------------------------------------------------------------

from .utils import get_change_rule_template, get_change_suggest_template
from .utils import get_change_rule_template, get_change_suggest_template, DiffLevel
from ._const import BREAKING_CHANE_RULE_LINK_URL_PREFIX, BREAKING_CHANE_RULE_LINK_URL_SUFFIX, \
CMD_PROPERTY_IGNORED_LIST, PARA_NAME_IGNORED_LIST, PARA_PROPERTY_IGNORED_LIST, PARA_VALUE_IGNORED_LIST


class MetaChange:

def __init__(self, rule_id="1000", is_break=False, rule_message="", suggest_message="",
def __init__(self, rule_id="1000", is_break=False, diff_level=DiffLevel.INFO, rule_message="", suggest_message="",
is_ignore=False, filter_key=None):
self.rule_id = rule_id
self.is_break = is_break
self.diff_level = diff_level
self.rule_message = rule_message
self.suggest_message = suggest_message
self.rule_link_url = BREAKING_CHANE_RULE_LINK_URL_PREFIX + self.rule_id + BREAKING_CHANE_RULE_LINK_URL_SUFFIX
self.is_ignore = is_ignore
self.filter_key = filter_key

def __str__(self):
res = [self.rule_message]
res = [self.rule_message, "diff_level: " + str(self.diff_level.value)]
if self.is_break:
res.append("is_break: {0}".format(self.is_break))
res.append(self.suggest_message)
return " | ".join([str(a) for a in res])


class SubgroupAdd(MetaChange):
def __init__(self, subgroup_name, is_break=False):
def __init__(self, subgroup_name, is_break=False, diff_level=DiffLevel.INFO):
if not subgroup_name:
raise Exception("sub group name needed")
self.rule_id = "1011"
self.subgroup_name = subgroup_name
self.is_break = is_break
self.diff_level = diff_level
self.rule_message = get_change_rule_template(self.rule_id).format(self.subgroup_name)
self.suggest_message = get_change_suggest_template(self.rule_id).format(self.subgroup_name) \
if self.is_break else ""
super().__init__(self.rule_id, is_break, self.rule_message, self.suggest_message)
super().__init__(self.rule_id, is_break, diff_level, self.rule_message, self.suggest_message)


class SubgroupRemove(MetaChange):
def __init__(self, subgroup_name, is_break=True):
def __init__(self, subgroup_name, is_break=True, diff_level=DiffLevel.BREAK):
if not subgroup_name:
raise Exception("sub group name needed")
self.rule_id = "1012"
self.subgroup_name = subgroup_name
self.is_break = is_break
self.diff_level = diff_level
self.rule_message = get_change_rule_template(self.rule_id).format(self.subgroup_name)
self.suggest_message = get_change_suggest_template(self.rule_id).format(self.subgroup_name) \
if self.is_break else ""
super().__init__(self.rule_id, is_break, self.rule_message, self.suggest_message)
super().__init__(self.rule_id, is_break, diff_level, self.rule_message, self.suggest_message)


class CmdAdd(MetaChange):
def __init__(self, cmd_name, is_break=False):
def __init__(self, cmd_name, is_break=False, diff_level=DiffLevel.INFO):
if not cmd_name:
raise Exception("cmd name needed")
self.rule_id = "1001"
self.cmd_name = cmd_name
self.is_break = is_break
self.diff_level = diff_level
self.rule_message = get_change_rule_template(self.rule_id).format(self.cmd_name)
self.suggest_message = get_change_suggest_template(self.rule_id).format(self.cmd_name) if self.is_break else ""
super().__init__(self.rule_id, is_break, self.rule_message, self.suggest_message)
super().__init__(self.rule_id, is_break, diff_level, self.rule_message, self.suggest_message)


class CmdRemove(MetaChange):
def __init__(self, cmd_name, is_break=True):
def __init__(self, cmd_name, is_break=True, diff_level=DiffLevel.BREAK):
if not cmd_name:
raise Exception("cmd name needed")
self.cmd_name = cmd_name
self.rule_id = "1002"
self.is_break = is_break
self.diff_level = diff_level
self.rule_message = get_change_rule_template(self.rule_id).format(self.cmd_name)
self.suggest_message = get_change_suggest_template(self.rule_id).format(self.cmd_name) if self.is_break else ""
super().__init__(self.rule_id, is_break, self.rule_message, self.suggest_message)
super().__init__(self.rule_id, is_break, diff_level, self.rule_message, self.suggest_message)


class CmdPropAdd(MetaChange):
def __init__(self, cmd_name, cmd_property, is_break=False):
def __init__(self, cmd_name, cmd_property, is_break=False, diff_level=DiffLevel.INFO):
if not cmd_name or not cmd_property:
raise Exception("cmd name needed")
self.rule_id = "1003"
self.is_ignore = False
self.cmd_name = cmd_name
self.cmd_property = cmd_property
self.is_break = is_break
self.diff_level = diff_level
self.rule_message = get_change_rule_template(self.rule_id).format(self.cmd_name, self.cmd_property)
self.suggest_message = get_change_suggest_template(self.rule_id).format(self.cmd_property, self.cmd_name) \
if self.is_break else ""
if cmd_property in CMD_PROPERTY_IGNORED_LIST:
self.is_ignore = True
self.filter_key = [self.rule_id, self.cmd_name, self.cmd_property]
super().__init__(self.rule_id, is_break, self.rule_message, self.suggest_message, self.is_ignore,
super().__init__(self.rule_id, is_break, diff_level, self.rule_message, self.suggest_message, self.is_ignore,
self.filter_key)


class CmdPropRemove(MetaChange):
def __init__(self, cmd_name, cmd_property, is_break=False):
def __init__(self, cmd_name, cmd_property, is_break=False, diff_level=DiffLevel.BREAK):
if not cmd_name or not cmd_property:
raise Exception("cmd name needed")
self.rule_id = "1004"
self.is_ignore = False
self.cmd_name = cmd_name
self.cmd_property = cmd_property
self.is_break = is_break
self.diff_level = diff_level
self.rule_message = get_change_rule_template(self.rule_id).format(self.cmd_name, self.cmd_property)
self.suggest_message = get_change_suggest_template(self.rule_id).format(self.cmd_property, self.cmd_name) \
if self.is_break else ""
if cmd_property in CMD_PROPERTY_IGNORED_LIST:
self.is_ignore = True
self.filter_key = [self.rule_id, self.cmd_name, self.cmd_property]
super().__init__(self.rule_id, is_break, self.rule_message, self.suggest_message,
super().__init__(self.rule_id, is_break, diff_level, self.rule_message, self.suggest_message,
self.is_ignore, self.filter_key)


class CmdPropUpdate(MetaChange):

def __init__(self, cmd_name, cmd_property, is_break=False, old_value=None, new_value=None):
def __init__(self, cmd_name, cmd_property, is_break=False, diff_level=DiffLevel.INFO,
old_value=None, new_value=None):
if not cmd_name or not cmd_property:
raise Exception("cmd name and cmd prop needed")
self.rule_id = "1005"
self.is_ignore = False
self.cmd_name = cmd_name
self.is_break = is_break
self.diff_level = diff_level
self.cmd_prop_updated = cmd_property
self.old_value = ""
self.new_value = ""
Expand All @@ -142,43 +151,45 @@ def __init__(self, cmd_name, cmd_property, is_break=False, old_value=None, new_v
if cmd_property in CMD_PROPERTY_IGNORED_LIST:
self.is_ignore = True
self.filter_key = [self.rule_id, self.cmd_name, self.cmd_prop_updated]
super().__init__(self.rule_id, is_break, self.rule_message, self.suggest_message,
super().__init__(self.rule_id, is_break, diff_level, self.rule_message, self.suggest_message,
self.is_ignore, self.filter_key)


class ParaAdd(MetaChange):

def __init__(self, cmd_name, para_name, is_break=False):
def __init__(self, cmd_name, para_name, is_break=False, diff_level=DiffLevel.INFO):
if not cmd_name or not para_name:
raise Exception("cmd name, parameter name needed")
self.rule_id = "1006"
self.cmd_name = cmd_name
self.para_name = para_name
self.is_break = is_break
self.diff_level = diff_level
self.rule_message = get_change_rule_template(self.rule_id).format(self.cmd_name, self.para_name)
self.suggest_message = get_change_suggest_template(self.rule_id).format(self.para_name,
self.cmd_name) if self.is_break else ""
super().__init__(self.rule_id, is_break, self.rule_message, self.suggest_message)
super().__init__(self.rule_id, is_break, diff_level, self.rule_message, self.suggest_message)


class ParaRemove(MetaChange):

def __init__(self, cmd_name, para_name, is_break=False):
def __init__(self, cmd_name, para_name, is_break=False, diff_level=DiffLevel.BREAK):
if not cmd_name or not para_name:
raise Exception("cmd name, parameter name needed")
self.rule_id = "1007"
self.cmd_name = cmd_name
self.para_name = para_name
self.is_break = is_break
self.diff_level = diff_level
self.rule_message = get_change_rule_template(self.rule_id).format(self.cmd_name, self.para_name)
self.suggest_message = get_change_suggest_template(self.rule_id).format(self.para_name,
self.cmd_name) if self.is_break else ""
super().__init__(self.rule_id, is_break, self.rule_message, self.suggest_message)
super().__init__(self.rule_id, is_break, diff_level, self.rule_message, self.suggest_message)


class ParaPropAdd(MetaChange):

def __init__(self, cmd_name, para_name, para_property, para_prop_value, is_break=False):
def __init__(self, cmd_name, para_name, para_property, para_prop_value, is_break=False, diff_level=DiffLevel.INFO):
if not cmd_name or not para_name or not para_property:
raise Exception("cmd name, parameter name and parameter property needed")
self.rule_id = "1008"
Expand All @@ -188,6 +199,7 @@ def __init__(self, cmd_name, para_name, para_property, para_prop_value, is_break
self.para_prop = para_property
self.para_prop_value = para_prop_value
self.is_break = is_break
self.diff_level = diff_level

self.rule_message = get_change_rule_template(self.rule_id).format(self.cmd_name, self.para_name,
self.para_prop, self.para_prop_value)
Expand All @@ -197,12 +209,12 @@ def __init__(self, cmd_name, para_name, para_property, para_prop_value, is_break
self.cmd_name) if self.is_break else ""
if para_property in PARA_PROPERTY_IGNORED_LIST or para_name in PARA_NAME_IGNORED_LIST:
self.is_ignore = True
super().__init__(self.rule_id, is_break, self.rule_message, self.suggest_message, self.is_ignore)
super().__init__(self.rule_id, is_break, diff_level, self.rule_message, self.suggest_message, self.is_ignore)


class ParaPropRemove(MetaChange):

def __init__(self, cmd_name, para_name, para_property, para_prop_value, is_break=False):
def __init__(self, cmd_name, para_name, para_property, para_prop_value, is_break=False, diff_level=DiffLevel.BREAK):
if not cmd_name or not para_name or not para_property:
raise Exception("cmd name, parameter name and parameter property needed")
self.rule_id = "1009"
Expand All @@ -212,6 +224,7 @@ def __init__(self, cmd_name, para_name, para_property, para_prop_value, is_break
self.para_prop = para_property
self.para_prop_value = para_prop_value
self.is_break = is_break
self.diff_level = diff_level

self.rule_message = get_change_rule_template(self.rule_id).format(self.cmd_name, self.para_name,
self.para_prop, self.para_prop_value)
Expand All @@ -221,12 +234,13 @@ def __init__(self, cmd_name, para_name, para_property, para_prop_value, is_break
self.cmd_name) if self.is_break else ""
if para_property in PARA_PROPERTY_IGNORED_LIST or para_name in PARA_NAME_IGNORED_LIST:
self.is_ignore = True
super().__init__(self.rule_id, is_break, self.rule_message, self.suggest_message, self.is_ignore)
super().__init__(self.rule_id, is_break, diff_level, self.rule_message, self.suggest_message, self.is_ignore)


class ParaPropUpdate(MetaChange):

def __init__(self, cmd_name, para_name, para_property, is_break=False, old_value=None, new_value=None):
def __init__(self, cmd_name, para_name, para_property, is_break=False, diff_level=DiffLevel.INFO,
old_value=None, new_value=None):
if not cmd_name or not para_name or not para_property:
raise Exception("cmd name, parameter name and parameter property needed")
self.rule_id = "1010"
Expand All @@ -235,6 +249,7 @@ def __init__(self, cmd_name, para_name, para_property, is_break=False, old_value
self.para_name = para_name
self.para_prop_updated = para_property
self.is_break = is_break
self.diff_level = diff_level
self.old_value = None
self.new_value = None
if old_value is not None:
Expand All @@ -254,5 +269,5 @@ def __init__(self, cmd_name, para_name, para_property, is_break=False, old_value
if self.new_value in PARA_VALUE_IGNORED_LIST or self.old_value in PARA_VALUE_IGNORED_LIST:
self.is_ignore = True
self.filter_key = [self.rule_id, self.cmd_name, self.para_name, self.para_prop_updated]
super().__init__(self.rule_id, is_break, self.rule_message, self.suggest_message,
super().__init__(self.rule_id, is_break, diff_level, self.rule_message, self.suggest_message,
self.is_ignore, self.filter_key)
Loading

0 comments on commit c1ceceb

Please sign in to comment.