diff options
author | Gauvain Pocentek <gauvain@pocentek.net> | 2016-02-14 10:40:12 +0100 |
---|---|---|
committer | Gauvain Pocentek <gauvain@pocentek.net> | 2016-02-14 10:40:14 +0100 |
commit | 58433d2b1854eb4e112c499d52d8dd0fd6dba094 (patch) | |
tree | f5f88ff6d8a665ac89c39b61fc37ca8350688c7b | |
parent | 7260684d11e8ffe02461f761b6677d039b703a8d (diff) | |
download | gitlab-58433d2b1854eb4e112c499d52d8dd0fd6dba094.tar.gz |
CI: implement user get-by-username
fixes #95
-rw-r--r-- | docs/cli.rst | 7 | ||||
-rw-r--r-- | gitlab/cli.py | 11 | ||||
-rwxr-xr-x | tools/functional_tests.sh | 8 |
3 files changed, 24 insertions, 2 deletions
diff --git a/docs/cli.rst b/docs/cli.rst index 6ab7957..81d308d 100644 --- a/docs/cli.rst +++ b/docs/cli.rst @@ -150,6 +150,13 @@ Get a specific project (id 2): $ gitlab project get --id 2 +Get a specific user by id or by username: + +.. code-block:: console + + $ gitlab user get --id 3 + $ gitlab user get-by-username --query jdoe + Get a list of snippets for this project: .. code-block:: console diff --git a/gitlab/cli.py b/gitlab/cli.py index 0e7d5ef..090978b 100644 --- a/gitlab/cli.py +++ b/gitlab/cli.py @@ -47,7 +47,8 @@ EXTRA_ACTIONS = { 'all': {}}, gitlab.User: {'block': {'required': ['id']}, 'unblock': {'required': ['id']}, - 'search': {'required': ['query']}}, + 'search': {'required': ['query']}, + 'get-by-username': {'required': ['query']}}, } @@ -229,6 +230,12 @@ class GitlabCLI(object): except Exception as e: _die("Impossible to search users (%s)" % str(e)) + def do_user_getbyusername(self, cls, gl, what, args): + try: + return gl.users.search(args['query']) + except Exception as e: + _die("Impossible to get user %s (%s)" % (args['query'], str(e))) + def _populate_sub_parser_by_class(cls, sub_parser): for action_name in ['list', 'get', 'create', 'update', 'delete']: @@ -370,7 +377,7 @@ def main(): cli = GitlabCLI() method = None what = what.replace('-', '_') - action = action.lower() + action = action.lower().replace('-', '') for test in ["do_%s_%s" % (what, action), "do_%s" % action]: if hasattr(cli, test): diff --git a/tools/functional_tests.sh b/tools/functional_tests.sh index fefb5af..84339e3 100755 --- a/tools/functional_tests.sh +++ b/tools/functional_tests.sh @@ -35,6 +35,14 @@ testcase "user creation" ' ' USER_ID=$(pecho "${OUTPUT}" | grep ^id: | cut -d' ' -f2) +testcase "user get (by id)" ' + GITLAB user get --id $USER_ID >/dev/null 2>&1 +' + +testcase "user get (by username)" ' + GITLAB user get-by-username --query user1 >/dev/null 2>&1 +' + testcase "verbose output" ' OUTPUT=$(try GITLAB -v user list) || exit 1 pecho "${OUTPUT}" | grep -q avatar-url |