Skip to content

Commit

Permalink
code (Azure#24253)
Browse files Browse the repository at this point in the history
  • Loading branch information
msyyc authored May 18, 2022
1 parent 2ae8ac9 commit 482c432
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
18 changes: 12 additions & 6 deletions tools/azure-sdk-tools/packaging_tools/change_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,18 @@ def operation(self, diff_entry):
if remaining_path[0] == "parameters":
old_parameters_list = self._old_report["operations"][operation_name]["functions"][function_name]['parameters']
new_parameters_list = self._new_report["operations"][operation_name]["functions"][function_name]['parameters']
old_parameters = {param_name['name'] for param_name in old_parameters_list}
new_parameters = {param_name['name'] for param_name in new_parameters_list}
old_parameters = {param_name['name']: param_name for param_name in old_parameters_list}
new_parameters = {param_name['name']: param_name for param_name in new_parameters_list}
old_parameters_set = set(old_parameters.keys())
new_parameters_set = set(new_parameters.keys())
# The new parameter is optional or not. Be breaking change for now.
for removed_parameter in old_parameters - new_parameters:
for removed_parameter in (old_parameters_set - new_parameters_set):
self.breaking_changes.append(_REMOVE_OPERATION_PARAM.format(operation_name, function_name, removed_parameter))
for added_parameter in new_parameters - old_parameters:
self.breaking_changes.append(_ADD_OPERATION_PARAM.format(operation_name, function_name,added_parameter))
for added_parameter in (new_parameters_set - old_parameters_set):
if new_parameters[added_parameter]['type'] == 'KEYWORD_ONLY' and new_parameters[added_parameter]['has_default_value']:
self.features.append(_ADD_OPERATION_PARAM_FEATURE.format(operation_name, function_name, added_parameter))
else:
self.breaking_changes.append(_ADD_OPERATION_PARAM.format(operation_name, function_name, added_parameter))
return
raise NotImplementedError(f"Other situations. Be err for now: {str(remaining_path)}")

Expand Down Expand Up @@ -151,7 +156,7 @@ def client(self):
## Features
_ADD_OPERATION_GROUP = "Added operation group {}"
_ADD_OPERATION = "Added operation {}.{}"
_ADD_OPERATION_PARAM = "Operation {}.{} has a new parameter {}"
_ADD_OPERATION_PARAM_FEATURE = "Operation {}.{} has a new optional and keyword-only parameter {}"
_MODEL_PARAM_ADD = "Model {} has a new parameter {}"
_MODEL_ADD = "Added model {}"

Expand All @@ -164,6 +169,7 @@ def client(self):
_MODEL_PARAM_DELETE = "Model {} no longer has parameter {}"
_MODEL_PARAM_ADD_REQUIRED = "Model {} has a new required parameter {}"
_MODEL_PARAM_CHANGE_REQUIRED = "Parameter {} of model {} is now required"
_ADD_OPERATION_PARAM = "Operation {}.{} has a new parameter {}"


def build_change_log(old_report, new_report):
Expand Down
2 changes: 2 additions & 0 deletions tools/azure-sdk-tools/packaging_tools/code_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ def create_report_from_func(function_attr):
func_content["parameters"].append(
{
"name": parameter.name,
"type": str(parameter.kind),
"has_default_value": not (parameter.default is parameter.empty)
}
)
return func_content
Expand Down

0 comments on commit 482c432

Please sign in to comment.