Skip to content

Feature/pipeline schedules #398

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions gitlab/v3/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -1496,6 +1496,18 @@ class ProjectFileManager(BaseManager):
obj_cls = ProjectFile


class ProjectPipelineSchedule(GitlabObject):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think pipelines schedule are implemented in the v3 API, so this file should probably not be changed.

_url = '/projects/%(project_id)s/pipeline_schedules'
_create_url = '/projects/%(project_id)s/pipeline_schedules'

requiredUrlAttrs = ['project_id']
requiredCreateAttrs = ['description', 'ref', 'cron']


class ProjectPipelineSchedulesManager(BaseManager):
obj_cls = ProjectPipelineSchedule


class ProjectPipeline(GitlabObject):
_url = '/projects/%(project_id)s/pipelines'
_create_url = '/projects/%(project_id)s/pipeline'
Expand Down Expand Up @@ -1803,6 +1815,7 @@ class Project(GitlabObject):
('notificationsettings', 'ProjectNotificationSettingsManager',
[('project_id', 'id')]),
('pipelines', 'ProjectPipelineManager', [('project_id', 'id')]),
('pipeline_schedules', 'ProjectPipelineSchedulesManager', [('project_id', 'id')]),
('runners', 'ProjectRunnerManager', [('project_id', 'id')]),
('services', 'ProjectServiceManager', [('project_id', 'id')]),
('snippets', 'ProjectSnippetManager', [('project_id', 'id')]),
Expand Down
76 changes: 76 additions & 0 deletions gitlab/v4/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -1706,7 +1706,23 @@ def raw(self, file_path, ref, streamed=False, action=None, chunk_size=1024,
return utils.response_content(result, streamed, action, chunk_size)


class ProjectPipelineJob(ProjectJob):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pipeline jobs support has already be implemented, could you remove these items?

pass


class ProjectPipelineJobsManager(ListMixin, RESTManager):
_path = '/projects/%(project_id)s/pipelines/%(pipeline_id)s/jobs'
_obj_cls = ProjectPipelineJob
_from_parent_attrs = {'project_id': 'project_id',
'pipeline_id' : 'id'}
_list_filters = ('scope',)


class ProjectPipeline(RESTObject):
_managers = (
('jobs', 'ProjectPipelineJobsManager'),
)

@cli.register_custom_action('ProjectPipeline')
@exc.on_http_error(exc.GitlabPipelineCancelError)
def cancel(self, **kwargs):
Expand Down Expand Up @@ -1764,6 +1780,65 @@ def create(self, data, **kwargs):
return CreateMixin.create(self, data, path=path, **kwargs)


class ProjectPipelineScheduleVariable(SaveMixin, ObjectDeleteMixin, RESTObject):
_id_attr = 'key'


class ProjectPipelineScheduleVariableManager(CRUDMixin, 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())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can remove this line since you redefine _create_attrs on the next line.

_create_attrs = (('key', 'value'), tuple())

def list(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure it's a good idea to implement this method. I'd like to avoid adding features that are not directly coming from the GitLab API. I'd rather remove this method.

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(RESTObject):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GitLab supports updating and deleting these resources, so you need to add the SaveMixin and ObjectDeleteMixin here.

_managers = (
('variables', 'ProjectPipelineScheduleVariableManager'),
)


class ProjectPipelineSchedulesManager(RetrieveMixin, CreateMixin, RESTManager):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use the CRUDMixin since all the methods are supported.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And the class should be called ProjectPipelineScheduleManager (no plural).

_path = '/projects/%(project_id)s/pipeline_schedules'
_obj_cls = ProjectPipelineSchedule
_from_parent_attrs = {'project_id': 'id'}
_create_attrs = (('description', 'ref', 'cron'),
('cron_timezone', 'active'))

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you define the _update_attrs attributes as well?

def create(self, data, **kwargs):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think you need this method (you're just calling the mixin method).

"""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)


class ProjectSnippetNote(SaveMixin, ObjectDeleteMixin, RESTObject):
pass

Expand Down Expand Up @@ -2035,6 +2110,7 @@ class Project(SaveMixin, ObjectDeleteMixin, RESTObject):
('notificationsettings', 'ProjectNotificationSettingsManager'),
('pipelines', 'ProjectPipelineManager'),
('protectedbranches', 'ProjectProtectedBranchManager'),
('pipeline_schedules', 'ProjectPipelineSchedulesManager'),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you use pipelineschedules for consistency with the rest of the attribute names?

('runners', 'ProjectRunnerManager'),
('services', 'ProjectServiceManager'),
('snippets', 'ProjectSnippetManager'),
Expand Down