Skip to content

Time tracking #222

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Mar 3, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions docs/gl_objects/issues.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,23 @@
# project issue todo
issue.todo()
# end project issue todo

# project issue time tracking stats
issue.time_stats()
# end project issue time tracking stats

# project issue set time estimate
issue.set_time_estimate({'duration': '3h30m'})
# end project issue set time estimate

# project issue reset time estimate
issue.reset_time_estimate()
# end project issue reset time estimate

# project issue set time spent
issue.add_time_spent({'duration': '3h30m'})
# end project issue set time spent

# project issue reset time spent
issue.reset_time_spent()
# end project issue reset time spent
31 changes: 31 additions & 0 deletions docs/gl_objects/issues.rst
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,34 @@ Make an issue as todo:
.. literalinclude:: issues.py
:start-after: # project issue todo
:end-before: # end project issue todo

Get time tracking stats:

.. literalinclude:: issues.py
:start-after: # project issue time tracking stats
:end-before: # end project time tracking stats

Set a time estimate for an issue:

.. literalinclude:: issues.py
:start-after: # project issue set time estimate
:end-before: # end project set time estimate

Reset a time estimate for an issue:

.. literalinclude:: issues.py
:start-after: # project issue reset time estimate
:end-before: # end project reset time estimate

Add spent time for an issue:

.. literalinclude:: issues.py
:start-after: # project issue set time spent
:end-before: # end project set time spent

Reset spent time for an issue:

.. literalinclude:: issues.py
:start-after: # project issue reset time spent
:end-before: # end project reset time spent

4 changes: 4 additions & 0 deletions gitlab/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ class GitlabTodoError(GitlabOperationError):
pass


class GitlabTimeTrackingError(GitlabOperationError):
pass


def raise_error_from_response(response, error, expected_code=200):
"""Tries to parse gitlab error message from response and raises error.

Expand Down
63 changes: 63 additions & 0 deletions gitlab/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -1525,6 +1525,69 @@ def todo(self, **kwargs):
r = self.gitlab._raw_post(url, **kwargs)
raise_error_from_response(r, GitlabTodoError, [201, 304])

def time_stats(self, **kwargs):
"""Get time stats for the issue.

Raises:
GitlabConnectionError: If the server cannot be reached.
"""
url = ('/projects/%(project_id)s/issues/%(issue_id)s/time_stats' %
{'project_id': self.project_id, 'issue_id': self.id})
r = self.gitlab._raw_get(url, **kwargs)
raise_error_from_response(r, GitlabGetError)
return r.json()

def time_estimate(self, **kwargs):
"""Set an estimated time of work for the issue.

Raises:
GitlabConnectionError: If the server cannot be reached.
"""
url = ('/projects/%(project_id)s/issues/%(issue_id)s/time_estimate' %
{'project_id': self.project_id, 'issue_id': self.id})
r = self.gitlab._raw_post(url, **kwargs)
raise_error_from_response(r, GitlabTimeTrackingError, 201)
return r.json()

def reset_time_estimate(self, **kwargs):
"""Resets estimated time for the issue to 0 seconds.

Raises:
GitlabConnectionError: If the server cannot be reached.
"""
url = ('/projects/%(project_id)s/issues/%(issue_id)s/'
'reset_time_estimate' %
{'project_id': self.project_id, 'issue_id': self.id})
r = self.gitlab._raw_post(url, **kwargs)
raise_error_from_response(r, GitlabTimeTrackingError, 200)
return r.json()

def add_spent_time(self, **kwargs):
"""Set an estimated time of work for the issue.

Raises:
GitlabConnectionError: If the server cannot be reached.
"""
url = ('/projects/%(project_id)s/issues/%(issue_id)s/'
'reset_spent_time' %
{'project_id': self.project_id, 'issue_id': self.id})
r = self.gitlab._raw_post(url, **kwargs)
raise_error_from_response(r, GitlabTimeTrackingError, 200)
return r.json()

def reset_spent_time(self, **kwargs):
"""Set an estimated time of work for the issue.

Raises:
GitlabConnectionError: If the server cannot be reached.
"""
url = ('/projects/%(project_id)s/issues/%(issue_id)s/'
'add_spent_time' %
{'project_id': self.project_id, 'issue_id': self.id})
r = self.gitlab._raw_post(url, **kwargs)
raise_error_from_response(r, GitlabTimeTrackingError, 200)
return r.json()


class ProjectIssueManager(BaseManager):
obj_cls = ProjectIssue
Expand Down