diff options
Diffstat (limited to 'gitlab')
-rw-r--r-- | gitlab/mixins.py | 16 | ||||
-rw-r--r-- | gitlab/v4/objects.py | 37 |
2 files changed, 51 insertions, 2 deletions
diff --git a/gitlab/mixins.py b/gitlab/mixins.py index 966a647..59fcf1b 100644 --- a/gitlab/mixins.py +++ b/gitlab/mixins.py @@ -223,6 +223,18 @@ class UpdateMixin(object): """ return getattr(self, '_update_attrs', (tuple(), tuple())) + def _get_update_method(self): + """Return the HTTP method to use. + + Returns: + object: http_put (default) or http_post + """ + if getattr(self, '_update_uses_post', False): + http_method = self.gitlab.http_post + else: + http_method = self.gitlab.http_put + return http_method + @exc.on_http_error(exc.GitlabUpdateError) def update(self, id=None, new_data={}, **kwargs): """Update an object on the server. @@ -265,8 +277,8 @@ class UpdateMixin(object): else: new_data[attr_name] = type_obj.get_for_api() - return self.gitlab.http_put(path, post_data=new_data, files=files, - **kwargs) + http_method = self._get_update_method() + return http_method(path, post_data=new_data, files=files, **kwargs) class SetMixin(object): diff --git a/gitlab/v4/objects.py b/gitlab/v4/objects.py index 13c9995..d6ae6c5 100644 --- a/gitlab/v4/objects.py +++ b/gitlab/v4/objects.py @@ -2631,6 +2631,42 @@ class ProjectAccessRequestManager(ListMixin, CreateMixin, DeleteMixin, _from_parent_attrs = {'project_id': 'id'} +class ProjectApproval(SaveMixin, RESTObject): + _id_attr = None + + +class ProjectApprovalManager(GetWithoutIdMixin, UpdateMixin, RESTManager): + _path = '/projects/%(project_id)s/approvals' + _obj_cls = ProjectApproval + _from_parent_attrs = {'project_id': 'id'} + _update_attrs = (tuple(), + ('approvals_before_merge', 'reset_approvals_on_push', + 'disable_overriding_approvers_per_merge_request')) + _update_uses_post = True + + @exc.on_http_error(exc.GitlabUpdateError) + def set_approvers(self, approver_ids=[], approver_group_ids=[], + **kwargs): + """Change project-level allowed approvers and approver groups. + + Args: + approver_ids (list): User IDs that can approve MRs. + approver_group_ids (list): Group IDs whose members can approve MRs. + + Raises: + GitlabAuthenticationError: If authentication is not correct + GitlabUpdateError: If the server failed to perform the request + """ + + path = '/projects/%s/approvers' % self._parent.get_id() + data = {'approver_ids': approver_ids, + 'approver_group_ids': approver_group_ids} + try: + self.gitlab.http_put(path, post_data=data, **kwargs) + except exc.GitlabHttpError as e: + raise exc.GitlabUpdateError(e.response_code, e.error_message) + + class ProjectDeployment(RESTObject): pass @@ -2729,6 +2765,7 @@ class Project(SaveMixin, ObjectDeleteMixin, RESTObject): _short_print_attr = 'path' _managers = ( ('accessrequests', 'ProjectAccessRequestManager'), + ('approvals', 'ProjectApprovalManager'), ('badges', 'ProjectBadgeManager'), ('boards', 'ProjectBoardManager'), ('branches', 'ProjectBranchManager'), |