diff options
Diffstat (limited to 'gitlab.py')
-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' |