diff options
| author | Gauvain Pocentek <gauvain@pocentek.net> | 2013-02-16 09:33:07 +0100 |
|---|---|---|
| committer | Gauvain Pocentek <gauvain@pocentek.net> | 2013-02-16 09:33:07 +0100 |
| commit | a02180d1fe47ebf823f91ea0caff9064b58d2f5a (patch) | |
| tree | 8b1362056e340ee2a1c15acf536904d77939154b | |
| parent | dd210bef3cd64e5e51fa36960b8148ad5bddbeb7 (diff) | |
| download | gitlab-a02180d1fe47ebf823f91ea0caff9064b58d2f5a.tar.gz | |
implement protect/unprotect for branches
| -rw-r--r-- | gitlab.py | 35 |
1 files changed, 35 insertions, 0 deletions
@@ -46,6 +46,10 @@ class GitlabDeleteError(Exception): pass +class GitlabProtectError(Exception): + pass + + class GitlabAuthenticationError(Exception): pass @@ -121,6 +125,19 @@ class Gitlab(object): return r + 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) + + return r + def list(self, obj_class, **kwargs): url = obj_class._url if kwargs: @@ -432,6 +449,24 @@ class ProjectBranch(GitlabObject): canUpdate = False canCreate = False + def protect(self, protect=True): + url = self._url % {'project_id': self.project_id} + if protect: + url = "%s/%s/protect" % (url, self.name) + else: + url = "%s/%s/unprotect" % (url, self.name) + r = self.gitlab.rawPut(url, True) + + if r.status_code == 200: + if protect: + self.protected = protect + else: + del self.protected + else: + raise GitlabProtectError + + def unprotect(self): + self.protect(False) class ProjectCommit(GitlabObject): _url = '/projects/%(project_id)d/repository/commits' |
