From f6abd4da5fc8958795995e892cc42be1bd352bea Mon Sep 17 00:00:00 2001 From: Gauvain Pocentek Date: Wed, 17 Jun 2015 20:46:10 +0200 Subject: [PATCH 1/5] Improve the README a bit Fix typos Detail which options are required in the [global] section (closes #61) --- README.md | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index a88c2685c..14fc6a182 100644 --- a/README.md +++ b/README.md @@ -73,21 +73,25 @@ Here's an example of the syntax: ````` [global] +# required setting default = local + +# optional settings ssl_verify = true timeout = 5 [local] url = http://10.0.3.2:8080 +# get the private token from the gitlab web interface private_token = vTbFeqJYCY3sibBP7BZM -[distant] +[remote] url = https://some.whe.re private_token = thisisaprivatetoken ssl_verify = false ````` -The [global] section define which server is accesed by default. +The [global] section defines which server is accessed by default. Each other section defines how to access a server. Only private token authentication is supported (not user/password). @@ -100,7 +104,7 @@ server should be abandonned. Choosing a different server than the default one can be done at run time: ````` -gitlab --gitlab=distant [command] +gitlab --gitlab=remote [command] ````` gitlab always requires 2 mandatory arguments. From 0922ed5453aaa5e982012bab16d9517e28626977 Mon Sep 17 00:00:00 2001 From: Gauvain Pocentek Date: Wed, 17 Jun 2015 20:56:55 +0200 Subject: [PATCH 2/5] more README updates --- README.md | 22 ++++++++++++++++------ docs/cli.rst | 4 ++-- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 14fc6a182..8196a3042 100644 --- a/README.md +++ b/README.md @@ -6,25 +6,35 @@ It supports the v3 api of GitLab. A CLI tool is also provided (called **gitlab**). -## Requirements +## Installation + +### Requirements python-gitlab depends on: -* [python-requests](http://docs.python-requests.org/en/latest/). +* [python-requests](http://docs.python-requests.org/en/latest/) +* [six](https://pythonhosted.org/six/) + +### Install with pip + +````` +pip install python-gitlab +````` ## State -python-gitlab >= 0.3 is considered stable. +python-gitlab is considered stable. ## Bugs reports Please report bugs and feature requests at https://github.com/gpocentek/python-gitlab/issues -## ToDo +## Documentation + +Work In Progress: http://python-gitlab.readthedocs.org/en/latest/ -* Improve documentation -* Write unit tests +Patches are welcome! ## Code snippet diff --git a/docs/cli.rst b/docs/cli.rst index 91001d793..2c0390144 100644 --- a/docs/cli.rst +++ b/docs/cli.rst @@ -1,4 +1,4 @@ -Commnad line use -================ +Command line usage +================== Document here how to use command line tool From e57b7794d1e1ae6795f5b914132a2891dc0d9509 Mon Sep 17 00:00:00 2001 From: Gauvain Pocentek Date: Sat, 11 Jul 2015 07:19:22 +0200 Subject: [PATCH 3/5] fix delete and update CLI methods --- gitlab/cli.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gitlab/cli.py b/gitlab/cli.py index 205f0f879..9c07e8226 100644 --- a/gitlab/cli.py +++ b/gitlab/cli.py @@ -182,7 +182,7 @@ def do_delete(cls, gl, what, args): if not cls.canDelete: die("%s objects can't be deleted" % what) - o = do_get(cls, args) + o = do_get(cls, args, what, args) try: o.delete() except Exception as e: @@ -193,7 +193,7 @@ def do_update(cls, gl, what, args): if not cls.canUpdate: die("%s objects can't be updated" % what) - o = do_get(cls, args) + o = do_get(cls, args, what, args) try: for k, v in args.items(): o.__dict__[k] = v From 802c144cfd199684506b3404f03c3657c75e307d Mon Sep 17 00:00:00 2001 From: Gauvain Pocentek Date: Sat, 11 Jul 2015 08:56:17 +0200 Subject: [PATCH 4/5] Fix the update/delete CLI subcommands Also update the testing tool to test these features. Closes #62 --- gitlab/__init__.py | 7 +++++++ gitlab/cli.py | 19 +++++++++++++++---- tools/functional_tests.sh | 10 +++++++++- 3 files changed, 31 insertions(+), 5 deletions(-) diff --git a/gitlab/__init__.py b/gitlab/__init__.py index 93e8b82ad..52fc7db3a 100644 --- a/gitlab/__init__.py +++ b/gitlab/__init__.py @@ -643,6 +643,11 @@ class GitlabObject(object): requiredCreateAttrs = [] #: Attributes that are optional when creating a new object optionalCreateAttrs = [] + #: Attributes that are required when updating an object + requiredUpdateAttrs = None + #: Attributes that are optional when updating an object + optionalUpdateAttrs = None + idAttr = 'id' shortPrintAttr = None @@ -1086,6 +1091,7 @@ class ProjectLabel(GitlabObject): idAttr = 'name' requiredDeleteAttrs = ['name'] requiredCreateAttrs = ['name', 'color'] + requiredUpdateAttrs = [] # FIXME: new_name is only valid with update optionalCreateAttrs = ['new_name'] @@ -1157,6 +1163,7 @@ class Project(GitlabObject): _url = '/projects' _constructorTypes = {'owner': 'User', 'namespace': 'Group'} requiredCreateAttrs = ['name'] + requiredUpdateAttrs = [] optionalCreateAttrs = ['default_branch', 'issues_enabled', 'wall_enabled', 'merge_requests_enabled', 'wiki_enabled', 'snippets_enabled', 'public', 'visibility_level', diff --git a/gitlab/cli.py b/gitlab/cli.py index 9c07e8226..d67843969 100644 --- a/gitlab/cli.py +++ b/gitlab/cli.py @@ -103,12 +103,23 @@ def populate_sub_parser_by_class(cls, sub_parser): for x in cls.optionalCreateAttrs] elif action_name == UPDATE: + id_attr = cls.idAttr.replace('_', '-') + sub_parser_action.add_argument("--%s" % id_attr, + required=True) + + attrs = (cls.requiredUpdateAttrs + if cls.requiredUpdateAttrs is not None + else cls.requiredCreateAttrs) [sub_parser_action.add_argument("--%s" % x.replace('_', '-'), required=True) - for x in cls.requiredCreateAttrs] + for x in attrs] + + attrs = (cls.optionalUpdateAttrs + if cls.optionalUpdateAttrs is not None + else cls.optionalCreateAttrs) [sub_parser_action.add_argument("--%s" % x.replace('_', '-'), required=False) - for x in cls.optionalCreateAttrs] + for x in attrs] if cls in extra_actions: for action_name in sorted(extra_actions[cls]): @@ -182,7 +193,7 @@ def do_delete(cls, gl, what, args): if not cls.canDelete: die("%s objects can't be deleted" % what) - o = do_get(cls, args, what, args) + o = do_get(cls, gl, what, args) try: o.delete() except Exception as e: @@ -193,7 +204,7 @@ def do_update(cls, gl, what, args): if not cls.canUpdate: die("%s objects can't be updated" % what) - o = do_get(cls, args, what, args) + o = do_get(cls, gl, what, args) try: for k, v in args.items(): o.__dict__[k] = v diff --git a/tools/functional_tests.sh b/tools/functional_tests.sh index 24124cef0..dd31c9007 100755 --- a/tools/functional_tests.sh +++ b/tools/functional_tests.sh @@ -23,7 +23,7 @@ cleanup() { } trap cleanup EXIT -docker run --name gitlab-test --detach --publish 8080:80 --publish 2222:22 sytse/gitlab-ce:7.10.1 >/dev/null 2>&1 +docker run --name gitlab-test --detach --publish 8080:80 --publish 2222:22 genezys/gitlab:latest >/dev/null 2>&1 LOGIN='root' PASSWORD='5iveL!fe' @@ -80,6 +80,14 @@ PROJECT_ID=$($GITLAB project create --name test-project1 | grep ^id: | cut -d' ' $GITLAB project list | grep -q test-project1 $OK +echo -n "Testing project update... " +$GITLAB project update --id $PROJECT_ID --description "My New Description" +$OK + +echo -n "Testing project deletion... " +$GITLAB project delete --id $PROJECT_ID +$OK + echo -n "Testing user creation... " USER_ID=$($GITLAB user create --email fake@email.com --username user1 --name "User One" --password fakepassword | grep ^id: | cut -d' ' -f2) $OK From 4bb42de27aec0aaa850c1e2cfc251a1c24658563 Mon Sep 17 00:00:00 2001 From: Gauvain Pocentek Date: Sat, 11 Jul 2015 08:58:45 +0200 Subject: [PATCH 5/5] version bump --- ChangeLog | 4 ++++ gitlab/__init__.py | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 81e97cf1f..3f11b7584 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +Version 0.9.2 + + * CLI: fix the update and delete subcommands (#62) + Version 0.9.1 * Fix the setup.py script diff --git a/gitlab/__init__.py b/gitlab/__init__.py index 52fc7db3a..260be4005 100644 --- a/gitlab/__init__.py +++ b/gitlab/__init__.py @@ -27,7 +27,7 @@ import six __title__ = 'python-gitlab' -__version__ = '0.9.1' +__version__ = '0.9.2' __author__ = 'Gauvain Pocentek' __email__ = 'gauvain@pocentek.net' __license__ = 'LGPL3'