From 678abfa925a0881615ef3db142b37ca35fd02915 Mon Sep 17 00:00:00 2001 From: Viraj <35092918+angrybayblade@users.noreply.github.com> Date: Tue, 25 Jun 2024 08:20:25 +0530 Subject: [PATCH] Support for iterating over actions for a specific app (#216) --- python/composio/cli/apps.py | 7 +++++++ python/composio/client/enums.py | 8 ++++++++ python/tests/test_client/test_enum.py | 7 +++++++ 3 files changed, 22 insertions(+) diff --git a/python/composio/cli/apps.py b/python/composio/cli/apps.py index d1911e5bb..2ff132935 100755 --- a/python/composio/cli/apps.py +++ b/python/composio/cli/apps.py @@ -61,6 +61,13 @@ def is_local(self) -> bool: \"\"\"If the app is local.\"\"\" return self.value.lower() in [{local_tools}] + @property + def actions(self) -> t.Iterator["Action"]: + \"\"\"Iterate over actions for this app.\"\"\" + for action in Action: + if action.name.startswith(self.value): + yield action + {apps} """ diff --git a/python/composio/client/enums.py b/python/composio/client/enums.py index 744dcd481..50f7c4c1b 100644 --- a/python/composio/client/enums.py +++ b/python/composio/client/enums.py @@ -4,6 +4,7 @@ - TODO: Replace Enums with something lightweight """ +import typing as t from enum import Enum @@ -424,6 +425,13 @@ def val(self) -> str: class App(str, Enum): """Composio App.""" + @property + def actions(self) -> t.Iterator["Action"]: + """Iterate over actions for this app.""" + for action in Action: + if action.name.startswith(self.value): + yield action + @property def is_local(self) -> bool: """If the app is local.""" diff --git a/python/tests/test_client/test_enum.py b/python/tests/test_client/test_enum.py index ce7333f04..6b98112ea 100644 --- a/python/tests/test_client/test_enum.py +++ b/python/tests/test_client/test_enum.py @@ -32,3 +32,10 @@ def test_trigger_enum() -> None: trigger = Trigger(("slack", "slack_receive_message")) assert trigger.app == "slack" assert trigger.event == "slack_receive_message" + + +def test_actions_list() -> None: + """Test action list from an app enum.""" + app = App.GITHUB + for action in app.actions: + assert action.name.startswith(app.value)