Skip to content

Commit 9dd410f

Browse files
author
Gauvain Pocentek
committed
Fix the CLI for objects without ID (API v4)
Fixes #319
1 parent d415cc0 commit 9dd410f

File tree

3 files changed

+23
-9
lines changed

3 files changed

+23
-9
lines changed

gitlab/mixins.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def get(self, id, lazy=False, **kwargs):
5151

5252
class GetWithoutIdMixin(object):
5353
@exc.on_http_error(exc.GitlabGetError)
54-
def get(self, **kwargs):
54+
def get(self, id=None, **kwargs):
5555
"""Retrieve a single object.
5656
5757
Args:

gitlab/v4/cli.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def do_list(self):
8383

8484
def do_get(self):
8585
id = None
86-
if gitlab.mixins.GetWithoutIdMixin not in inspect.getmro(self.cls):
86+
if gitlab.mixins.GetWithoutIdMixin not in inspect.getmro(self.mgr_cls):
8787
id = self.args.pop(self.cls._id_attr)
8888

8989
try:
@@ -99,7 +99,9 @@ def do_delete(self):
9999
cli.die("Impossible to destroy object", e)
100100

101101
def do_update(self):
102-
id = self.args.pop(self.cls._id_attr)
102+
id = None
103+
if gitlab.mixins.GetWithoutIdMixin not in inspect.getmro(self.mgr_cls):
104+
id = self.args.pop(self.cls._id_attr)
103105
try:
104106
return self.mgr.update(id, self.args)
105107
except Exception as e:
@@ -282,15 +284,18 @@ def display_dict(d, padding):
282284
return
283285

284286
# not a dict, we assume it's a RESTObject
285-
id = getattr(obj, obj._id_attr, None)
286-
print('%s: %s' % (obj._id_attr, id))
287+
if obj._id_attr:
288+
id = getattr(obj, obj._id_attr, None)
289+
print('%s: %s' % (obj._id_attr, id))
287290
attrs = obj.attributes
288-
attrs.pop(obj._id_attr)
291+
if obj._id_attr:
292+
attrs.pop(obj._id_attr)
289293
display_dict(attrs, padding)
290294

291295
else:
292-
id = getattr(obj, obj._id_attr)
293-
print('%s: %s' % (obj._id_attr.replace('_', '-'), id))
296+
if obj._id_attr:
297+
id = getattr(obj, obj._id_attr)
298+
print('%s: %s' % (obj._id_attr.replace('_', '-'), id))
294299
if hasattr(obj, '_short_print_attr'):
295300
value = getattr(obj, obj._short_print_attr)
296301
print('%s: %s' % (obj._short_print_attr, value))

tools/cli_test_v4.sh

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,18 @@ testcase "branch deletion" '
9595
'
9696

9797
testcase "project upload" '
98-
GITLAB project upload --id "$PROJECT_ID" --filename '$(basename $0)' --filepath '$0'
98+
GITLAB project upload --id "$PROJECT_ID" \
99+
--filename '$(basename $0)' --filepath '$0' >/dev/null 2>&1
99100
'
100101

101102
testcase "project deletion" '
102103
GITLAB project delete --id "$PROJECT_ID"
103104
'
105+
106+
testcase "application settings get" '
107+
GITLAB application-settings get >/dev/null 2>&1
108+
'
109+
110+
testcase "application settings update" '
111+
GITLAB application-settings update --signup-enabled false
112+
'

0 commit comments

Comments
 (0)