Skip to content

Commit

Permalink
[bct] Add specific messages for enums in the changelog (Azure#37216)
Browse files Browse the repository at this point in the history
* add enum specific messages for changelog

* add test

* nit remove comment

---------

Co-authored-by: Catalina Peralta <caperal@microsoft.com>
  • Loading branch information
catalinaperalta and cperaltah authored Sep 6, 2024
1 parent 6b5ce2d commit 2551571
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 0 deletions.
20 changes: 20 additions & 0 deletions scripts/breaking_changes_checker/changelog_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class ChangeType(str, Enum):
ADDED_CLASS_METHOD = "AddedClassMethod"
ADDED_CLASS_METHOD_PARAMETER = "AddedClassMethodParameter"
ADDED_CLASS_PROPERTY = "AddedClassProperty"
ADDED_ENUM = "AddedEnum"
ADDED_ENUM_MEMBER = "AddedEnumMember"
ADDED_FUNCTION_PARAMETER = "AddedFunctionParameter"
ADDED_OPERATION_GROUP = "AddedOperationGroup"

Expand All @@ -36,6 +38,10 @@ class ChangelogTracker(BreakingChangesTracker):
"Function `{}` added parameter `{}`"
ADDED_CLASS_PROPERTY_MSG = \
"Model `{}` added property `{}`"
ADDED_ENUM_MSG = \
"Added enum `{}`"
ADDED_ENUM_MEMBER_MSG = \
"Enum `{}` added member `{}`"
ADDED_OPERATION_GROUP_MSG = \
"Client `{}` added operation group `{}`"

Expand Down Expand Up @@ -71,6 +77,14 @@ def run_non_breaking_class_level_diff_checks(self, module: Dict) -> None:
self.module_name, class_name
)
self.features_added.append(fa)
elif class_components.get("type", None) == "Enum":
# This is a new enum
fa = (
self.ADDED_ENUM_MSG,
ChangeType.ADDED_ENUM,
self.module_name, class_name
)
self.features_added.append(fa)
else:
# This is a new class
fa = (
Expand Down Expand Up @@ -135,6 +149,12 @@ def run_non_breaking_class_level_diff_checks(self, module: Dict) -> None:
ChangeType.ADDED_OPERATION_GROUP,
self.module_name, self.class_name, property_name
)
if stable_class_nodes[self.class_name]["type"] == "Enum":
fa = (
self.ADDED_ENUM_MEMBER_MSG,
ChangeType.ADDED_ENUM_MEMBER,
self.module_name, class_name, property_name
)
self.features_added.append(fa)


Expand Down
58 changes: 58 additions & 0 deletions scripts/breaking_changes_checker/tests/test_changelog.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def test_new_class_property_added():
"azure.ai.contentsafety": {
"class_nodes": {
"AnalyzeTextResult": {
"type": None,
"methods": {},
"properties": {
"blocklists_match": "Optional",
Expand All @@ -47,6 +48,7 @@ def test_new_class_property_added():
"azure.ai.contentsafety": {
"class_nodes": {
"AnalyzeTextResult": {
"type": None,
"methods": {},
"properties": {
"blocklists_match": "Optional",
Expand Down Expand Up @@ -144,6 +146,7 @@ def test_new_class_property_added_init():
"azure.ai.contentsafety": {
"class_nodes": {
"AnalyzeTextResult": {
"type": None,
"methods": {
"__init__": {
"parameters": {
Expand Down Expand Up @@ -177,6 +180,7 @@ def test_new_class_property_added_init():
"azure.ai.contentsafety": {
"class_nodes": {
"AnalyzeTextResult": {
"type": None,
"methods": {
"__init__": {
"parameters": {
Expand Down Expand Up @@ -390,6 +394,7 @@ def test_added_operation_group():
"azure.contoso": {
"class_nodes": {
"ContosoClient": {
"type": None,
"methods": {},
"properties": {
"bar": {
Expand All @@ -405,6 +410,7 @@ def test_added_operation_group():
"azure.contoso": {
"class_nodes": {
"ContosoClient": {
"type": None,
"methods": {},
"properties": {
"bar": {
Expand Down Expand Up @@ -438,6 +444,7 @@ def test_ignore_changes():
"azure.contoso": {
"class_nodes": {
"ContosoClient": {
"type": None,
"methods": {},
"properties": {
"bar": {
Expand All @@ -453,6 +460,7 @@ def test_ignore_changes():
"azure.contoso": {
"class_nodes": {
"ContosoClient": {
"type": None,
"methods": {},
"properties": {
"bar": {
Expand Down Expand Up @@ -497,3 +505,53 @@ def test_async_features_added_cleanup():
assert len(ct.features_added) == 2
assert ct.features_added[0] == ("Message", "AddedClient", "azure.contoso", "FooClient", "foo")
assert ct.features_added[1] == ("Message", "AddedClassMethod", "azure.contoso", "FooClient", "from_connection_string")


def test_new_enum_added():
current = {
"azure.contoso.widgetmanager": {
"class_nodes": {
"WidgetEnum": {
"type": "Enum",
"methods": {},
"properties": {
"a": "a",
"b": "b",
}
},
"ManagerEnum": {
"type": "Enum",
"methods": {},
"properties": {
"foo": "foo",
"bar": "bar",
}
},
}
}
}

stable = {
"azure.contoso.widgetmanager": {
"class_nodes": {
"ManagerEnum": {
"type": "Enum",
"methods": {},
"properties": {
"foo": "foo",
}
},
}
}
}

bc = ChangelogTracker(stable, current, "azure-contoso-widgetmanager")
bc.run_checks()

assert len(bc.features_added) == 2
msg, _, *args = bc.features_added[0]
assert msg == ChangelogTracker.ADDED_ENUM_MEMBER_MSG
assert args == ['azure.contoso.widgetmanager', 'ManagerEnum', 'bar']
msg, _, *args = bc.features_added[1]
assert msg == ChangelogTracker.ADDED_ENUM_MSG
assert args == ['azure.contoso.widgetmanager', 'WidgetEnum']

0 comments on commit 2551571

Please sign in to comment.