Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 0d16dfd

Browse files
author
Sascha Mahmood
committedFeb 15, 2017
Added gitlabs time tracking features
- get/set/remove estimated time per issue - get/set/remove time spent per issu
1 parent 1e0ae59 commit 0d16dfd

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed
 

‎gitlab/exceptions.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,10 @@ class GitlabTodoError(GitlabOperationError):
143143
pass
144144

145145

146+
class GitlabTimeTrackingError(GitlabOperationError):
147+
pass
148+
149+
146150
def raise_error_from_response(response, error, expected_code=200):
147151
"""Tries to parse gitlab error message from response and raises error.
148152

‎gitlab/objects.py

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1525,6 +1525,65 @@ def todo(self, **kwargs):
15251525
r = self.gitlab._raw_post(url, **kwargs)
15261526
raise_error_from_response(r, GitlabTodoError, [201, 304])
15271527

1528+
def time_stats(self, **kwargs):
1529+
"""Get time stats for the issue.
1530+
1531+
Raises:
1532+
GitlabConnectionError: If the server cannot be reached.
1533+
"""
1534+
url = ('/projects/%(project_id)s/issues/%(issue_id)s/time_stats' %
1535+
{'project_id': self.project_id, 'issue_id': self.id})
1536+
r = self.gitlab._raw_get(url, **kwargs)
1537+
raise_error_from_response(r, GitlabGetError)
1538+
return r.json()
1539+
1540+
def time_estimate(self, **kwargs):
1541+
"""Set an estimated time of work for the issue.
1542+
1543+
Raises:
1544+
GitlabConnectionError: If the server cannot be reached.
1545+
"""
1546+
url = ('/projects/%(project_id)s/issues/%(issue_id)s/time_estimate' %
1547+
{'project_id': self.project_id, 'issue_id': self.id})
1548+
r = self.gitlab._raw_post(url, **kwargs)
1549+
raise_error_from_response(r, GitlabTimeTrackingError, 201)
1550+
return r.json()
1551+
1552+
def reset_time_estimate(self, **kwargs):
1553+
"""Resets estimated time for the issue to 0 seconds.
1554+
1555+
Raises:
1556+
GitlabConnectionError: If the server cannot be reached.
1557+
"""
1558+
url = ('/projects/%(project_id)s/issues/%(issue_id)s/reset_time_estimate' %
1559+
{'project_id': self.project_id, 'issue_id': self.id})
1560+
r = self.gitlab._raw_post(url, **kwargs)
1561+
raise_error_from_response(r, GitlabTimeTrackingError, 200)
1562+
return r.json()
1563+
1564+
def add_spent_time(self, **kwargs):
1565+
"""Set an estimated time of work for the issue.
1566+
1567+
Raises:
1568+
GitlabConnectionError: If the server cannot be reached.
1569+
"""
1570+
url = ('/projects/%(project_id)s/issues/%(issue_id)s/reset_spent_time' %
1571+
{'project_id': self.project_id, 'issue_id': self.id})
1572+
r = self.gitlab._raw_post(url, **kwargs)
1573+
raise_error_from_response(r, GitlabTimeTrackingError, 200)
1574+
return r.json()
1575+
1576+
def reset_spent_time(self, **kwargs):
1577+
"""Set an estimated time of work for the issue.
1578+
1579+
Raises:
1580+
GitlabConnectionError: If the server cannot be reached.
1581+
"""
1582+
url = ('/projects/%(project_id)s/issues/%(issue_id)s/add_spent_time' %
1583+
{'project_id': self.project_id, 'issue_id': self.id})
1584+
r = self.gitlab._raw_post(url, **kwargs)
1585+
raise_error_from_response(r, GitlabTimeTrackingError, 200)
1586+
return r.json()
15281587

15291588
class ProjectIssueManager(BaseManager):
15301589
obj_cls = ProjectIssue

0 commit comments

Comments
 (0)
Failed to load comments.