summaryrefslogtreecommitdiff
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
parent26f95f30a5219243f33d505747c65f798ac6a486 (diff)
parent696147922552a8e6ddda3a5b852ee2de6b983e37 (diff)
downloadgitlab-750f4ee6554381830e6add55583903919db2ba29.tar.gz
Merge pull request #1157 from Shkurupii/issue-1154
Add support to resource milestone events
-rw-r--r--docs/gl_objects/milestones.rst33
-rw-r--r--gitlab/tests/objects/test_resource_milestone_events.py73
-rw-r--r--gitlab/v4/objects.py24
-rw-r--r--tools/python_test_v4.py13
4 files changed, 143 insertions, 0 deletions
diff --git a/docs/gl_objects/milestones.rst b/docs/gl_objects/milestones.rst
index f24e13f..40f9ba6 100644
--- a/docs/gl_objects/milestones.rst
+++ b/docs/gl_objects/milestones.rst
@@ -2,6 +2,9 @@
Milestones
##########
+Project milestones
+==================
+
Reference
---------
@@ -70,3 +73,33 @@ List the issues related to a milestone::
List the merge requests related to a milestone::
merge_requests = milestone.merge_requests()
+
+Milestone events
+============
+
+Resource milestone events keep track of what happens to GitLab issues and merge requests.
+
+Reference
+---------
+
+* v4 API:
+
+ + :class:`gitlab.v4.objects.ProjectIssueResourceMilestoneEvent`
+ + :class:`gitlab.v4.objects.ProjectIssueResourceMilestoneEventManager`
+ + :attr:`gitlab.v4.objects.ProjectIssue.resourcemilestoneevents`
+ + :class:`gitlab.v4.objects.ProjectMergeRequestResourceMilestoneEvent`
+ + :class:`gitlab.v4.objects.ProjectMergeRequestResourceMilestoneEventManager`
+ + :attr:`gitlab.v4.objects.ProjectMergeRequest.resourcemilestoneevents`
+
+* GitLab API: https://docs.gitlab.com/ee/api/resource_milestone_events.html
+
+Examples
+--------
+
+Get milestones for a resource (issue, merge request)::
+
+ milestones = resource.resourcemilestoneevents.list()
+
+Get a specific milestone for a resource::
+
+ milestone = resource.resourcemilestoneevents.get(milestone_id)
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")
diff --git a/tools/python_test_v4.py b/tools/python_test_v4.py
index 8c548be..21faf9e 100644
--- a/tools/python_test_v4.py
+++ b/tools/python_test_v4.py
@@ -787,6 +787,11 @@ assert events
event = issue1.resourcelabelevents.get(events[0].id)
assert event
+# issue milestones
+milestones = issue1.resourcemilestoneevents.list()
+assert milestones
+milestone = issue1.resourcemilestoneevents.get(milestones[0].id)
+assert milestone
size = len(issue1.discussions.list())
discussion = issue1.discussions.create({"body": "Discussion body"})
@@ -896,6 +901,14 @@ assert events
event = mr.resourcelabelevents.get(events[0].id)
assert event
+# mr milestone events
+mr.milestone_id = m1.id
+mr.save()
+milestones = mr.resourcemilestoneevents.list()
+assert milestones
+milestone = mr.resourcemilestoneevents.get(milestones[0].id)
+assert milestone
+
# rebasing
assert mr.rebase()