◐ Shell
reader mode source ↗
Skip to content
Merged
Changes from all commits
File filter
Conversations
Jump to
Diff view
Apply and reload
Show whitespace
Diff view
Apply and reload
55 changes: 28 additions & 27 deletions gitlab.py
Original file line number Diff line number Diff line change
@@ -135,11 +135,11 @@ def setCredentials(self, email, password):

def rawGet(self, path, with_token=False):
url = '%s%s' % (self._url, path)
if with_token:
url += "?private_token=%s" % self.private_token

try:
r = requests.get(url)
except:
raise GitlabConnectionError(
"Can't connect to GitLab server (%s)" % self._url)
Expand All @@ -158,11 +158,12 @@ def rawPost(self, path, data):

def rawPut(self, path, with_token=False):
url = '%s%s' % (self._url, path)
if with_token:
url += "?private_token=%s" % self.private_token

try:
r = requests.put(url)
except:
raise GitlabConnectionError(
"Can't connect to GitLab server (%s)" % self._url)
Expand All @@ -181,13 +182,13 @@ def list(self, obj_class, **kwargs):
url = obj_class._url
if kwargs:
url = obj_class._url % kwargs
url = '%s%s?private_token=%s' % (self._url, url, self.private_token)
if kwargs:
url += "&%s" % ("&".join(
["%s=%s" % (k, v) for k, v in kwargs.items()]))

try:
r = requests.get(url)
except:
raise GitlabConnectionError(
"Can't connect to GitLab server (%s)" % self._url)
Expand Down Expand Up @@ -223,17 +224,17 @@ def get(self, obj_class, id=None, **kwargs):
url = obj_class._url % kwargs
if id is not None:
try:
url = '%s%s/%d?private_token=%s' % \
(self._url, url, id, self.private_token)
except TypeError: # id might be a str (ProjectBranch)
url = '%s%s/%s?private_token=%s' % \
(self._url, url, id, self.private_token)
else:
url = '%s%s?private_token=%s' % \
(self._url, url, self.private_token)

try:
r = requests.get(url)
except:
raise GitlabConnectionError(
"Can't connect to GitLab server (%s)" % self._url)
Expand All @@ -249,11 +250,11 @@ def get(self, obj_class, id=None, **kwargs):

def delete(self, obj):
url = obj._url % obj.__dict__
url = '%s%s/%d?private_token=%s' % \
(self._url, url, obj.id, self.private_token)

try:
r = requests.delete(url)
except:
raise GitlabConnectionError(
"Can't connect to GitLab server (%s)" % self._url)
Expand All @@ -276,15 +277,15 @@ def create(self, obj):
", ".join(missing))

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
r = requests.post(url, obj.__dict__)
except:
raise GitlabConnectionError(
"Can't connect to GitLab server (%s)" % self._url)
Expand All @@ -298,8 +299,8 @@ def create(self, obj):

def update(self, obj):
url = obj._url % obj.__dict__
url = '%s%s/%d?private_token=%s' % \
(self._url, url, obj.id, self.private_token)

# build a dict of data that can really be sent to server
d = {}
Expand All @@ -308,7 +309,7 @@ def update(self, obj):
d[k] = str(v)

try:
r = requests.put(url, d)
except:
raise GitlabConnectionError(
"Can't connect to GitLab server (%s)" % self._url)
Expand Down Expand Up @@ -576,9 +577,9 @@ class Group(GitlabObject):
shortPrintAttr = 'name'

def transfer_project(self, id):
url = '/groups/%d/projects/%d?private_token=%s' % \
(self.id, id, self.gitlab.private_token)
r = self.gitlab.rawPost(url, None)
if r.status_code != 201:
raise GitlabTransferProjectError()

Expand Down
Toggle all file notes Toggle all file annotations