diff options
Diffstat (limited to 'gitlab')
-rw-r--r-- | gitlab/mixins.py | 11 | ||||
-rw-r--r-- | gitlab/v4/cli.py | 5 | ||||
-rw-r--r-- | gitlab/v4/objects.py | 22 |
3 files changed, 33 insertions, 5 deletions
diff --git a/gitlab/mixins.py b/gitlab/mixins.py index 59fcf1b..bd4d8c7 100644 --- a/gitlab/mixins.py +++ b/gitlab/mixins.py @@ -66,6 +66,8 @@ class GetWithoutIdMixin(object): GitlabGetError: If the server cannot perform the request """ server_data = self.gitlab.http_get(self.path, **kwargs) + if server_data is None: + return None return self._obj_cls(self, server_data) @@ -317,9 +319,12 @@ class DeleteMixin(object): GitlabAuthenticationError: If authentication is not correct GitlabDeleteError: If the server cannot perform the request """ - if not isinstance(id, int): - id = id.replace('/', '%2F') - path = '%s/%s' % (self.path, id) + if id is None: + path = self.path + else: + if not isinstance(id, int): + id = id.replace('/', '%2F') + path = '%s/%s' % (self.path, id) self.gitlab.http_delete(path, **kwargs) diff --git a/gitlab/v4/cli.py b/gitlab/v4/cli.py index 0e50de1..451bec8 100644 --- a/gitlab/v4/cli.py +++ b/gitlab/v4/cli.py @@ -143,8 +143,9 @@ def _populate_sub_parser_by_class(cls, sub_parser): action='store_true') if action_name == 'delete': - id_attr = cls._id_attr.replace('_', '-') - sub_parser_action.add_argument("--%s" % id_attr, required=True) + if cls._id_attr is not None: + id_attr = cls._id_attr.replace('_', '-') + sub_parser_action.add_argument("--%s" % id_attr, required=True) if action_name == "get": if gitlab.mixins.GetWithoutIdMixin not in inspect.getmro(cls): diff --git a/gitlab/v4/objects.py b/gitlab/v4/objects.py index 856d74a..2db2e39 100644 --- a/gitlab/v4/objects.py +++ b/gitlab/v4/objects.py @@ -2459,6 +2459,27 @@ class ProjectPipelineScheduleManager(CRUDMixin, RESTManager): ('description', 'ref', 'cron', 'cron_timezone', 'active')) +class ProjectPushRules(SaveMixin, ObjectDeleteMixin, RESTObject): + _id_attr = None + + +class ProjectPushRulesManager(GetWithoutIdMixin, CreateMixin, UpdateMixin, + DeleteMixin, RESTManager): + _path = '/projects/%(project_id)s/push_rule' + _obj_cls = ProjectPushRules + _from_parent_attrs = {'project_id': 'id'} + _create_attrs = (tuple(), + ('deny_delete_tag', 'member_check', + 'prevent_secrets', 'commit_message_regex', + 'branch_name_regex', 'author_email_regex', + 'file_name_regex', 'max_file_size')) + _update_attrs = (tuple(), + ('deny_delete_tag', 'member_check', + 'prevent_secrets', 'commit_message_regex', + 'branch_name_regex', 'author_email_regex', + 'file_name_regex', 'max_file_size')) + + class ProjectSnippetNoteAwardEmoji(ObjectDeleteMixin, RESTObject): pass @@ -2887,6 +2908,7 @@ class Project(SaveMixin, ObjectDeleteMixin, RESTObject): ('pipelines', 'ProjectPipelineManager'), ('protectedbranches', 'ProjectProtectedBranchManager'), ('pipelineschedules', 'ProjectPipelineScheduleManager'), + ('pushrules', 'ProjectPushRulesManager'), ('runners', 'ProjectRunnerManager'), ('services', 'ProjectServiceManager'), ('snippets', 'ProjectSnippetManager'), |