Skip to content

Commit a4f1839

Browse files
[bct] Support suppressions for features_added (Azure#37065)
* support suppressions for changelog reporting * clean up * fix type * clean up imports * add test --------- Co-authored-by: Catalina Peralta <[email protected]>
1 parent edf1164 commit a4f1839

File tree

3 files changed

+60
-10
lines changed

3 files changed

+60
-10
lines changed

scripts/breaking_changes_checker/breaking_changes_tracker.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -597,15 +597,15 @@ def match(self, bc, ignored):
597597
return False
598598
return True
599599

600-
def get_reportable_breaking_changes(self, ignore_changes: Dict) -> List:
600+
def get_reportable_changes(self, ignore_changes: Dict, changes_list: List) -> List:
601601
ignored = []
602602
# Match all ignore rules that should apply to this package
603603
for ignored_package, ignore_rules in ignore_changes.items():
604604
if re.findall(ignored_package, self.package_name):
605605
ignored.extend(ignore_rules)
606606

607-
# Remove ignored breaking changes from list of reportable changes
608-
bc_copy = deepcopy(self.breaking_changes)
607+
# Remove ignored changes from list of reportable changes
608+
bc_copy = deepcopy(changes_list)
609609
for bc in bc_copy:
610610
_, bc_type, module_name, *args = bc
611611
class_name = args[0] if args else None
@@ -616,17 +616,17 @@ def get_reportable_breaking_changes(self, ignore_changes: Dict) -> List:
616616
suppression = Suppression(*rule)
617617

618618
if suppression.parameter_or_property_name is not None:
619-
# If the ignore rule is for a property or parameter, we should check up to that level on the original breaking change
619+
# If the ignore rule is for a property or parameter, we should check up to that level on the original change
620620
if self.match((bc_type, module_name, class_name, function_name, parameter_name), suppression):
621-
self.breaking_changes.remove(bc)
621+
changes_list.remove(bc)
622622
break
623623
elif self.match((bc_type, module_name, class_name, function_name), suppression):
624-
self.breaking_changes.remove(bc)
624+
changes_list.remove(bc)
625625
break
626626

627627
def report_changes(self) -> None:
628628
ignore_changes = self.ignore if self.ignore else IGNORE_BREAKING_CHANGES
629-
self.get_reportable_breaking_changes(ignore_changes)
629+
self.get_reportable_changes(ignore_changes, self.breaking_changes)
630630

631631
# If there are no breaking changes after the ignore check, return early
632632
if not self.breaking_changes:

scripts/breaking_changes_checker/changelog_tracker.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# --------------------------------------------------------------------------------------------
77

88
from enum import Enum
9-
from typing import Any, Dict, List, Union
9+
from typing import Any, Dict
1010
import jsondiff
1111
from breaking_changes_tracker import BreakingChangesTracker
1212
from breaking_changes_allowlist import IGNORE_BREAKING_CHANGES
@@ -155,10 +155,11 @@ def check_non_positional_parameter_added(self, current_parameters_node: Dict) ->
155155
)
156156
)
157157

158+
158159
def report_changes(self) -> None:
159160
ignore_changes = self.ignore if self.ignore else IGNORE_BREAKING_CHANGES
160-
self.get_reportable_breaking_changes(ignore_changes)
161-
161+
self.get_reportable_changes(ignore_changes, self.breaking_changes)
162+
self.get_reportable_changes(ignore_changes, self.features_added)
162163
# Code borrowed and modified from the previous change log tool
163164
def _build_md(content: list, title: str, buffer: list):
164165
buffer.append(title)

scripts/breaking_changes_checker/tests/test_changelog.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,55 @@ def test_added_operation_group():
441441
assert msg == ChangelogTracker.ADDED_CLASS_PROPERTY_MSG
442442

443443

444+
def test_ignore_changes():
445+
stable = {
446+
"azure.contoso": {
447+
"class_nodes": {
448+
"ContosoClient": {
449+
"methods": {},
450+
"properties": {
451+
"bar": {
452+
"attr_type": "str"
453+
}
454+
}
455+
}
456+
}
457+
}
458+
}
459+
460+
current = {
461+
"azure.contoso": {
462+
"class_nodes": {
463+
"ContosoClient": {
464+
"methods": {},
465+
"properties": {
466+
"bar": {
467+
"attr_type": "str"
468+
},
469+
"foo": {
470+
"attr_type": "DeviceGroupsOperations"
471+
},
472+
"zip": {
473+
"attr_type": "bool"
474+
}
475+
}
476+
}
477+
}
478+
}
479+
}
480+
481+
IGNORE = {
482+
"azure-contoso": [("AddedOperationGroup", "*", "ContosoClient", "foo")]
483+
}
484+
diff = jsondiff.diff(stable, current)
485+
bc = ChangelogTracker(stable, current, diff, "azure-contoso", ignore=IGNORE)
486+
bc.run_checks()
487+
bc.report_changes()
488+
assert len(bc.features_added) == 1
489+
msg, _, *args = bc.features_added[0]
490+
assert msg == ChangelogTracker.ADDED_CLASS_PROPERTY_MSG
491+
492+
444493
def test_async_features_added_cleanup():
445494
features_added = [
446495
("Message", "AddedClient", "azure.contoso.aio", "FooClient", "foo"),

0 commit comments

Comments
 (0)