diff options
Diffstat (limited to 'gitlab/mixins.py')
-rw-r--r-- | gitlab/mixins.py | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/gitlab/mixins.py b/gitlab/mixins.py index ca68658..98c3185 100644 --- a/gitlab/mixins.py +++ b/gitlab/mixins.py @@ -136,6 +136,26 @@ class ListMixin(object): else: return base.RESTObjectList(self, self._obj_cls, obj) + @exc.on_http_error(exc.GitlabListError) + def count(self, **kwargs): + """Retrieve the number of available objects. + + Args: + **kwargs: Extra options to send to the server (e.g. sudo) + + Returns: + int: The number of objects + + Raises: + GitlabAuthenticationError: If authentication is not correct + GitlabCountError: If the server cannot perform the request + """ + # Allow to overwrite the path, handy for custom calls + path = kwargs.pop('path', self.path) + + headers = self.gitlab.http_head(path, **kwargs) + return int(headers['x-total']) + class RetrieveMixin(ListMixin, GetMixin): pass |