Skip to content

Commit fbbc0d4

Browse files
Ludwig WeissJohnVillalovos
authored andcommitted
feat(api): add deployment mergerequests interface
1 parent 149953d commit fbbc0d4

File tree

4 files changed

+112
-3
lines changed

4 files changed

+112
-3
lines changed

docs/gl_objects/deployments.rst

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,25 @@ Update a deployment::
3939
deployment = project.deployments.get(42)
4040
deployment.status = "failed"
4141
deployment.save()
42+
43+
Merge requests associated with a deployment
44+
===========================================
45+
46+
Reference
47+
----------
48+
49+
* v4 API:
50+
51+
+ :class:`gitlab.v4.objects.ProjectDeploymentMergeRequest`
52+
+ :class:`gitlab.v4.objects.ProjectDeploymentMergeRequestManager`
53+
+ :attr:`gitlab.v4.objects.ProjectDeployment.mergerequests`
54+
55+
* GitLab API: https://docs.gitlab.com/ee/api/deployments.html#list-of-merge-requests-associated-with-a-deployment
56+
57+
Examples
58+
--------
59+
60+
List the merge requests associated with a deployment::
61+
62+
deployment = project.deployments.get(42, lazy=True)
63+
mrs = deployment.mergerequests.list()

gitlab/v4/objects/deployments.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,30 @@
11
from gitlab.base import RequiredOptional, RESTManager, RESTObject
22
from gitlab.mixins import CreateMixin, RetrieveMixin, SaveMixin, UpdateMixin
33

4+
from .merge_requests import ProjectDeploymentMergeRequestManager # noqa: F401
5+
46
__all__ = [
57
"ProjectDeployment",
68
"ProjectDeploymentManager",
79
]
810

911

1012
class ProjectDeployment(SaveMixin, RESTObject):
11-
pass
13+
_managers = (("mergerequests", "ProjectDeploymentMergeRequestManager"),)
1214

1315

1416
class ProjectDeploymentManager(RetrieveMixin, CreateMixin, UpdateMixin, RESTManager):
1517
_path = "/projects/%(project_id)s/deployments"
1618
_obj_cls = ProjectDeployment
1719
_from_parent_attrs = {"project_id": "id"}
18-
_list_filters = ("order_by", "sort")
20+
_list_filters = (
21+
"order_by",
22+
"sort",
23+
"updated_after",
24+
"updated_before",
25+
"environment",
26+
"status",
27+
)
1928
_create_attrs = RequiredOptional(
2029
required=("sha", "ref", "tag", "status", "environment")
2130
)

gitlab/v4/objects/merge_requests.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
"GroupMergeRequestManager",
3737
"ProjectMergeRequest",
3838
"ProjectMergeRequestManager",
39+
"ProjectDeploymentMergeRequest",
40+
"ProjectDeploymentMergeRequestManager",
3941
"ProjectMergeRequestDiff",
4042
"ProjectMergeRequestDiffManager",
4143
]
@@ -48,32 +50,42 @@ class MergeRequest(RESTObject):
4850
class MergeRequestManager(ListMixin, RESTManager):
4951
_path = "/merge_requests"
5052
_obj_cls = MergeRequest
51-
_from_parent_attrs = {"group_id": "id"}
5253
_list_filters = (
5354
"state",
5455
"order_by",
5556
"sort",
5657
"milestone",
5758
"view",
5859
"labels",
60+
"with_labels_details",
61+
"with_merge_status_recheck",
5962
"created_after",
6063
"created_before",
6164
"updated_after",
6265
"updated_before",
6366
"scope",
6467
"author_id",
68+
"author_username",
6569
"assignee_id",
6670
"approver_ids",
6771
"approved_by_ids",
72+
"reviewer_id",
73+
"reviewer_username",
6874
"my_reaction_emoji",
6975
"source_branch",
7076
"target_branch",
7177
"search",
78+
"in",
7279
"wip",
80+
"not",
81+
"environment",
82+
"deployed_before",
83+
"deployed_after",
7384
)
7485
_types = {
7586
"approver_ids": types.ListAttribute,
7687
"approved_by_ids": types.ListAttribute,
88+
"in": types.ListAttribute,
7789
"labels": types.ListAttribute,
7890
}
7991

@@ -409,6 +421,16 @@ class ProjectMergeRequestManager(CRUDMixin, RESTManager):
409421
}
410422

411423

424+
class ProjectDeploymentMergeRequest(MergeRequest):
425+
pass
426+
427+
428+
class ProjectDeploymentMergeRequestManager(MergeRequestManager):
429+
_path = "/projects/%(project_id)s/deployments/%(deployment_id)s/merge_requests"
430+
_obj_cls = ProjectDeploymentMergeRequest
431+
_from_parent_attrs = {"deployment_id": "id", "project_id": "project_id"}
432+
433+
412434
class ProjectMergeRequestDiff(RESTObject):
413435
pass
414436

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
"""
2+
GitLab API:
3+
https://docs.gitlab.com/ce/api/merge_requests.html
4+
https://docs.gitlab.com/ee/api/deployments.html#list-of-merge-requests-associated-with-a-deployment
5+
"""
6+
import re
7+
8+
import pytest
9+
import responses
10+
11+
from gitlab.v4.objects import ProjectDeploymentMergeRequest, ProjectMergeRequest
12+
13+
mr_content = {
14+
"id": 1,
15+
"iid": 1,
16+
"project_id": 3,
17+
"title": "test1",
18+
"description": "fixed login page css paddings",
19+
"state": "merged",
20+
"merged_by": {
21+
"id": 87854,
22+
"name": "Douwe Maan",
23+
"username": "DouweM",
24+
"state": "active",
25+
"avatar_url": "https://gitlab.example.com/uploads/-/system/user/avatar/87854/avatar.png",
26+
"web_url": "https://gitlab.com/DouweM",
27+
},
28+
}
29+
30+
31+
@pytest.fixture
32+
def resp_list_merge_requests():
33+
with responses.RequestsMock() as rsps:
34+
rsps.add(
35+
method=responses.GET,
36+
url=re.compile(
37+
r"http://localhost/api/v4/projects/1/(deployments/1/)?merge_requests"
38+
),
39+
json=[mr_content],
40+
content_type="application/json",
41+
status=200,
42+
)
43+
yield rsps
44+
45+
46+
def test_list_project_merge_requests(project, resp_list_merge_requests):
47+
mrs = project.mergerequests.list()
48+
assert isinstance(mrs[0], ProjectMergeRequest)
49+
assert mrs[0].iid == mr_content["iid"]
50+
51+
52+
def test_list_deployment_merge_requests(project, resp_list_merge_requests):
53+
deployment = project.deployments.get(1, lazy=True)
54+
mrs = deployment.mergerequests.list()
55+
assert isinstance(mrs[0], ProjectDeploymentMergeRequest)
56+
assert mrs[0].iid == mr_content["iid"]

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy