summaryrefslogtreecommitdiff
path: root/gitlab
diff options
context:
space:
mode:
authorNejc Habjan <hab.nejc@gmail.com>2021-02-24 00:18:49 +0100
committerNejc Habjan <hab.nejc@gmail.com>2021-06-13 21:18:44 +0200
commit954357c49963ef51945c81c41fd4345002f9fb98 (patch)
tree13cd0da13d9a747cae56eff45fe27244f3c13a51 /gitlab
parente3aa0238da48589d41c84e3102611eb21d032ea5 (diff)
downloadgitlab-954357c49963ef51945c81c41fd4345002f9fb98.tar.gz
feat(api): add MR pipeline manager in favor of pipelines() method
Diffstat (limited to 'gitlab')
-rw-r--r--gitlab/cli.py3
-rw-r--r--gitlab/v4/objects/merge_requests.py21
-rw-r--r--gitlab/v4/objects/pipelines.py41
3 files changed, 45 insertions, 20 deletions
diff --git a/gitlab/cli.py b/gitlab/cli.py
index a5044ff..c053a38 100644
--- a/gitlab/cli.py
+++ b/gitlab/cli.py
@@ -53,6 +53,7 @@ def register_custom_action(
cls_names: Union[str, Tuple[str, ...]],
mandatory: Tuple[str, ...] = tuple(),
optional: Tuple[str, ...] = tuple(),
+ custom_action: Optional[str] = None,
) -> Callable[[__F], __F]:
def wrap(f: __F) -> __F:
@functools.wraps(f)
@@ -74,7 +75,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 cast(__F, wrapped_f)
diff --git a/gitlab/v4/objects/merge_requests.py b/gitlab/v4/objects/merge_requests.py
index dd118d0..e8c2a96 100644
--- a/gitlab/v4/objects/merge_requests.py
+++ b/gitlab/v4/objects/merge_requests.py
@@ -28,6 +28,7 @@ from .merge_request_approvals import ( # noqa: F401
ProjectMergeRequestApprovalRuleManager,
)
from .notes import ProjectMergeRequestNoteManager # noqa: F401
+from .pipelines import ProjectMergeRequestPipelineManager # noqa: F401
__all__ = [
"MergeRequest",
@@ -145,6 +146,7 @@ class ProjectMergeRequest(
("diffs", "ProjectMergeRequestDiffManager"),
("discussions", "ProjectMergeRequestDiscussionManager"),
("notes", "ProjectMergeRequestNoteManager"),
+ ("pipelines", "ProjectMergeRequestPipelineManager"),
("resourcelabelevents", "ProjectMergeRequestResourceLabelEventManager"),
("resourcemilestoneevents", "ProjectMergeRequestResourceMilestoneEventManager"),
("resourcestateevents", "ProjectMergeRequestResourceStateEventManager"),
@@ -240,25 +242,6 @@ class ProjectMergeRequest(
path = "%s/%s/changes" % (self.manager.path, self.get_id())
return self.manager.gitlab.http_get(path, **kwargs)
- @cli.register_custom_action("ProjectMergeRequest")
- @exc.on_http_error(exc.GitlabListError)
- def pipelines(self, **kwargs):
- """List the merge request pipelines.
-
- Args:
- **kwargs: Extra options to send to the server (e.g. sudo)
-
- Raises:
- GitlabAuthenticationError: If authentication is not correct
- GitlabListError: If the list could not be retrieved
-
- Returns:
- RESTObjectList: List of changes
- """
-
- path = "%s/%s/pipelines" % (self.manager.path, self.get_id())
- return self.manager.gitlab.http_get(path, **kwargs)
-
@cli.register_custom_action("ProjectMergeRequest", tuple(), ("sha",))
@exc.on_http_error(exc.GitlabMRApprovalError)
def approve(self, sha=None, **kwargs):
diff --git a/gitlab/v4/objects/pipelines.py b/gitlab/v4/objects/pipelines.py
index 79b0802..5118e78 100644
--- a/gitlab/v4/objects/pipelines.py
+++ b/gitlab/v4/objects/pipelines.py
@@ -1,3 +1,5 @@
+import warnings
+
from gitlab import cli
from gitlab import exceptions as exc
from gitlab.base import RequiredOptional, RESTManager, RESTObject
@@ -15,6 +17,8 @@ from gitlab.mixins import (
)
__all__ = [
+ "ProjectMergeRequestPipeline",
+ "ProjectMergeRequestPipelineManager",
"ProjectPipeline",
"ProjectPipelineManager",
"ProjectPipelineJob",
@@ -32,6 +36,43 @@ __all__ = [
]
+class ProjectMergeRequestPipeline(RESTObject):
+ pass
+
+
+class ProjectMergeRequestPipelineManager(CreateMixin, ListMixin, RESTManager):
+ _path = "/projects/%(project_id)s/merge_requests/%(mr_iid)s/pipelines"
+ _obj_cls = ProjectMergeRequestPipeline
+ _from_parent_attrs = {"project_id": "project_id", "mr_iid": "iid"}
+
+ # If the manager was called directly as a callable via
+ # mr.pipelines(), execute the deprecated method for now.
+ # TODO: in python-gitlab 3.0.0, remove this method entirely.
+
+ @cli.register_custom_action("ProjectMergeRequest", custom_action="pipelines")
+ @exc.on_http_error(exc.GitlabListError)
+ def __call__(self, **kwargs):
+ """List the merge request pipelines.
+
+ Args:
+ **kwargs: Extra options to send to the server (e.g. sudo)
+
+ Raises:
+ GitlabAuthenticationError: If authentication is not correct
+ GitlabListError: If the list could not be retrieved
+
+ Returns:
+ RESTObjectList: List of changes
+ """
+ warnings.warn(
+ "Calling the ProjectMergeRequest.pipelines() method on "
+ "merge request objects directly is deprecated and will be replaced "
+ "by ProjectMergeRequest.pipelines.list() in python-gitlab 3.0.0.\n",
+ DeprecationWarning,
+ )
+ return self.list(**kwargs)
+
+
class ProjectPipeline(RefreshMixin, ObjectDeleteMixin, RESTObject):
_managers = (
("jobs", "ProjectPipelineJobManager"),