Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions taskbadger/cli/basics.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def create(
"-a",
metavar="<trigger integration config>",
show_default=False,
help="Action definition e.g. 'success,error email to:me@email.com'",
help="[Deprecated] Action definition e.g. 'success,error email to:me@email.com'",
),
status: StatusEnum = typer.Option(StatusEnum.PROCESSING, help="The initial status of the task."),
value_max: int = typer.Option(100, help="The maximum value for the task."),
Expand Down Expand Up @@ -118,7 +118,7 @@ def update(
"-a",
metavar="<trigger integration config>",
show_default=False,
help="Action definition e.g. 'success,error email to:me@email.com'",
help="[Deprecated] Action definition e.g. 'success,error email to:me@email.com'",
),
status: StatusEnum = typer.Option(StatusEnum.PROCESSING, help="The status of the task."),
value: int = typer.Option(None, show_default=False, help="The current task value (progress)."),
Expand Down
2 changes: 1 addition & 1 deletion taskbadger/cli/wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def run(
"-a",
metavar="<trigger integration config>",
show_default=False,
help="Action definition e.g. 'success,error email to:me@email.com'",
help="[Deprecated] Action definition e.g. 'success,error email to:me@email.com'",
),
tag: list[str] = typer.Option(
None,
Expand Down
22 changes: 19 additions & 3 deletions taskbadger/sdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def create_task(
data: Custom task data.
max_runtime: Maximum expected runtime (seconds).
stale_timeout: Maximum allowed time between updates (seconds).
actions: Task actions.
actions: Task actions. **Deprecated:** use project-level actions instead.
monitor_id: ID of the monitor to associate this task with.
tags: Dictionary of namespace -> value tags.
queue: Name of the queue the task is from.
Expand All @@ -190,6 +190,7 @@ def create_task(
data = data or {}
task_dict["data"] = {**scope.context, **data}
if actions:
_warn_actions_deprecated()
task_dict["actions"] = [a.to_dict() for a in actions]
if scope.tags or tags:
tags = tags or {}
Expand Down Expand Up @@ -234,7 +235,7 @@ def update_task(
data: Custom task data.
max_runtime: Maximum expected runtime (seconds).
stale_timeout: Maximum allowed time between updates (seconds).
actions: Task actions.
actions: Task actions. **Deprecated:** use project-level actions instead.
tags: Dictionary of namespace -> value tags.
queue: Name of the queue the task is from.

Expand Down Expand Up @@ -262,6 +263,7 @@ def update_task(
queue=queue,
)
if actions:
_warn_actions_deprecated()
body.additional_properties = {"actions": [a.to_dict() for a in actions]}
if tags:
body.tags = PatchedTaskRequestTags.from_dict(tags)
Expand All @@ -281,6 +283,16 @@ def list_tasks(page_size: int = None, cursor: str = None):
return response.parsed


_ACTIONS_DEPRECATED_MESSAGE = (
"Per-task actions are deprecated in favor of project-level actions and will be "
"removed in a future release. See https://docs.taskbadger.net/actions/."
)


def _warn_actions_deprecated():
warnings.warn(_ACTIONS_DEPRECATED_MESSAGE, DeprecationWarning, stacklevel=3)


def _make_args(**kwargs):
settings = Badger.current.settings
ret_args = settings.as_kwargs()
Expand Down Expand Up @@ -457,7 +469,11 @@ def update(
self._task = task._task

def add_actions(self, actions: list[Action]):
"""Add actions to the task."""
"""Add actions to the task.

**Deprecated:** per-task actions are deprecated in favor of project-level
actions and will be removed in a future release.
"""
self.update(actions=actions)

def tag(self, tags: dict[str, str]):
Expand Down
14 changes: 14 additions & 0 deletions tests/test_sdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,20 @@ def test_add_actions(settings, patched_update):
)


def test_actions_deprecated(settings, patched_create, patched_update):
api_task = task_for_test()
patched_create.return_value = Response(HTTPStatus.OK, b"", {}, api_task)
patched_update.return_value = Response(HTTPStatus.OK, b"", {}, api_task)

action = Action("success", integration=EmailIntegration(to="me@example.com"))

with pytest.warns(DeprecationWarning, match="Per-task actions are deprecated"):
task = Task.create(name="task name", actions=[action])

with pytest.warns(DeprecationWarning, match="Per-task actions are deprecated"):
task.add_actions([action])


def test_action_validation():
WebhookIntegration(id="webhook:123")
with pytest.raises(TaskbadgerException):
Expand Down