Skip to content

Commit

Permalink
MR: add (un)subscribe support
Browse files Browse the repository at this point in the history
  • Loading branch information
Gauvain Pocentek committed Jun 19, 2016
1 parent d340d31 commit 867b7ab
Showing 1 changed file with 32 additions and 2 deletions.
34 changes: 32 additions & 2 deletions gitlab/objects.py
Expand Up @@ -1099,7 +1099,7 @@ def unsubscribe(self, **kwargs):
Raises:
GitlabConnectionError: If the server cannot be reached.
GitlabSubscribeError: If the unsubscription cannot be done
GitlabUnsubscribeError: If the unsubscription cannot be done
"""
url = ('/projects/%(project_id)s/issues/%(issue_id)s/subscription' %
{'project_id': self.project_id, 'issue_id': self.id})
Expand Down Expand Up @@ -1249,6 +1249,36 @@ def _data_for_gitlab(self, extra_parameters={}, update=False):
data = json.dumps(d)
return data

def subscribe(self, **kwargs):
"""Subscribe to a MR.
Raises:
GitlabConnectionError: If the server cannot be reached.
GitlabSubscribeError: If the subscription cannot be done
"""
url = ('/projects/%(project_id)s/merge_requests/%(mr_id)s/'
'subscription' %
{'project_id': self.project_id, 'mr_id': self.id})

r = self.gitlab._raw_post(url, **kwargs)
raise_error_from_response(r, GitlabSubscribeError, [201, 304])
self._set_from_dict(r.json())

def unsubscribe(self, **kwargs):
"""Unsubscribe a MR.
Raises:
GitlabConnectionError: If the server cannot be reached.
GitlabUnsubscribeError: If the unsubscription cannot be done
"""
url = ('/projects/%(project_id)s/merge_requests/%(mr_id)s/'
'subscription' %
{'project_id': self.project_id, 'mr_id': self.id})

r = self.gitlab._raw_delete(url, **kwargs)
raise_error_from_response(r, GitlabUnsubscribeError, [200, 304])
self._set_from_dict(r.json())

def cancel_merge_when_build_succeeds(self, **kwargs):
"""Cancel merge when build succeeds."""

Expand Down Expand Up @@ -1377,7 +1407,7 @@ def unsubscribe(self, **kwargs):
Raises:
GitlabConnectionError: If the server cannot be reached.
GitlabSubscribeError: If the unsubscription cannot be done
GitlabUnsubscribeError: If the unsubscription cannot be done
"""
url = ('/projects/%(project_id)s/labels/%(label_id)s/subscription' %
{'project_id': self.project_id, 'label_id': self.name})
Expand Down

0 comments on commit 867b7ab

Please sign in to comment.