8000 Fix the update/delete CLI subcommands · guyzmo/python-gitlab@802c144 · GitHub
[go: up one dir, main page]

Skip to content

Commit 802c144

Browse files
author
Gauvain Pocentek
committed
Fix the update/delete CLI subcommands
Also update the testing tool to test these features. Closes python-gitlab#62
1 parent e57b779 commit 802c144

File tree

3 files changed

+31
-5
lines changed

3 files changed

+31
-5
lines changed

gitlab/__init__.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -643,6 +643,11 @@ class GitlabObject(object):
643643
requiredCreateAttrs = []
644644
#: Attributes that are optional when creating a new object
645645
optionalCreateAttrs = []
646+
#: Attributes that are required when updating an object
647+
requiredUpdateAttrs = None
648+
#: Attributes that are optional when updating an object
649+
optionalUpdateAttrs = None
650+
646651
idAttr = 'id'
647652
shortPrintAttr = None
648653

@@ -1086,6 +1091,7 @@ class ProjectLabel(GitlabObject):
10861091
idAttr = 'name'
10871092
requiredDeleteAttrs = ['name']
10881093
requiredCreateAttrs = ['name', 'color']
1094+
requiredUpdateAttrs = []
10891095
# FIXME: new_name is only valid with update
10901096
optionalCreateAttrs = ['new_name']
10911097

@@ -1157,6 +1163,7 @@ class Project(GitlabObject):
11571163
_url = '/projects'
11581164
_constructorTypes = {'owner': 'User', 'namespace': 'Group'}
11591165
requiredCreateAttrs = ['name']
1166+
requiredUpdateAttrs = []
11601167
optionalCreateAttrs = ['default_branch', 'issues_enabled', 'wall_enabled',
11611168
'merge_requests_enabled', 'wiki_enabled',
11621169
'snippets_enabled', 'public', 'visibility_level',

gitlab/cli.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,23 @@ def populate_sub_parser_by_class(cls, sub_parser):
103103
for x in cls.optionalCreateAttrs]
104104

105105
elif action_name == UPDATE:
106+
id_attr = cls.idAttr.replace('_', '-')
107+
sub_parser_action.add_argument("--%s" % id_attr,
108+
required=True)
109+
110+
attrs = (cls.requiredUpdateAttrs
111+
if cls.requiredUpdateAttrs is not None
112+
else cls.requiredCreateAttrs)
106113
[sub_parser_action.add_argument("--%s" % x.replace('_', '-'),
107114
required=True)
108-
for x in cls.requiredCreateAttrs]
115+
for x in attrs]
116+
117+
attrs = (cls.optionalUpdateAttrs
118+
if cls.optionalUpdateAttrs is not None
119+
else cls.optionalCreateAttrs)
109120
[sub_parser_action.add_argument("--%s" % x.replace('_', '-'),
110121
required=False)
111-
for x in cls.optionalCreateAttrs]
122+
for x in attrs]
112123

113124
if cls in extra_actions:
114125
for action_name in sorted(extra_actions[cls]):
@@ -182,7 +193,7 @@ def do_delete(cls, gl, what, args):
182193
if not cls.canDelete:
183194
die("%s objects can't be deleted" % what)
184195

185-
o = do_get(cls, args, what, args)
196+
o = do_get(cls, gl, what, args)
186197
try:
187198
o.delete()
188199
except Exception as e 8000 :
@@ -193,7 +204,7 @@ def do_update(cls, gl, what, args):
193204
if not cls.canUpdate:
194205
die("%s objects can't be updated" % what)
195206

196-
o = do_get(cls, args, what, args)
207+
o = do_get(cls, gl, what, args)
197208
try:
198209
for k, v in args.items():
199210
o.__dict__[k] = v

tools/functional_tests.sh

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ cleanup() {
2323
}
2424
trap cleanup EXIT
2525

26-
docker run --name gitlab-test --detach --publish 8080:80 --publish 2222:22 sytse/gitlab-ce:7.10.1 >/dev/null 2>&1
26+
docker run --name gitlab-test --detach --publish 8080:80 --publish 2222:22 genezys/gitlab:latest >/dev/null 2>&1
2727

2828
LOGIN='root'
2929
PASSWORD='5iveL!fe'
@@ -80,6 +80,14 @@ PROJECT_ID=$($GITLAB project create --name test-project1 | grep ^id: | cut -d' '
8080
$GITLAB project list | grep -q test-project1
8181
$OK
8282

83+
echo -n "Testing project update... "
84+
$GITLAB project update --id $PROJECT_ID --description "My New Description"
85+
$OK
86+
87+
echo -n "Testing project deletion... "
88+
$GITLAB project delete --id $PROJECT_ID
89+
$OK
90+
8391
echo -n "Testing user creation... "
8492
USER_ID=$($GITLAB user create --email fake@email.com --username user1 --name "User One" --password fakepassword | grep ^id: | cut -d' ' -f2)
8593
$OK

0 commit comments

Comments
 (0)
0