| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 149953d commit fbbc0d4
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -39,3 +39,25 @@ Update a deployment:: | |||
| 39 | 39 | deployment = project.deployments.get(42) | |
| 40 | 40 | deployment.status = "failed" | |
| 41 | 41 | 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() | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,21 +1,30 @@ | |||
| 1 | 1 | from gitlab.base import RequiredOptional, RESTManager, RESTObject | |
| 2 | 2 | from gitlab.mixins import CreateMixin, RetrieveMixin, SaveMixin, UpdateMixin | |
| 3 | 3 | ||
| 4 | + from .merge_requests import ProjectDeploymentMergeRequestManager # noqa: F401 | ||
| 5 | + | ||
| 4 | 6 | __all__ = [ | |
| 5 | 7 | "ProjectDeployment", | |
| 6 | 8 | "ProjectDeploymentManager", | |
| 7 | 9 | ] | |
| 8 | 10 | ||
| 9 | 11 | ||
| 10 | 12 | class ProjectDeployment(SaveMixin, RESTObject): | |
| 11 | - pass | ||
| 13 | + _managers = (("mergerequests", "ProjectDeploymentMergeRequestManager"),) | ||
| 12 | 14 | ||
| 13 | 15 | ||
| 14 | 16 | class ProjectDeploymentManager(RetrieveMixin, CreateMixin, UpdateMixin, RESTManager): | |
| 15 | 17 | _path = "/projects/%(project_id)s/deployments" | |
| 16 | 18 | _obj_cls = ProjectDeployment | |
| 17 | 19 | _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 | + ) | ||
| 19 | 28 | _create_attrs = RequiredOptional( | |
| 20 | 29 | required=("sha", "ref", "tag", "status", "environment") | |
| 21 | 30 | ) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -36,6 +36,8 @@ | |||
| 36 | 36 | "GroupMergeRequestManager", | |
| 37 | 37 | "ProjectMergeRequest", | |
| 38 | 38 | "ProjectMergeRequestManager", | |
| 39 | + "ProjectDeploymentMergeRequest", | ||
| 40 | + "ProjectDeploymentMergeRequestManager", | ||
| 39 | 41 | "ProjectMergeRequestDiff", | |
| 40 | 42 | "ProjectMergeRequestDiffManager", | |
| 41 | 43 | ] | |
@@ -48,32 +50,42 @@ class MergeRequest(RESTObject): | |||
| 48 | 50 | class MergeRequestManager(ListMixin, RESTManager): | |
| 49 | 51 | _path = "/merge_requests" | |
| 50 | 52 | _obj_cls = MergeRequest | |
| 51 | - _from_parent_attrs = {"group_id": "id"} | ||
| 52 | 53 | _list_filters = ( | |
| 53 | 54 | "state", | |
| 54 | 55 | "order_by", | |
| 55 | 56 | "sort", | |
| 56 | 57 | "milestone", | |
| 57 | 58 | "view", | |
| 58 | 59 | "labels", | |
| 60 | + "with_labels_details", | ||
| 61 | + "with_merge_status_recheck", | ||
| 59 | 62 | "created_after", | |
| 60 | 63 | "created_before", | |
| 61 | 64 | "updated_after", | |
| 62 | 65 | "updated_before", | |
| 63 | 66 | "scope", | |
| 64 | 67 | "author_id", | |
| 68 | + "author_username", | ||
| 65 | 69 | "assignee_id", | |
| 66 | 70 | "approver_ids", | |
| 67 | 71 | "approved_by_ids", | |
| 72 | + "reviewer_id", | ||
| 73 | + "reviewer_username", | ||
| 68 | 74 | "my_reaction_emoji", | |
| 69 | 75 | "source_branch", | |
| 70 | 76 | "target_branch", | |
| 71 | 77 | "search", | |
| 78 | + "in", | ||
| 72 | 79 | "wip", | |
| 80 | + "not", | ||
| 81 | + "environment", | ||
| 82 | + "deployed_before", | ||
| 83 | + "deployed_after", | ||
| 73 | 84 | ) | |
| 74 | 85 | _types = { | |
| 75 | 86 | "approver_ids": types.ListAttribute, | |
| 76 | 87 | "approved_by_ids": types.ListAttribute, | |
| 88 | + "in": types.ListAttribute, | ||
| 77 | 89 | "labels": types.ListAttribute, | |
| 78 | 90 | } | |
| 79 | 91 | ||
@@ -409,6 +421,16 @@ class ProjectMergeRequestManager(CRUDMixin, RESTManager): | |||
| 409 | 421 | } | |
| 410 | 422 | ||
| 411 | 423 | ||
| 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 | + | ||
| 412 | 434 | class ProjectMergeRequestDiff(RESTObject): | |
| 413 | 435 | pass | |
| 414 | 436 | ||
| Original file line number | Diff line number | Diff 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"] | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments