Skip to content

Commit dba828b

Browse files
committed
chore(cli): allow overriding current function name for CLI action
1 parent 1cc86d8 commit dba828b

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

gitlab/cli.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import functools
2222
import re
2323
import sys
24-
from typing import Any, Callable, Dict, Tuple
24+
from typing import Any, Callable, Dict, Optional, Tuple
2525

2626
import gitlab.config
2727

@@ -36,9 +36,12 @@
3636

3737

3838
def register_custom_action(
39-
cls_names, mandatory: Tuple[Any, ...] = tuple(), optional: Tuple[Any, ...] = tuple()
39+
cls_names,
40+
mandatory: Tuple[Any, ...] = tuple(),
41+
optional: Tuple[Any, ...] = tuple(),
42+
custom_action: Optional[str] = None,
4043
) -> Callable:
41-
def wrap(f) -> Callable:
44+
def wrap(f, custom_action: Optional[str] = custom_action) -> Callable:
4245
@functools.wraps(f)
4346
def wrapped_f(*args, **kwargs):
4447
return f(*args, **kwargs)
@@ -57,7 +60,7 @@ def wrapped_f(*args, **kwargs):
5760
if final_name not in custom_actions:
5861
custom_actions[final_name] = {}
5962

60-
action = f.__name__.replace("_", "-")
63+
action = custom_action or f.__name__.replace("_", "-")
6164
custom_actions[final_name][action] = (mandatory, optional, in_obj)
6265

6366
return wrapped_f

gitlab/v4/objects/pipelines.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class MergeRequestPipelineManager(CreateMixin, ListMixin, RESTManager):
4848
# mr.pipelines(), execute the deprecated method for now.
4949
# TODO: in python-gitlab 3.0.0, remove this method entirely.
5050

51-
@cli.register_custom_action("ProjectMergeRequest")
51+
@cli.register_custom_action("ProjectMergeRequest", custom_action="pipelines")
5252
@exc.on_http_error(exc.GitlabListError)
5353
def __call__(self, **kwargs):
5454
"""List the merge request pipelines.

0 commit comments

Comments
 (0)