Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita02180d

Browse files
author
Gauvain Pocentek
committed
implement protect/unprotect for branches
1 parentdd210be commita02180d

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

‎gitlab.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ class GitlabDeleteError(Exception):
4646
pass
4747

4848

49+
classGitlabProtectError(Exception):
50+
pass
51+
52+
4953
classGitlabAuthenticationError(Exception):
5054
pass
5155

@@ -121,6 +125,19 @@ def rawPost(self, path, data):
121125

122126
returnr
123127

128+
defrawPut(self,path,with_token=False):
129+
url='%s%s'% (self._url,path)
130+
ifwith_token:
131+
url+="?private_token=%s"%self.private_token
132+
133+
try:
134+
r=requests.put(url)
135+
except:
136+
raiseGitlabConnectionError(
137+
"Can't connect to GitLab server (%s)"%self._url)
138+
139+
returnr
140+
124141
deflist(self,obj_class,**kwargs):
125142
url=obj_class._url
126143
ifkwargs:
@@ -432,6 +449,24 @@ class ProjectBranch(GitlabObject):
432449
canUpdate=False
433450
canCreate=False
434451

452+
defprotect(self,protect=True):
453+
url=self._url% {'project_id':self.project_id}
454+
ifprotect:
455+
url="%s/%s/protect"% (url,self.name)
456+
else:
457+
url="%s/%s/unprotect"% (url,self.name)
458+
r=self.gitlab.rawPut(url,True)
459+
460+
ifr.status_code==200:
461+
ifprotect:
462+
self.protected=protect
463+
else:
464+
delself.protected
465+
else:
466+
raiseGitlabProtectError
467+
468+
defunprotect(self):
469+
self.protect(False)
435470

436471
classProjectCommit(GitlabObject):
437472
_url='/projects/%(project_id)d/repository/commits'

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp