diff options
author | Nejc Habjan <hab.nejc@gmail.com> | 2021-02-26 19:30:43 +0100 |
---|---|---|
committer | Nejc Habjan <hab.nejc@gmail.com> | 2021-02-26 20:26:48 +0100 |
commit | dba828b9cfca03f6d339329f9b7d49878cf9e11a (patch) | |
tree | 3dddcf5cc66ab60e8aa5f95875b9ffbcfa20b0e3 | |
parent | 1cc86d8aabc2b472c9d9fda751858146dd584726 (diff) | |
download | gitlab-dba828b9cfca03f6d339329f9b7d49878cf9e11a.tar.gz |
chore(cli): allow overriding current function name for CLI action
-rw-r--r-- | gitlab/cli.py | 11 | ||||
-rw-r--r-- | gitlab/v4/objects/pipelines.py | 2 |
2 files changed, 8 insertions, 5 deletions
diff --git a/gitlab/cli.py b/gitlab/cli.py index 1e98a38..9d3424a 100644 --- a/gitlab/cli.py +++ b/gitlab/cli.py @@ -21,7 +21,7 @@ import argparse import functools import re import sys -from typing import Any, Callable, Dict, Tuple +from typing import Any, Callable, Dict, Optional, Tuple import gitlab.config @@ -36,9 +36,12 @@ custom_actions: Dict[str, Dict[str, Tuple[Tuple[Any, ...], Tuple[Any, ...], bool def register_custom_action( - cls_names, mandatory: Tuple[Any, ...] = tuple(), optional: Tuple[Any, ...] = tuple() + cls_names, + mandatory: Tuple[Any, ...] = tuple(), + optional: Tuple[Any, ...] = tuple(), + custom_action: Optional[str] = None, ) -> Callable: - def wrap(f) -> Callable: + def wrap(f, custom_action: Optional[str] = custom_action) -> Callable: @functools.wraps(f) def wrapped_f(*args, **kwargs): return f(*args, **kwargs) @@ -57,7 +60,7 @@ def register_custom_action( if final_name not in custom_actions: custom_actions[final_name] = {} - action = f.__name__.replace("_", "-") + action = custom_action or f.__name__.replace("_", "-") custom_actions[final_name][action] = (mandatory, optional, in_obj) return wrapped_f diff --git a/gitlab/v4/objects/pipelines.py b/gitlab/v4/objects/pipelines.py index 5469ef7..8024ad1 100644 --- a/gitlab/v4/objects/pipelines.py +++ b/gitlab/v4/objects/pipelines.py @@ -48,7 +48,7 @@ class MergeRequestPipelineManager(CreateMixin, ListMixin, RESTManager): # mr.pipelines(), execute the deprecated method for now. # TODO: in python-gitlab 3.0.0, remove this method entirely. - @cli.register_custom_action("ProjectMergeRequest") + @cli.register_custom_action("ProjectMergeRequest", custom_action="pipelines") @exc.on_http_error(exc.GitlabListError) def __call__(self, **kwargs): """List the merge request pipelines. |