Skip to content

Commit 2fbc7be

Browse files
authored
[Tool] changelog tool rename feature (Azure#25955)
* rename feature * update function name * become better
1 parent 8b302fb commit 2fbc7be

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

tools/azure-sdk-tools/packaging_tools/change_log.py

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,16 @@ def __init__(self, old_report, new_report):
2121
self.optional_features = []
2222
self._old_report = old_report
2323
self._new_report = new_report
24+
self.removed_operations = []
25+
self.added_operations = []
2426

2527
def sort(self):
2628
self.features.sort()
2729
self.breaking_changes.sort()
2830
self.optional_features.sort()
2931

3032
def build_md(self):
33+
self.compare_operation()
3134
self.sort()
3235
buffer = []
3336
if self.features:
@@ -73,10 +76,11 @@ def operation(self, diff_entry):
7376
# Is this a new operation, inside a known operation group?
7477
function_name, *remaining_path = remaining_path
7578
if not remaining_path:
79+
# Simplify renaming func to begin_func change, put it into the compare_operation() for processing
7680
if is_deletion:
77-
self.breaking_changes.append(_REMOVE_OPERATION.format(operation_name, function_name))
81+
self.removed_operations.append(f'{operation_name}.{function_name}')
7882
else:
79-
self.features.append(_ADD_OPERATION.format(operation_name, function_name))
83+
self.added_operations.append(f'{operation_name}.{function_name}')
8084
return
8185

8286
if remaining_path[0] == "metadata":
@@ -175,6 +179,23 @@ def client(self, old_report, new_report):
175179
self.breaking_changes.append(msg)
176180
return
177181

182+
def compare_operation(self):
183+
'''
184+
Record changelog like "rename operation.delete to operation.begin_delete"
185+
instead of "remove operation.delete or add operation.begin_delete"
186+
'''
187+
while self.removed_operations:
188+
op, old_function = self.removed_operations.pop().split('.')
189+
new_function = f'begin_{old_function}'
190+
if f'{op}.{new_function}' in self.added_operations:
191+
self.added_operations.remove(f'{op}.{new_function}')
192+
self.breaking_changes.append(_RENAME_OPERATION.format(op, old_function, op, new_function))
193+
else:
194+
self.breaking_changes.append(_REMOVE_OPERATION.format(op, old_function))
195+
for op_function in self.added_operations:
196+
operation_name, function_name = op_function.split('.')
197+
self.features.append(_ADD_OPERATION.format(operation_name, function_name))
198+
178199

179200
## Features
180201
_ADD_OPERATION_GROUP = "Added operation group {}"
@@ -186,6 +207,7 @@ def client(self, old_report, new_report):
186207
## Breaking Changes
187208
_REMOVE_OPERATION_GROUP = "Removed operation group {}"
188209
_REMOVE_OPERATION = "Removed operation {}.{}"
210+
_RENAME_OPERATION = "Renamed operation {}.{} to {}.{}"
189211
_REMOVE_OPERATION_PARAM = "Operation {}.{} no longer has parameter {}"
190212
_CLIENT_SIGNATURE_CHANGE = "Client name is changed from `{}` to `{}`"
191213
_CLIENT_SIGNATURE_CHANGE_WITHOUT_OLD = "Client name is changed to `{}`"

0 commit comments

Comments
 (0)