Skip to content

Commit 9572caf

Browse files
committed
Add a search_users method
Signed-off-by: David Greaves <david.greaves@jolla.com>
1 parent d069381 commit 9572caf

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

gitlab/__init__.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,35 @@ def User(self, id=None, **kwargs):
600600
"""
601601
return User._get_list_or_object(self, id, **kwargs)
602602

603+
def _list_users(self, url, exact, **kwargs):
604+
r = self.rawGet(url, **kwargs)
605+
if r.status_code != 200:
606+
_raiseErrorFromResponse(r, GitlabListError)
607+
608+
l = []
609+
for o in r.json():
610+
u=User(self, o)
611+
if exact:
612+
if u.username == exact:
613+
return u
614+
else:
615+
l.append(u)
616+
617+
if exact:
618+
return None
619+
return l
620+
621+
def search_users(self, query, exact, **kwargs):
622+
"""Searches users by name.
623+
624+
Returns a list of matching users.
625+
626+
If 'exact' is true then only return one user with an exact match for the query
627+
"""
628+
if exact:
629+
exact=query
630+
return self._list_users("/users?search=" + query, exact, **kwargs)
631+
603632
def Team(self, id=None, **kwargs):
604633
"""Creates/gets/lists team(s) known by the GitLab server.
605634

0 commit comments

Comments
 (0)