Skip to content

Commit

Permalink
gitlab: make the current-user option work
Browse files Browse the repository at this point in the history
  • Loading branch information
Gauvain Pocentek committed Jun 22, 2013
1 parent a7f2065 commit 4c998ea
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
21 changes: 12 additions & 9 deletions gitlab
Expand Up @@ -59,8 +59,9 @@ def actionHelpList(cls):
detail += " "
detail += "--page=ARG --per-page=ARG"
elif action in ['get', 'delete']:
detail = "--id=ARG "
detail += " ".join(["--%s=ARG" % x.replace('_', '-') for x in cls.requiredGetAttrs])
if cls not in [gitlab.CurrentUser]:
detail = "--id=ARG "
detail += " ".join(["--%s=ARG" % x.replace('_', '-') for x in cls.requiredGetAttrs])
elif action == 'create':
detail = " ".join(["--%s=ARG" % x.replace('_', '-') for x in cls.requiredCreateAttrs])
if detail:
Expand Down Expand Up @@ -113,7 +114,7 @@ args = []
d = {}
for arg in sys.argv[1:]:
if arg.startswith('--'):
arg = arg[2:].replace('-', '_')
arg = arg[2:]

if arg == 'help':
usage()
Expand All @@ -122,8 +123,8 @@ for arg in sys.argv[1:]:
verbose = True
continue

k, v = arg.split('=', 2)
k = k.strip()
k, v = arg.split('=', 1)
k = k.strip().replace('_', '-')
v = v.strip()

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

try:
id = d.pop('id')
except:
die("Missing --id argument")
id = None
if cls not in [gitlab.CurrentUser]:
try:
id = d.pop('id')
except:
die("Missing --id argument")

try:
o = cls(gl, id, **d)
Expand Down
6 changes: 6 additions & 0 deletions gitlab.py
Expand Up @@ -278,6 +278,9 @@ def create(self, obj):
url = obj._url % obj.__dict__
url = '%s%s?private_token=%s' % (self._url, url, self.private_token)

print url
print obj.__dict__

try:
# TODO: avoid too much work on the server side by filtering the
# __dict__ keys
Expand Down Expand Up @@ -529,6 +532,8 @@ class User(GitlabObject):
class CurrentUserKey(GitlabObject):
_url = '/user/keys'
canUpdate = False
shortPrintAttr = 'title'
requiredCreateAttrs = ['title', 'key']


class CurrentUser(GitlabObject):
Expand All @@ -537,6 +542,7 @@ class CurrentUser(GitlabObject):
canCreate = False
canUpdate = False
canDelete = False
shortPrintAttr = 'username'

def Key(self, id=None, **kwargs):
if id is None:
Expand Down

0 comments on commit 4c998ea

Please sign in to comment.