Skip to content

Commit

Permalink
[v4] Make project issues work properly
Browse files Browse the repository at this point in the history
* Use iids instead of ids
* Add required duration argument for time_estimate() and
  add_spent_time()
  • Loading branch information
Gauvain Pocentek committed May 27, 2017
1 parent f3b2855 commit ac3aef6
Showing 1 changed file with 36 additions and 27 deletions.
63 changes: 36 additions & 27 deletions gitlab/v4/objects.py
Expand Up @@ -850,10 +850,10 @@ class ProjectHookManager(BaseManager):


class ProjectIssueNote(GitlabObject):
_url = '/projects/%(project_id)s/issues/%(issue_id)s/notes'
_url = '/projects/%(project_id)s/issues/%(issue_iid)s/notes'
_constructorTypes = {'author': 'User'}
canDelete = False
requiredUrlAttrs = ['project_id', 'issue_id']
requiredUrlAttrs = ['project_id', 'issue_iid']
requiredCreateAttrs = ['body']
optionalCreateAttrs = ['created_at']

Expand All @@ -875,9 +875,10 @@ class ProjectIssue(GitlabObject):
'milestone_id', 'labels', 'created_at',
'updated_at', 'state_event', 'due_date']
shortPrintAttr = 'title'
idAttr = 'iid'
managers = (
('notes', 'ProjectIssueNoteManager',
[('project_id', 'project_id'), ('issue_id', 'id')]),
[('project_id', 'project_id'), ('issue_iid', 'iid')]),
)

def subscribe(self, **kwargs):
Expand All @@ -887,8 +888,8 @@ def subscribe(self, **kwargs):
GitlabConnectionError: If the server cannot be reached.
GitlabSubscribeError: If the subscription cannot be done
"""
url = ('/projects/%(project_id)s/issues/%(issue_id)s/subscribe' %
{'project_id': self.project_id, 'issue_id': self.id})
url = ('/projects/%(project_id)s/issues/%(issue_iid)s/subscribe' %
{'project_id': self.project_id, 'issue_iid': self.iid})

r = self.gitlab._raw_post(url, **kwargs)
raise_error_from_response(r, GitlabSubscribeError, [201, 304])
Expand All @@ -901,8 +902,8 @@ def unsubscribe(self, **kwargs):
GitlabConnectionError: If the server cannot be reached.
GitlabUnsubscribeError: If the unsubscription cannot be done
"""
url = ('/projects/%(project_id)s/issues/%(issue_id)s/unsubscribe' %
{'project_id': self.project_id, 'issue_id': self.id})
url = ('/projects/%(project_id)s/issues/%(issue_iid)s/unsubscribe' %
{'project_id': self.project_id, 'issue_iid': self.iid})

r = self.gitlab._raw_post(url, **kwargs)
raise_error_from_response(r, GitlabUnsubscribeError, [201, 304])
Expand All @@ -914,8 +915,8 @@ def move(self, to_project_id, **kwargs):
Raises:
GitlabConnectionError: If the server cannot be reached.
"""
url = ('/projects/%(project_id)s/issues/%(issue_id)s/move' %
{'project_id': self.project_id, 'issue_id': self.id})
url = ('/projects/%(project_id)s/issues/%(issue_iid)s/move' %
{'project_id': self.project_id, 'issue_iid': self.iid})

data = {'to_project_id': to_project_id}
data.update(**kwargs)
Expand All @@ -929,8 +930,8 @@ def todo(self, **kwargs):
Raises:
GitlabConnectionError: If the server cannot be reached.
"""
url = ('/projects/%(project_id)s/issues/%(issue_id)s/todo' %
{'project_id': self.project_id, 'issue_id': self.id})
url = ('/projects/%(project_id)s/issues/%(issue_iid)s/todo' %
{'project_id': self.project_id, 'issue_iid': self.iid})
r = self.gitlab._raw_post(url, **kwargs)
raise_error_from_response(r, GitlabTodoError, [201, 304])

Expand All @@ -940,22 +941,26 @@ def time_stats(self, **kwargs):
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})
url = ('/projects/%(project_id)s/issues/%(issue_iid)s/time_stats' %
{'project_id': self.project_id, 'issue_iid': self.iid})
r = self.gitlab._raw_get(url, **kwargs)
raise_error_from_response(r, GitlabGetError)
return r.json()

def time_estimate(self, **kwargs):
def time_estimate(self, duration, **kwargs):
"""Set an estimated time of work for the issue.
Args:
duration (str): duration in human format (e.g. 3h30)
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)
url = ('/projects/%(project_id)s/issues/%(issue_iid)s/time_estimate' %
{'project_id': self.project_id, 'issue_iid': self.iid})
data = {'duration': duration}
r = self.gitlab._raw_post(url, data, **kwargs)
raise_error_from_response(r, GitlabTimeTrackingError, 200)
return r.json()

def reset_time_estimate(self, **kwargs):
Expand All @@ -964,24 +969,28 @@ def reset_time_estimate(self, **kwargs):
Raises:
GitlabConnectionError: If the server cannot be reached.
"""
url = ('/projects/%(project_id)s/issues/%(issue_id)s/'
url = ('/projects/%(project_id)s/issues/%(issue_iid)s/'
'reset_time_estimate' %
{'project_id': self.project_id, 'issue_id': self.id})
{'project_id': self.project_id, 'issue_iid': self.iid})
r = self.gitlab._raw_post(url, **kwargs)
raise_error_from_response(r, GitlabTimeTrackingError, 200)
return r.json()

def add_spent_time(self, **kwargs):
def add_spent_time(self, duration, **kwargs):
"""Set an estimated time of work for the issue.
Args:
duration (str): duration in human format (e.g. 3h30)
Raises:
GitlabConnectionError: If the server cannot be reached.
"""
url = ('/projects/%(project_id)s/issues/%(issue_id)s/'
url = ('/projects/%(project_id)s/issues/%(issue_iid)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)
{'project_id': self.project_id, 'issue_iid': self.iid})
data = {'duration': duration}
r = self.gitlab._raw_post(url, data, **kwargs)
raise_error_from_response(r, GitlabTimeTrackingError, 201)
return r.json()

def reset_spent_time(self, **kwargs):
Expand All @@ -990,9 +999,9 @@ def reset_spent_time(self, **kwargs):
Raises:
GitlabConnectionError: If the server cannot be reached.
"""
url = ('/projects/%(project_id)s/issues/%(issue_id)s/'
url = ('/projects/%(project_id)s/issues/%(issue_iid)s/'
'reset_spent_time' %
{'project_id': self.project_id, 'issue_id': self.id})
{'project_id': self.project_id, 'issue_iid': self.iid})
r = self.gitlab._raw_post(url, **kwargs)
raise_error_from_response(r, GitlabTimeTrackingError, 200)
return r.json()
Expand Down

0 comments on commit ac3aef6

Please sign in to comment.