diff options
| author | John Villalovos <john@sodarock.com> | 2021-06-14 10:57:59 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-06-14 10:57:59 -0700 |
| commit | e77554c18f87a24ea1367cf9e2e53c48ad6ce3e4 (patch) | |
| tree | 86f36a08f17597a36b46b0022f4d4da36de8a4d2 /gitlab/v4/objects | |
| parent | 1f5b3c03b2ae451dfe518ed65ec2bec4e80c09d1 (diff) | |
| parent | 954357c49963ef51945c81c41fd4345002f9fb98 (diff) | |
| download | gitlab-e77554c18f87a24ea1367cf9e2e53c48ad6ce3e4.tar.gz | |
Merge pull request #1323 from python-gitlab/feat/mr-pipeline-manager
feat(api): add merge request pipeline manager and deprecate mr.pipelines() method
Diffstat (limited to 'gitlab/v4/objects')
| -rw-r--r-- | gitlab/v4/objects/merge_requests.py | 21 | ||||
| -rw-r--r-- | gitlab/v4/objects/pipelines.py | 41 |
2 files changed, 43 insertions, 19 deletions
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"), |
