diff options
author | Gauvain Pocentek <gauvain@pocentek.net> | 2013-12-26 14:18:40 +0100 |
---|---|---|
committer | Gauvain Pocentek <gauvain@pocentek.net> | 2013-12-26 15:13:32 +0100 |
commit | ba39e88e215b6a5ef16c58efb26e33148a7fa19e (patch) | |
tree | 927f69e8b9471092d97fdecd7a5c6083b22953e9 | |
parent | debe41aee6eb53c11ea0e6870becc116947fe17d (diff) | |
download | gitlab-ba39e88e215b6a5ef16c58efb26e33148a7fa19e.tar.gz |
Project: add methods for create/update/delete files
-rw-r--r-- | gitlab.py | 42 |
1 files changed, 41 insertions, 1 deletions
@@ -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: @@ -880,6 +891,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, @@ -953,6 +969,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' |