Skip to content

Commit 58433d2

Browse files
author
Gauvain Pocentek
committed
CI: implement user get-by-username
fixes #95
1 parent 7260684 commit 58433d2

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

docs/cli.rst

+7
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,13 @@ Get a specific project (id 2):
150150
151151
$ gitlab project get --id 2
152152
153+
Get a specific user by id or by username:
154+
155+
.. code-block:: console
156+
157+
$ gitlab user get --id 3
158+
$ gitlab user get-by-username --query jdoe
159+
153160
Get a list of snippets for this project:
154161

155162
.. code-block:: console

gitlab/cli.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@
4747
'all': {}},
4848
gitlab.User: {'block': {'required': ['id']},
4949
'unblock': {'required': ['id']},
50-
'search': {'required': ['query']}},
50+
'search': {'required': ['query']},
51+
'get-by-username': {'required': ['query']}},
5152
}
5253

5354

@@ -229,6 +230,12 @@ def do_user_search(self, cls, gl, what, args):
229230
except Exception as e:
230231
_die("Impossible to search users (%s)" % str(e))
231232

233+
def do_user_getbyusername(self, cls, gl, what, args):
234+
try:
235+
return gl.users.search(args['query'])
236+
except Exception as e:
237+
_die("Impossible to get user %s (%s)" % (args['query'], str(e)))
238+
232239

233240
def _populate_sub_parser_by_class(cls, sub_parser):
234241
for action_name in ['list', 'get', 'create', 'update', 'delete']:
@@ -370,7 +377,7 @@ def main():
370377
cli = GitlabCLI()
371378
method = None
372379
what = what.replace('-', '_')
373-
action = action.lower()
380+
action = action.lower().replace('-', '')
374381
for test in ["do_%s_%s" % (what, action),
375382
"do_%s" % action]:
376383
if hasattr(cli, test):

tools/functional_tests.sh

+8
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,14 @@ testcase "user creation" '
3535
'
3636
USER_ID=$(pecho "${OUTPUT}" | grep ^id: | cut -d' ' -f2)
3737

38+
testcase "user get (by id)" '
39+
GITLAB user get --id $USER_ID >/dev/null 2>&1
40+
'
41+
42+
testcase "user get (by username)" '
43+
GITLAB user get-by-username --query user1 >/dev/null 2>&1
44+
'
45+
3846
testcase "verbose output" '
3947
OUTPUT=$(try GITLAB -v user list) || exit 1
4048
pecho "${OUTPUT}" | grep -q avatar-url

0 commit comments

Comments
 (0)