Skip to content

Commit fe496bd

Browse files
authored
Merge pull request #53 from taskbadger/deprecate-actions
Deprecate per-task actions
2 parents 9d5cc7c + 9f523cb commit fe496bd

4 files changed

Lines changed: 36 additions & 6 deletions

File tree

taskbadger/cli/basics.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def create(
5555
"-a",
5656
metavar="<trigger integration config>",
5757
show_default=False,
58-
help="Action definition e.g. 'success,error email to:me@email.com'",
58+
help="[Deprecated] Action definition e.g. 'success,error email to:me@email.com'",
5959
),
6060
status: StatusEnum = typer.Option(StatusEnum.PROCESSING, help="The initial status of the task."),
6161
value_max: int = typer.Option(100, help="The maximum value for the task."),
@@ -118,7 +118,7 @@ def update(
118118
"-a",
119119
metavar="<trigger integration config>",
120120
show_default=False,
121-
help="Action definition e.g. 'success,error email to:me@email.com'",
121+
help="[Deprecated] Action definition e.g. 'success,error email to:me@email.com'",
122122
),
123123
status: StatusEnum = typer.Option(StatusEnum.PROCESSING, help="The status of the task."),
124124
value: int = typer.Option(None, show_default=False, help="The current task value (progress)."),

taskbadger/cli/wrapper.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def run(
1717
"-a",
1818
metavar="<trigger integration config>",
1919
show_default=False,
20-
help="Action definition e.g. 'success,error email to:me@email.com'",
20+
help="[Deprecated] Action definition e.g. 'success,error email to:me@email.com'",
2121
),
2222
tag: list[str] = typer.Option(
2323
None,

taskbadger/sdk.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ def create_task(
163163
data: Custom task data.
164164
max_runtime: Maximum expected runtime (seconds).
165165
stale_timeout: Maximum allowed time between updates (seconds).
166-
actions: Task actions.
166+
actions: Task actions. **Deprecated:** use project-level actions instead.
167167
monitor_id: ID of the monitor to associate this task with.
168168
tags: Dictionary of namespace -> value tags.
169169
queue: Name of the queue the task is from.
@@ -190,6 +190,7 @@ def create_task(
190190
data = data or {}
191191
task_dict["data"] = {**scope.context, **data}
192192
if actions:
193+
_warn_actions_deprecated()
193194
task_dict["actions"] = [a.to_dict() for a in actions]
194195
if scope.tags or tags:
195196
tags = tags or {}
@@ -234,7 +235,7 @@ def update_task(
234235
data: Custom task data.
235236
max_runtime: Maximum expected runtime (seconds).
236237
stale_timeout: Maximum allowed time between updates (seconds).
237-
actions: Task actions.
238+
actions: Task actions. **Deprecated:** use project-level actions instead.
238239
tags: Dictionary of namespace -> value tags.
239240
queue: Name of the queue the task is from.
240241
@@ -262,6 +263,7 @@ def update_task(
262263
queue=queue,
263264
)
264265
if actions:
266+
_warn_actions_deprecated()
265267
body.additional_properties = {"actions": [a.to_dict() for a in actions]}
266268
if tags:
267269
body.tags = PatchedTaskRequestTags.from_dict(tags)
@@ -281,6 +283,16 @@ def list_tasks(page_size: int = None, cursor: str = None):
281283
return response.parsed
282284

283285

286+
_ACTIONS_DEPRECATED_MESSAGE = (
287+
"Per-task actions are deprecated in favor of project-level actions and will be "
288+
"removed in a future release. See https://docs.taskbadger.net/actions/."
289+
)
290+
291+
292+
def _warn_actions_deprecated():
293+
warnings.warn(_ACTIONS_DEPRECATED_MESSAGE, DeprecationWarning, stacklevel=3)
294+
295+
284296
def _make_args(**kwargs):
285297
settings = Badger.current.settings
286298
ret_args = settings.as_kwargs()
@@ -457,7 +469,11 @@ def update(
457469
self._task = task._task
458470

459471
def add_actions(self, actions: list[Action]):
460-
"""Add actions to the task."""
472+
"""Add actions to the task.
473+
474+
**Deprecated:** per-task actions are deprecated in favor of project-level
475+
actions and will be removed in a future release.
476+
"""
461477
self.update(actions=actions)
462478

463479
def tag(self, tags: dict[str, str]):

tests/test_sdk.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,20 @@ def test_add_actions(settings, patched_update):
312312
)
313313

314314

315+
def test_actions_deprecated(settings, patched_create, patched_update):
316+
api_task = task_for_test()
317+
patched_create.return_value = Response(HTTPStatus.OK, b"", {}, api_task)
318+
patched_update.return_value = Response(HTTPStatus.OK, b"", {}, api_task)
319+
320+
action = Action("success", integration=EmailIntegration(to="me@example.com"))
321+
322+
with pytest.warns(DeprecationWarning, match="Per-task actions are deprecated"):
323+
task = Task.create(name="task name", actions=[action])
324+
325+
with pytest.warns(DeprecationWarning, match="Per-task actions are deprecated"):
326+
task.add_actions([action])
327+
328+
315329
def test_action_validation():
316330
WebhookIntegration(id="webhook:123")
317331
with pytest.raises(TaskbadgerException):

0 commit comments

Comments
 (0)