summaryrefslogtreecommitdiff
path: root/gitlab.py
diff options
context:
space:
mode:
Diffstat (limited to 'gitlab.py')
-rw-r--r--gitlab.py42
1 files changed, 41 insertions, 1 deletions
diff --git a/gitlab.py b/gitlab.py
index 32d7ae5..c78cdb2 100644
--- a/gitlab.py
+++ b/gitlab.py
@@ -141,7 +141,7 @@ class Gitlab(object):
raise GitlabConnectionError(
"Can't connect to GitLab server (%s)" % self._url)
- def rawPost(self, path, data):
+ def rawPost(self, path, data=None):
url = '%s%s' % (self._url, path)
try:
return requests.post(url, data,
@@ -162,6 +162,17 @@ class Gitlab(object):
raise GitlabConnectionError(
"Can't connect to GitLab server (%s)" % self._url)
+ def rawDelete(self, path):
+ url = '%s%s' % (self._url, path)
+
+ try:
+ return requests.delete(url,
+ headers=self.headers,
+ verify=self.ssl_verify)
+ except:
+ raise GitlabConnectionError(
+ "Can't connect to GitLab server (%s)" % self._url)
+
def list(self, obj_class, **kwargs):
missing = []
for k in obj_class.requiredListAttrs:
@@ -907,6 +918,11 @@ class Project(GitlabObject):
project_id=self.id,
**kwargs)
+ def File(self, id=None, **kwargs):
+ return self._getListOrObject(ProjectFile, id,
+ project_id=self.id,
+ **kwargs)
+
def Hook(self, id=None, **kwargs):
return self._getListOrObject(ProjectHook, id,
project_id=self.id,
@@ -980,6 +996,30 @@ class Project(GitlabObject):
raise GitlabGetError
+ def create_file(self, path, branch, content, message):
+ url = "/projects/%s/repository/files" % self.id
+ url += "?file_path=%s&branch_name=%s&content=%s&commit_message=%s" % \
+ (path, branch, content, message)
+ r = self.gitlab.rawPost(url)
+ if r.status_code != 201:
+ raise GitlabCreateError
+
+ def update_file(self, path, branch, content, message):
+ url = "/projects/%s/repository/files" % self.id
+ url += "?file_path=%s&branch_name=%s&content=%s&commit_message=%s" % \
+ (path, branch, content, message)
+ r = self.gitlab.rawPut(url)
+ if r.status_code != 200:
+ raise GitlabUpdateError
+
+ def delete_file(self, path, branch, message):
+ url = "/projects/%s/repository/files" % self.id
+ url += "?file_path=%s&branch_name=%s&commit_message=%s" % \
+ (path, branch, message)
+ r = self.gitlab.rawDelete(url)
+ if r.status_code != 200:
+ raise GitlabDeleteError
+
class TeamMember(GitlabObject):
_url = '/user_teams/%(team_id)s/members'