Skip to content

Commit 6a87d38

Browse files
author
Gauvain Pocentek
committed
Update pipeline schedules code
2 parents f276f13 + b861837 commit 6a87d38

File tree

2 files changed

+64
-1
lines changed

2 files changed

+64
-1
lines changed

gitlab/exceptions.py

+4
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,10 @@ class GitlabHousekeepingError(GitlabOperationError):
193193
pass
194194

195195

196+
class GitlabOwnershipError(GitlabOperationError):
197+
pass
198+
199+
196200
def raise_error_from_response(response, error, expected_code=200):
197201
"""Tries to parse gitlab error message from response and raises error.
198202

gitlab/v4/objects.py

+60-1
Original file line numberDiff line numberDiff line change
@@ -2012,6 +2012,55 @@ def create(self, data, **kwargs):
20122012
return CreateMixin.create(self, data, path=path, **kwargs)
20132013

20142014

2015+
class ProjectPipelineScheduleVariable(SaveMixin, ObjectDeleteMixin, RESTObject):
2016+
_id_attr = 'key'
2017+
2018+
2019+
class ProjectPipelineScheduleVariableManager(CreateMixin, UpdateMixin,
2020+
DeleteMixin, RESTManager):
2021+
_path = ('/projects/%(project_id)s/pipeline_schedules/'
2022+
'%(pipeline_schedule_id)s/variables')
2023+
_obj_cls = ProjectPipelineScheduleVariable
2024+
_from_parent_attrs = {'project_id': 'project_id',
2025+
'pipeline_schedule_id' : 'id'}
2026+
_create_attrs = (('key', 'value'), tuple())
2027+
_update_attrs = (('key', 'value'), tuple())
2028+
2029+
2030+
class ProjectPipelineSchedule(SaveMixin, ObjectDeleteMixin, RESTObject):
2031+
_managers = (('variables', 'ProjectPipelineScheduleVariableManager'),)
2032+
2033+
@cli.register_custom_action('ProjectPipelineSchedule')
2034+
@exc.on_http_error(exc.GitlabOwnershipError)
2035+
def take_ownership(self, **kwargs):
2036+
"""Update the owner of a pipeline schedule.
2037+
2038+
Args:
2039+
**kwargs: Extra options to send to the server (e.g. sudo)
2040+
2041+
Raises:
2042+
GitlabAuthenticationError: If authentication is not correct
2043+
GitlabOwnershipError: If the request failed
2044+
"""
2045+
path = '%s/%s/take_ownership' % (self.manager.path, self.get_id())
2046+
server_data = self.manager.gitlab.http_post(path, **kwargs)
2047+
self._update_attrs(server_data)
2048+
2049+
2050+
class ProjectPipelineScheduleManager(CRUDMixin, RESTManager):
2051+
_path = '/projects/%(project_id)s/pipeline_schedules'
2052+
_obj_cls = ProjectPipelineSchedule
2053+
_from_parent_attrs = {'project_id': 'id'}
2054+
_create_attrs = (('description', 'ref', 'cron'),
2055+
('cron_timezone', 'active'))
2056+
_update_attrs = (tuple(),
2057+
('description', 'ref', 'cron', 'cron_timezone', 'active'))
2058+
2059+
2060+
class ProjectSnippetNote(SaveMixin, ObjectDeleteMixin, RESTObject):
2061+
pass
2062+
2063+
20152064
class ProjectPipelineJob(ProjectJob):
20162065
pass
20172066

@@ -2106,8 +2155,17 @@ class ProjectSnippetManager(CRUDMixin, RESTManager):
21062155

21072156
class ProjectTrigger(SaveMixin, ObjectDeleteMixin, RESTObject):
21082157
@cli.register_custom_action('ProjectTrigger')
2158+
@exc.on_http_error(exc.GitlabOwnershipError)
21092159
def take_ownership(self, **kwargs):
2110-
"""Update the owner of a trigger."""
2160+
"""Update the owner of a trigger.
2161+
2162+
Args:
2163+
**kwargs: Extra options to send to the server (e.g. sudo)
2164+
2165+
Raises:
2166+
GitlabAuthenticationError: If authentication is not correct
2167+
GitlabOwnershipError: If the request failed
2168+
"""
21112169
path = '%s/%s/take_ownership' % (self.manager.path, self.get_id())
21122170
server_data = self.manager.gitlab.http_post(path, **kwargs)
21132171
self._update_attrs(server_data)
@@ -2323,6 +2381,7 @@ class Project(SaveMixin, ObjectDeleteMixin, RESTObject):
23232381
('pagesdomains', 'ProjectPagesDomainManager'),
23242382
('pipelines', 'ProjectPipelineManager'),
23252383
('protectedbranches', 'ProjectProtectedBranchManager'),
2384+
('pipelineschedules', 'ProjectPipelineScheduleManager'),
23262385
('runners', 'ProjectRunnerManager'),
23272386
('services', 'ProjectServiceManager'),
23282387
('snippets', 'ProjectSnippetManager'),

0 commit comments

Comments
 (0)