|
1 |
| -fromgitlabimportcli |
2 |
| -fromgitlabimportexceptionsasexc |
3 | 1 | fromgitlab.baseimportRequiredOptional,RESTManager,RESTObject
|
4 | 2 | fromgitlab.mixinsimportNoUpdateMixin,ObjectDeleteMixin
|
5 | 3 |
|
|
14 | 12 | classProjectBranch(ObjectDeleteMixin,RESTObject):
|
15 | 13 | _id_attr="name"
|
16 | 14 |
|
17 |
| -@cli.register_custom_action( |
18 |
| -"ProjectBranch",tuple(), ("developers_can_push","developers_can_merge") |
19 |
| - ) |
20 |
| -@exc.on_http_error(exc.GitlabProtectError) |
21 |
| -defprotect(self,developers_can_push=False,developers_can_merge=False,**kwargs): |
22 |
| -"""Protect the branch. |
23 |
| -
|
24 |
| - Args: |
25 |
| - developers_can_push (bool): Set to True if developers are allowed |
26 |
| - to push to the branch |
27 |
| - developers_can_merge (bool): Set to True if developers are allowed |
28 |
| - to merge to the branch |
29 |
| - **kwargs: Extra options to send to the server (e.g. sudo) |
30 |
| -
|
31 |
| - Raises: |
32 |
| - GitlabAuthenticationError: If authentication is not correct |
33 |
| - GitlabProtectError: If the branch could not be protected |
34 |
| - """ |
35 |
| -id=self.get_id().replace("/","%2F") |
36 |
| -path="%s/%s/protect"% (self.manager.path,id) |
37 |
| -post_data= { |
38 |
| -"developers_can_push":developers_can_push, |
39 |
| -"developers_can_merge":developers_can_merge, |
40 |
| - } |
41 |
| -self.manager.gitlab.http_put(path,post_data=post_data,**kwargs) |
42 |
| -self._attrs["protected"]=True |
43 |
| - |
44 |
| -@cli.register_custom_action("ProjectBranch") |
45 |
| -@exc.on_http_error(exc.GitlabProtectError) |
46 |
| -defunprotect(self,**kwargs): |
47 |
| -"""Unprotect the branch. |
48 |
| -
|
49 |
| - Args: |
50 |
| - **kwargs: Extra options to send to the server (e.g. sudo) |
51 |
| -
|
52 |
| - Raises: |
53 |
| - GitlabAuthenticationError: If authentication is not correct |
54 |
| - GitlabProtectError: If the branch could not be unprotected |
55 |
| - """ |
56 |
| -id=self.get_id().replace("/","%2F") |
57 |
| -path="%s/%s/unprotect"% (self.manager.path,id) |
58 |
| -self.manager.gitlab.http_put(path,**kwargs) |
59 |
| -self._attrs["protected"]=False |
60 |
| - |
61 | 15 |
|
62 | 16 | classProjectBranchManager(NoUpdateMixin,RESTManager):
|
63 | 17 | _path="/projects/%(project_id)s/repository/branches"
|
|