Skip to content

Commit 4c998ea

Browse files
author
Gauvain Pocentek
committed
gitlab: make the current-user option work
1 parent a7f2065 commit 4c998ea

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

gitlab

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,9 @@ def actionHelpList(cls):
5959
detail += " "
6060
detail += "--page=ARG --per-page=ARG"
6161
elif action in ['get', 'delete']:
62-
detail = "--id=ARG "
63-
detail += " ".join(["--%s=ARG" % x.replace('_', '-') for x in cls.requiredGetAttrs])
62+
if cls not in [gitlab.CurrentUser]:
63+
detail = "--id=ARG "
64+
detail += " ".join(["--%s=ARG" % x.replace('_', '-') for x in cls.requiredGetAttrs])
6465
elif action == 'create':
6566
detail = " ".join(["--%s=ARG" % x.replace('_', '-') for x in cls.requiredCreateAttrs])
6667
if detail:
@@ -113,7 +114,7 @@ args = []
113114
d = {}
114115
for arg in sys.argv[1:]:
115116
if arg.startswith('--'):
116-
arg = arg[2:].replace('-', '_')
117+
arg = arg[2:]
117118

118119
if arg == 'help':
119120
usage()
@@ -122,8 +123,8 @@ for arg in sys.argv[1:]:
122123
verbose = True
123124
continue
124125

125-
k, v = arg.split('=', 2)
126-
k = k.strip()
126+
k, v = arg.split('=', 1)
127+
k = k.strip().replace('_', '-')
127128
v = v.strip()
128129

129130
if k == 'gitlab':
@@ -219,10 +220,12 @@ elif action == "get":
219220
if not cls.canGet:
220221
die("%s objects can't be retrieved" % what)
221222

222-
try:
223-
id = d.pop('id')
224-
except:
225-
die("Missing --id argument")
223+
id = None
224+
if cls not in [gitlab.CurrentUser]:
225+
try:
226+
id = d.pop('id')
227+
except:
228+
die("Missing --id argument")
226229

227230
try:
228231
o = cls(gl, id, **d)

gitlab.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,9 @@ def create(self, obj):
278278
url = obj._url % obj.__dict__
279279
url = '%s%s?private_token=%s' % (self._url, url, self.private_token)
280280

281+
print url
282+
print obj.__dict__
283+
281284
try:
282285
# TODO: avoid too much work on the server side by filtering the
283286
# __dict__ keys
@@ -529,6 +532,8 @@ class User(GitlabObject):
529532
class CurrentUserKey(GitlabObject):
530533
_url = '/user/keys'
531534
canUpdate = False
535+
shortPrintAttr = 'title'
536+
requiredCreateAttrs = ['title', 'key']
532537

533538

534539
class CurrentUser(GitlabObject):
@@ -537,6 +542,7 @@ class CurrentUser(GitlabObject):
537542
canCreate = False
538543
canUpdate = False
539544
canDelete = False
545+
shortPrintAttr = 'username'
540546

541547
def Key(self, id=None, **kwargs):
542548
if id is None:

0 commit comments

Comments
 (0)