Skip to content
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

[tools] optimize change_log for added parameters #24253

Merged
merged 3 commits into from
May 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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