summaryrefslogtreecommitdiff
path: root/gitlab
diff options
context:
space:
mode:
authorMax Wittig <max.wittig@siemens.com>2020-08-29 12:11:06 +0200
committerGitHub <noreply@github.com>2020-08-29 12:11:06 +0200
commit750f4ee6554381830e6add55583903919db2ba29 (patch)
tree6cca4ff3b67741c85bbbf3a58f98852bdc4f53e5 /gitlab
parent26f95f30a5219243f33d505747c65f798ac6a486 (diff)
parent696147922552a8e6ddda3a5b852ee2de6b983e37 (diff)
downloadgitlab-750f4ee6554381830e6add55583903919db2ba29.tar.gz
Merge pull request #1157 from Shkurupii/issue-1154
Add support to resource milestone events
Diffstat (limited to 'gitlab')
-rw-r--r--gitlab/tests/objects/test_resource_milestone_events.py73
-rw-r--r--gitlab/v4/objects.py24
2 files changed, 97 insertions, 0 deletions
diff --git a/gitlab/tests/objects/test_resource_milestone_events.py b/gitlab/tests/objects/test_resource_milestone_events.py
new file mode 100644
index 0000000..99faeaa
--- /dev/null
+++ b/gitlab/tests/objects/test_resource_milestone_events.py
@@ -0,0 +1,73 @@
+"""
+GitLab API: https://docs.gitlab.com/ee/api/resource_milestone_events.html
+"""
+
+import pytest
+import responses
+
+from gitlab.v4.objects import (
+ ProjectIssueResourceMilestoneEvent,
+ ProjectMergeRequestResourceMilestoneEvent,
+)
+
+
+@pytest.fixture()
+def resp_merge_request_milestone_events():
+ mr_content = {"iid": 1}
+ events_content = {"id": 1, "resource_type": "MergeRequest"}
+ with responses.RequestsMock() as rsps:
+ rsps.add(
+ method=responses.GET,
+ url="http://localhost/api/v4/projects/1/merge_requests",
+ json=[mr_content],
+ content_type="application/json",
+ status=200,
+ )
+ rsps.add(
+ method=responses.GET,
+ url="http://localhost/api/v4/projects/1/merge_requests/1/resource_milestone_events",
+ json=[events_content],
+ content_type="application/json",
+ status=200,
+ )
+ yield rsps
+
+
+@pytest.fixture()
+def resp_project_issue_milestone_events():
+ issue_content = {"iid": 1}
+ events_content = {"id": 1, "resource_type": "Issue"}
+ with responses.RequestsMock() as rsps:
+ rsps.add(
+ method=responses.GET,
+ url="http://localhost/api/v4/projects/1/issues",
+ json=[issue_content],
+ content_type="application/json",
+ status=200,
+ )
+ rsps.add(
+ method=responses.GET,
+ url="http://localhost/api/v4/projects/1/issues/1/resource_milestone_events",
+ json=[events_content],
+ content_type="application/json",
+ status=200,
+ )
+ yield rsps
+
+
+def test_project_issue_milestone_events(project, resp_project_issue_milestone_events):
+ issue = project.issues.list()[0]
+ milestone_events = issue.resourcemilestoneevents.list()
+ assert isinstance(milestone_events, list)
+ milestone_event = milestone_events[0]
+ assert isinstance(milestone_event, ProjectIssueResourceMilestoneEvent)
+ assert milestone_event.resource_type == "Issue"
+
+
+def test_merge_request_milestone_events(project, resp_merge_request_milestone_events):
+ mr = project.mergerequests.list()[0]
+ milestone_events = mr.resourcemilestoneevents.list()
+ assert isinstance(milestone_events, list)
+ milestone_event = milestone_events[0]
+ assert isinstance(milestone_event, ProjectMergeRequestResourceMilestoneEvent)
+ assert milestone_event.resource_type == "MergeRequest"
diff --git a/gitlab/v4/objects.py b/gitlab/v4/objects.py
index 8d24b52..e7d7d23 100644
--- a/gitlab/v4/objects.py
+++ b/gitlab/v4/objects.py
@@ -2682,6 +2682,16 @@ class ProjectIssueResourceLabelEventManager(RetrieveMixin, RESTManager):
_from_parent_attrs = {"project_id": "project_id", "issue_iid": "iid"}
+class ProjectIssueResourceMilestoneEvent(RESTObject):
+ pass
+
+
+class ProjectIssueResourceMilestoneEventManager(RetrieveMixin, RESTManager):
+ _path = "/projects/%(project_id)s/issues/%(issue_iid)s/resource_milestone_events"
+ _obj_cls = ProjectIssueResourceMilestoneEvent
+ _from_parent_attrs = {"project_id": "project_id", "issue_iid": "iid"}
+
+
class ProjectIssue(
UserAgentDetailMixin,
SubscribableMixin,
@@ -2700,6 +2710,7 @@ class ProjectIssue(
("links", "ProjectIssueLinkManager"),
("notes", "ProjectIssueNoteManager"),
("resourcelabelevents", "ProjectIssueResourceLabelEventManager"),
+ ("resourcemilestoneevents", "ProjectIssueResourceMilestoneEventManager"),
)
@cli.register_custom_action("ProjectIssue", ("to_project_id",))
@@ -3109,6 +3120,18 @@ class ProjectMergeRequestResourceLabelEventManager(RetrieveMixin, RESTManager):
_from_parent_attrs = {"project_id": "project_id", "mr_iid": "iid"}
+class ProjectMergeRequestResourceMilestoneEvent(RESTObject):
+ pass
+
+
+class ProjectMergeRequestResourceMilestoneEventManager(RetrieveMixin, RESTManager):
+ _path = (
+ "/projects/%(project_id)s/merge_requests/%(mr_iid)s/resource_milestone_events"
+ )
+ _obj_cls = ProjectMergeRequestResourceMilestoneEvent
+ _from_parent_attrs = {"project_id": "project_id", "mr_iid": "iid"}
+
+
class ProjectMergeRequest(
SubscribableMixin,
TodoMixin,
@@ -3127,6 +3150,7 @@ class ProjectMergeRequest(
("discussions", "ProjectMergeRequestDiscussionManager"),
("notes", "ProjectMergeRequestNoteManager"),
("resourcelabelevents", "ProjectMergeRequestResourceLabelEventManager"),
+ ("resourcemilestoneevents", "ProjectMergeRequestResourceMilestoneEventManager"),
)
@cli.register_custom_action("ProjectMergeRequest")