Skip to content

Commit

Permalink
Support for iterating over actions for a specific app (#216)
Browse files Browse the repository at this point in the history
  • Loading branch information
angrybayblade committed Jun 25, 2024
1 parent 7f80125 commit 678abfa
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
7 changes: 7 additions & 0 deletions python/composio/cli/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}
"""

Expand Down
8 changes: 8 additions & 0 deletions python/composio/client/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
- TODO: Replace Enums with something lightweight
"""

import typing as t
from enum import Enum


Expand Down Expand Up @@ -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."""
Expand Down
7 changes: 7 additions & 0 deletions python/tests/test_client/test_enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 678abfa

Please sign in to comment.