Skip to content

Commit 324f81b

Browse files
author
Gauvain Pocentek
committed
MR: add support for time tracking features
Fixes #248
1 parent 391417c commit 324f81b

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

gitlab/objects.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1850,6 +1850,58 @@ def time_stats(self, **kwargs):
18501850
raise_error_from_response(r, GitlabGetError)
18511851
return r.json()
18521852

1853+
def time_estimate(self, **kwargs):
1854+
"""Set an estimated time of work for the merge request.
1855+
1856+
Raises:
1857+
GitlabConnectionError: If the server cannot be reached.
1858+
"""
1859+
url = ('/projects/%(project_id)s/merge_requests/%(mr_id)s/'
1860+
'time_estimate' %
1861+
{'project_id': self.project_id, 'mr_id': self.id})
1862+
r = self.gitlab._raw_post(url, **kwargs)
1863+
raise_error_from_response(r, GitlabTimeTrackingError, 201)
1864+
return r.json()
1865+
1866+
def reset_time_estimate(self, **kwargs):
1867+
"""Resets estimated time for the merge request to 0 seconds.
1868+
1869+
Raises:
1870+
GitlabConnectionError: If the server cannot be reached.
1871+
"""
1872+
url = ('/projects/%(project_id)s/merge_requests/%(mr_id)s/'
1873+
'reset_time_estimate' %
1874+
{'project_id': self.project_id, 'mr_id': self.id})
1875+
r = self.gitlab._raw_post(url, **kwargs)
1876+
raise_error_from_response(r, GitlabTimeTrackingError, 200)
1877+
return r.json()
1878+
1879+
def add_spent_time(self, **kwargs):
1880+
"""Set an estimated time of work for the merge request.
1881+
1882+
Raises:
1883+
GitlabConnectionError: If the server cannot be reached.
1884+
"""
1885+
url = ('/projects/%(project_id)s/merge_requests/%(mr_id)s/'
1886+
'add_spent_time' %
1887+
{'project_id': self.project_id, 'mr_id': self.id})
1888+
r = self.gitlab._raw_post(url, **kwargs)
1889+
raise_error_from_response(r, GitlabTimeTrackingError, 200)
1890+
return r.json()
1891+
1892+
def reset_spent_time(self, **kwargs):
1893+
"""Set an estimated time of work for the merge request.
1894+
1895+
Raises:
1896+
GitlabConnectionError: If the server cannot be reached.
1897+
"""
1898+
url = ('/projects/%(project_id)s/merge_requests/%(mr_id)s/'
1899+
'reset_spent_time' %
1900+
{'project_id': self.project_id, 'mr_id': self.id})
1901+
r = self.gitlab._raw_post(url, **kwargs)
1902+
raise_error_from_response(r, GitlabTimeTrackingError, 200)
1903+
return r.json()
1904+
18531905

18541906
class ProjectMergeRequestManager(BaseManager):
18551907
obj_cls = ProjectMergeRequest

0 commit comments

Comments
 (0)