Skip to content

Commit

Permalink
Merge branch 'mlq-feature/pipeline-schedules'
Browse files Browse the repository at this point in the history
  • Loading branch information
Gauvain Pocentek committed Feb 5, 2018
2 parents fd726cd + 6a87d38 commit 39a0429
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 40 deletions.
4 changes: 4 additions & 0 deletions gitlab/exceptions.py
Expand Up @@ -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.
Expand Down
75 changes: 35 additions & 40 deletions gitlab/v4/objects.py
Expand Up @@ -2028,59 +2028,45 @@ class ProjectPipelineScheduleVariable(SaveMixin, ObjectDeleteMixin, RESTObject):
_id_attr = 'key'


class ProjectPipelineScheduleVariableManager(CRUDMixin, RESTManager):
_path = '/projects/%(project_id)s/pipeline_schedules/%(pipeline_schedule_id)s/variables'
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 = (('pipeline_schedule_id', 'key', 'value'), tuple())
_create_attrs = (('key', 'value'), tuple())
_update_attrs = (('key', 'value'), tuple())

def list(self):
array = []
if 'variables' in self._parent._attrs:
for variable in self._parent._attrs['variables']:
schedule_variable = self._obj_cls(self, variable)
array.append(schedule_variable)
else:
obj = self._parent.manager.get(self._parent.id)
for variable in obj._attrs['variables']:
schedule_variable = self._obj_cls(self, variable)
array.append(schedule_variable)

return array
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.
class ProjectPipelineSchedule(RESTObject):
_managers = (
('variables', 'ProjectPipelineScheduleVariableManager'),
)
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 ProjectPipelineSchedulesManager(RetrieveMixin, CreateMixin, RESTManager):
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'))

def create(self, data, **kwargs):
"""Creates a new object.
Args:
data (dict): Parameters to send to the server to create the
resource
**kwargs: Extra options to send to the server (e.g. sudo)
Raises:
GitlabAuthenticationError: If authentication is not correct
GitlabCreateError: If the server cannot perform the request
Returns:
RESTObject: A new instance of the managed object class build with
the data sent by the server
"""
return CreateMixin.create(self, data, path=self.path, **kwargs)
_update_attrs = (tuple(),
('description', 'ref', 'cron', 'cron_timezone', 'active'))


class ProjectSnippetNote(SaveMixin, ObjectDeleteMixin, RESTObject):
Expand Down Expand Up @@ -2181,8 +2167,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)
Expand Down Expand Up @@ -2398,7 +2393,7 @@ class Project(SaveMixin, ObjectDeleteMixin, RESTObject):
('pagesdomains', 'ProjectPagesDomainManager'),
('pipelines', 'ProjectPipelineManager'),
('protectedbranches', 'ProjectProtectedBranchManager'),
('pipeline_schedules', 'ProjectPipelineSchedulesManager'),
('pipelineschedules', 'ProjectPipelineScheduleManager'),
('runners', 'ProjectRunnerManager'),
('services', 'ProjectServiceManager'),
('snippets', 'ProjectSnippetManager'),
Expand Down

0 comments on commit 39a0429

Please sign in to comment.