1- from typing import Any , cast , Dict , List , Optional , TYPE_CHECKING , Union
1+ from typing import Any , cast , List , Optional , TYPE_CHECKING , Union
22
33from gitlab import exceptions as exc
44from gitlab .base import RESTManager , RESTObject
@@ -132,42 +132,16 @@ def set_approvers(
132132
133133class ProjectMergeRequestApprovalRule (SaveMixin , ObjectDeleteMixin , RESTObject ):
134134 _repr_attr = "name"
135- id : int
136- approval_rule_id : int
137- merge_request_iid : int
138-
139- @exc .on_http_error (exc .GitlabUpdateError )
140- def save (self , ** kwargs : Any ) -> None :
141- """Save the changes made to the object to the server.
142-
143- The object is updated to match what the server returns.
144-
145- Args:
146- **kwargs: Extra options to send to the server (e.g. sudo)
147-
148- Raise:
149- GitlabAuthenticationError: If authentication is not correct
150- GitlabUpdateError: If the server cannot perform the request
151- """
152- # There is a mismatch between the name of our id attribute and the put
153- # REST API name for the project_id, so we override it here.
154- self .approval_rule_id = self .id
155- self .merge_request_iid = self ._parent_attrs ["mr_iid" ]
156- self .id = self ._parent_attrs ["project_id" ]
157- # save will update self.id with the result from the server, so no need
158- # to overwrite with what it was before we overwrote it.
159- SaveMixin .save (self , ** kwargs )
160135
161136
162137class ProjectMergeRequestApprovalRuleManager (CRUDMixin , RESTManager ):
163- _path = "/projects/{project_id}/merge_requests/{mr_iid }/approval_rules"
138+ _path = "/projects/{project_id}/merge_requests/{merge_request_iid }/approval_rules"
164139 _obj_cls = ProjectMergeRequestApprovalRule
165- _from_parent_attrs = {"project_id" : "project_id" , "mr_iid " : "iid" }
140+ _from_parent_attrs = {"project_id" : "project_id" , "merge_request_iid " : "iid" }
166141 _update_attrs = RequiredOptional (
167142 required = (
168143 "id" ,
169144 "merge_request_iid" ,
170- "approval_rule_id" ,
171145 "name" ,
172146 "approvals_required" ,
173147 ),
@@ -177,7 +151,7 @@ class ProjectMergeRequestApprovalRuleManager(CRUDMixin, RESTManager):
177151 # groups of project-level rule will be copied. The approvals_required
178152 # specified will be used.
179153 _create_attrs = RequiredOptional (
180- required = ("id" , "merge_request_iid" , " name" , "approvals_required" ),
154+ required = ("name" , "approvals_required" ),
181155 optional = ("approval_project_rule_id" , "user_ids" , "group_ids" ),
182156 )
183157
@@ -188,32 +162,6 @@ def get(
188162 ProjectMergeRequestApprovalRule , super ().get (id = id , lazy = lazy , ** kwargs )
189163 )
190164
191- def create (
192- self , data : Optional [Dict [str , Any ]] = None , ** kwargs : Any
193- ) -> RESTObject :
194- """Create a new object.
195-
196- Args:
197- data: Parameters to send to the server to create the
198- resource
199- **kwargs: Extra options to send to the server (e.g. sudo or
200- 'ref_name', 'stage', 'name', 'all')
201-
202- Raises:
203- GitlabAuthenticationError: If authentication is not correct
204- GitlabCreateError: If the server cannot perform the request
205-
206- Returns:
207- A new instance of the manage object class build with
208- the data sent by the server
209- """
210- if TYPE_CHECKING :
211- assert data is not None
212- new_data = data .copy ()
213- new_data ["id" ] = self ._from_parent_attrs ["project_id" ]
214- new_data ["merge_request_iid" ] = self ._from_parent_attrs ["mr_iid" ]
215- return CreateMixin .create (self , new_data , ** kwargs )
216-
217165
218166class ProjectMergeRequestApprovalState (RESTObject ):
219167 pass
0 commit comments