Skip to content

Commit

Permalink
Merge branch 'label-subscribe'
Browse files Browse the repository at this point in the history
  • Loading branch information
Gauvain Pocentek committed Jun 19, 2016
2 parents 79feb87 + 6f29ff1 commit d340d31
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
28 changes: 28 additions & 0 deletions gitlab/objects.py
Expand Up @@ -1358,6 +1358,34 @@ class ProjectLabel(GitlabObject):
requiredUpdateAttrs = ['name']
optionalUpdateAttrs = ['new_name', 'color', 'description']

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

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 label.
Raises:
GitlabConnectionError: If the server cannot be reached.
GitlabSubscribeError: 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})

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


class ProjectLabelManager(BaseManager):
obj_cls = ProjectLabel
Expand Down
4 changes: 4 additions & 0 deletions tools/python_test.py
Expand Up @@ -163,6 +163,10 @@
label1.new_name = 'label1updated'
label1.save()
assert(label1.name == 'label1updated')
label1.subscribe()
assert(label1.subscribed == True)
label1.unsubscribe()
assert(label1.subscribed == False)
label1.delete()

# milestones
Expand Down

0 comments on commit d340d31

Please sign in to comment.