From 1b6c5952f06fe1236e1e75ae68f9c2325e78d372 Mon Sep 17 00:00:00 2001 From: Diego Giovane Pasqualin Date: Fri, 10 Jan 2014 09:55:48 -0200 Subject: [PATCH 1/5] Add support for extra parameters when listing all projects (Refs #12) Signed-off-by: Diego Giovane Pasqualin --- gitlab.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/gitlab.py b/gitlab.py index f827a5b72..d1a9dd6b3 100644 --- a/gitlab.py +++ b/gitlab.py @@ -131,8 +131,12 @@ def setCredentials(self, email, password): self.email = email self.password = password - def rawGet(self, path): + def rawGet(self, path, **kwargs): url = '%s%s' % (self._url, path) + if kwargs: + url += "?%s" % ("&".join( + ["%s=%s" % (k, v) for k, v in kwargs.items()])) + try: return requests.get(url, headers=self.headers, @@ -355,8 +359,8 @@ def UserProject(self, id=None, **kwargs): """ return self._getListOrObject(UserProject, id, **kwargs) - def _list_projects(self, url): - r = self.rawGet(url) + def _list_projects(self, url, **kwargs): + r = self.rawGet(url, **kwargs) if r.status_code != 200: raise GitlabListError @@ -373,13 +377,13 @@ def search_projects(self, query): """ return self._list_projects("/projects/search/" + query) - def all_projects(self): + def all_projects(self, **kwargs): """Lists all the projects (need admin rights).""" - return self._list_projects("/projects/all") + return self._list_projects("/projects/all", **kwargs) - def owned_projects(self): + def owned_projects(self, **kwargs): """Lists owned projects.""" - return self._list_projects("/projects/owned") + return self._list_projects("/projects/owned", **kwargs) def Group(self, id=None, **kwargs): """Creates/gets/lists group(s) known by the GitLab server. From c6e371e7b2e2e499e32dd11feb81c013b8ab32c4 Mon Sep 17 00:00:00 2001 From: Gauvain Pocentek Date: Thu, 16 Jan 2014 06:57:32 +0100 Subject: [PATCH 2/5] ids can be unicode Fixes #15 --- gitlab.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gitlab.py b/gitlab.py index f827a5b72..4fbb05a7e 100644 --- a/gitlab.py +++ b/gitlab.py @@ -523,7 +523,7 @@ def delete(self): def __init__(self, gl, data=None, **kwargs): self.gitlab = gl - if data is None or isinstance(data, int) or isinstance(data, str): + if data is None or type(data) in [int, str, unicode]: data = self.gitlab.get(self.__class__, data, **kwargs) self._setFromDict(data) From 1c214233360524fae06c9f6946e0956843a000f3 Mon Sep 17 00:00:00 2001 From: Gauvain Pocentek Date: Thu, 16 Jan 2014 07:59:38 +0100 Subject: [PATCH 3/5] ProjectMember: constructor should not create a User object --- gitlab.py | 1 - 1 file changed, 1 deletion(-) diff --git a/gitlab.py b/gitlab.py index 4fbb05a7e..9db538e55 100644 --- a/gitlab.py +++ b/gitlab.py @@ -798,7 +798,6 @@ def Note(self, id=None, **kwargs): class ProjectMember(GitlabObject): _url = '/projects/%(project_id)s/members' - _returnClass = User requiredListAttrs = ['project_id'] requiredGetAttrs = ['project_id'] requiredCreateAttrs = ['project_id', 'user_id', 'access_level'] From 4fcef67d7ef275d81c3c4db7dfd21cdea0310e60 Mon Sep 17 00:00:00 2001 From: Gauvain Pocentek Date: Thu, 16 Jan 2014 08:15:01 +0100 Subject: [PATCH 4/5] projects listing: explicitly define arguments for pagination --- gitlab.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/gitlab.py b/gitlab.py index 9182f512e..36a1da2a2 100644 --- a/gitlab.py +++ b/gitlab.py @@ -377,13 +377,23 @@ def search_projects(self, query): """ return self._list_projects("/projects/search/" + query) - def all_projects(self, **kwargs): + def all_projects(self, page=None, per_page=None): """Lists all the projects (need admin rights).""" - return self._list_projects("/projects/all", **kwargs) + d = {} + if page is not None: + d['page'] = page + if per_page is not None: + d['per_page'] = per_page + return self._list_projects("/projects/all", **d) - def owned_projects(self, **kwargs): + def owned_projects(self, page=None, per_page=None): """Lists owned projects.""" - return self._list_projects("/projects/owned", **kwargs) + d = {} + if page is not None: + d['page'] = page + if per_page is not None: + d['per_page'] = per_page + return self._list_projects("/projects/owned", **d) def Group(self, id=None, **kwargs): """Creates/gets/lists group(s) known by the GitLab server. From 1fe783dba0e63796411bc6a358191a3144dc9bb8 Mon Sep 17 00:00:00 2001 From: Gauvain Pocentek Date: Thu, 16 Jan 2014 08:18:39 +0100 Subject: [PATCH 5/5] version bump Update Changelog and AUTHORS --- AUTHORS | 1 + ChangeLog | 7 +++++++ gitlab.py | 2 +- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/AUTHORS b/AUTHORS index d6130439c..c6350f365 100644 --- a/AUTHORS +++ b/AUTHORS @@ -11,3 +11,4 @@ Erik Weatherwax Andrew Austin Koen Smets Mart Sõmermaa +Diego Giovane Pasqualin diff --git a/ChangeLog b/ChangeLog index b9766ea52..29a8981c6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +Version 0.6 + + * IDs can be unicode (#15) + * ProjectMember: constructor should not create a User object + * Add support for extra parameters when listing all projects (#12) + * Projects listing: explicitly define arguments for pagination + Version 0.5 * Add SSH key for user diff --git a/gitlab.py b/gitlab.py index 36a1da2a2..a64fdcada 100644 --- a/gitlab.py +++ b/gitlab.py @@ -21,7 +21,7 @@ import sys __title__ = 'python-gitlab' -__version__ = '0.5' +__version__ = '0.6' __author__ = 'Gauvain Pocentek' __email__ = 'gauvain@pocentek.net' __license__ = 'LGPL3'