diff options
author | Gauvain Pocentek <gauvain@pocentek.net> | 2018-02-05 15:37:39 +0100 |
---|---|---|
committer | Gauvain Pocentek <gauvain@pocentek.net> | 2018-02-05 15:38:08 +0100 |
commit | 6a87d38b0c5ffdfa9c78dcf5232ec78986010ce6 (patch) | |
tree | 29a1c2641cbc0c6a4ec405a008273ac464767404 | |
parent | f276f13df50132554984f989b1d3d6c5fa8cdc01 (diff) | |
parent | b861837b25bb45dbe40b035dff5f41898450e22b (diff) | |
download | gitlab-6a87d38b0c5ffdfa9c78dcf5232ec78986010ce6.tar.gz |
Update pipeline schedules code
-rw-r--r-- | gitlab/exceptions.py | 4 | ||||
-rw-r--r-- | gitlab/v4/objects.py | 61 |
2 files changed, 64 insertions, 1 deletions
diff --git a/gitlab/exceptions.py b/gitlab/exceptions.py index 9a423dd..5825d23 100644 --- a/gitlab/exceptions.py +++ b/gitlab/exceptions.py @@ -193,6 +193,10 @@ class GitlabHousekeepingError(GitlabOperationError): pass +class GitlabOwnershipError(GitlabOperationError): + pass + + def raise_error_from_response(response, error, expected_code=200): """Tries to parse gitlab error message from response and raises error. diff --git a/gitlab/v4/objects.py b/gitlab/v4/objects.py index f8b0dce..aff5e17 100644 --- a/gitlab/v4/objects.py +++ b/gitlab/v4/objects.py @@ -2012,6 +2012,55 @@ class ProjectPipelineManager(RetrieveMixin, CreateMixin, RESTManager): return CreateMixin.create(self, data, path=path, **kwargs) +class ProjectPipelineScheduleVariable(SaveMixin, ObjectDeleteMixin, RESTObject): + _id_attr = 'key' + + +class ProjectPipelineScheduleVariableManager(CreateMixin, UpdateMixin, + DeleteMixin, RESTManager): + _path = ('/projects/%(project_id)s/pipeline_schedules/' + '%(pipeline_schedule_id)s/variables') + _obj_cls = ProjectPipelineScheduleVariable + _from_parent_attrs = {'project_id': 'project_id', + 'pipeline_schedule_id' : 'id'} + _create_attrs = (('key', 'value'), tuple()) + _update_attrs = (('key', 'value'), tuple()) + + +class ProjectPipelineSchedule(SaveMixin, ObjectDeleteMixin, RESTObject): + _managers = (('variables', 'ProjectPipelineScheduleVariableManager'),) + + @cli.register_custom_action('ProjectPipelineSchedule') + @exc.on_http_error(exc.GitlabOwnershipError) + def take_ownership(self, **kwargs): + """Update the owner of a pipeline schedule. + + Args: + **kwargs: Extra options to send to the server (e.g. sudo) + + Raises: + GitlabAuthenticationError: If authentication is not correct + GitlabOwnershipError: If the request failed + """ + path = '%s/%s/take_ownership' % (self.manager.path, self.get_id()) + server_data = self.manager.gitlab.http_post(path, **kwargs) + self._update_attrs(server_data) + + +class ProjectPipelineScheduleManager(CRUDMixin, RESTManager): + _path = '/projects/%(project_id)s/pipeline_schedules' + _obj_cls = ProjectPipelineSchedule + _from_parent_attrs = {'project_id': 'id'} + _create_attrs = (('description', 'ref', 'cron'), + ('cron_timezone', 'active')) + _update_attrs = (tuple(), + ('description', 'ref', 'cron', 'cron_timezone', 'active')) + + +class ProjectSnippetNote(SaveMixin, ObjectDeleteMixin, RESTObject): + pass + + class ProjectPipelineJob(ProjectJob): pass @@ -2106,8 +2155,17 @@ class ProjectSnippetManager(CRUDMixin, RESTManager): class ProjectTrigger(SaveMixin, ObjectDeleteMixin, RESTObject): @cli.register_custom_action('ProjectTrigger') + @exc.on_http_error(exc.GitlabOwnershipError) def take_ownership(self, **kwargs): - """Update the owner of a trigger.""" + """Update the owner of a trigger. + + Args: + **kwargs: Extra options to send to the server (e.g. sudo) + + Raises: + GitlabAuthenticationError: If authentication is not correct + GitlabOwnershipError: If the request failed + """ path = '%s/%s/take_ownership' % (self.manager.path, self.get_id()) server_data = self.manager.gitlab.http_post(path, **kwargs) self._update_attrs(server_data) @@ -2323,6 +2381,7 @@ class Project(SaveMixin, ObjectDeleteMixin, RESTObject): ('pagesdomains', 'ProjectPagesDomainManager'), ('pipelines', 'ProjectPipelineManager'), ('protectedbranches', 'ProjectProtectedBranchManager'), + ('pipelineschedules', 'ProjectPipelineScheduleManager'), ('runners', 'ProjectRunnerManager'), ('services', 'ProjectServiceManager'), ('snippets', 'ProjectSnippetManager'), |