Skip to content

Commit

Permalink
Add support for project pipelines
Browse files Browse the repository at this point in the history
  • Loading branch information
Gauvain Pocentek committed Aug 27, 2016
1 parent ef2dbf7 commit 8257400
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 2 deletions.
20 changes: 20 additions & 0 deletions docs/gl_objects/projects.py
Expand Up @@ -382,3 +382,23 @@
# service delete
service.delete()
# end service delete

# pipeline list
pipelines = gl.project_pipelines.list(project_id=1)
# or
pipelines = project.pipelines.list()
# end pipeline list

# pipeline get
pipeline = gl.project_pipelines.get(pipeline_id, project_id=1)
# or
pipeline = project.pipelines.get(pipeline_id)
# end pipeline get

# pipeline retry
pipeline.retry()
# end pipeline retry

# pipeline cancel
pipeline.cancel()
# end pipeline cancel
31 changes: 31 additions & 0 deletions docs/gl_objects/projects.rst
Expand Up @@ -395,6 +395,37 @@ Delete a project hook:
:start-after: # hook delete
:end-before: # end hook delete

Pipelines
---------

Use :class:`~gitlab.objects.ProjectPipeline` objects to manipulate projects
pipelines. The :attr:`gitlab.Gitlab.project_pipelines` and
:attr:`Project.services <gitlab.objects.Projects.pipelines>` manager objects
provide helper functions.

List pipelines for a project:

.. literalinclude:: projects.py
:start-after: # pipeline list
:end-before: # end pipeline list

Get a pipeline for a project:

.. literalinclude:: projects.py
:start-after: # pipeline get
:end-before: # end pipeline get

Retry the failed builds for a pipeline:

.. literalinclude:: projects.py
:start-after: # pipeline retry
:end-before: # end pipeline retry

Cancel builds in a pipeline:

.. literalinclude:: projects.py
:start-after: # pipeline cancel
:end-before: # end pipeline cancel
Services
--------

Expand Down
3 changes: 3 additions & 0 deletions gitlab/__init__.py
Expand Up @@ -102,6 +102,8 @@ class Gitlab(object):
project_members (ProjectMemberManager): Manager for GitLab projects
members
project_notes (ProjectNoteManager): Manager for GitLab projects notes
project_pipelines (ProjectPipelineManager): Manager for GitLab projects
pipelines
project_tags (ProjectTagManager): Manager for GitLab projects tags
project_mergerequest_notes (ProjectMergeRequestNoteManager): Manager
for GitLab notes on merge requests
Expand Down Expand Up @@ -179,6 +181,7 @@ def __init__(self, url, private_token=None, email=None, password=None,
self.project_issues = ProjectIssueManager(self)
self.project_members = ProjectMemberManager(self)
self.project_notes = ProjectNoteManager(self)
self.project_pipelines = ProjectPipelineManager(self)
self.project_tags = ProjectTagManager(self)
self.project_mergerequest_notes = ProjectMergeRequestNoteManager(self)
self.project_mergerequests = ProjectMergeRequestManager(self)
Expand Down
20 changes: 18 additions & 2 deletions gitlab/exceptions.py
Expand Up @@ -75,11 +75,27 @@ class GitlabTransferProjectError(GitlabOperationError):
pass


class GitlabBuildCancelError(GitlabOperationError):
class GitlabCancelError(GitlabOperationError):
pass


class GitlabBuildRetryError(GitlabOperationError):
class GitlabBuildCancelError(GitlabCancelError):
pass


class GitlabPipelineCancelError(GitlabCancelError):
pass


class GitlabRetryError(GitlabOperationError):
pass


class GitlabBuildRetryError(GitlabRetryError):
pass


class GitlabPipelineRetryError(GitlabRetryError):
pass


Expand Down
38 changes: 38 additions & 0 deletions gitlab/objects.py
Expand Up @@ -1610,6 +1610,43 @@ class ProjectFileManager(BaseManager):
obj_cls = ProjectFile


class ProjectPipeline(GitlabObject):
_url = '/projects/%(project_id)s/pipelines'
canCreate = False
canUpdate = False
canDelete = False

def retry(self, **kwargs):
"""Retries failed builds in a pipeline.
Raises:
GitlabConnectionError: If the server cannot be reached.
GitlabPipelineRetryError: If the retry cannot be done.
"""
url = ('/projects/%(project_id)s/pipelines/%(id)s/retry' %
{'project_id': self.project_id, 'id': self.id})
r = self.gitlab._raw_post(url, data=None, content_type=None, **kwargs)
raise_error_from_response(r, GitlabPipelineRetryError, 201)
self._set_from_dict(r.json())

def cancel(self, **kwargs):
"""Cancel builds in a pipeline.
Raises:
GitlabConnectionError: If the server cannot be reached.
GitlabPipelineCancelError: If the retry cannot be done.
"""
url = ('/projects/%(project_id)s/pipelines/%(id)s/cancel' %
{'project_id': self.project_id, 'id': self.id})
r = self.gitlab._raw_post(url, data=None, content_type=None, **kwargs)
raise_error_from_response(r, GitlabPipelineRetryError, 200)
self._set_from_dict(r.json())


class ProjectPipelineManager(BaseManager):
obj_cls = ProjectPipeline


class ProjectSnippetNote(GitlabObject):
_url = '/projects/%(project_id)s/snippets/%(snippet_id)s/notes'
_constructorTypes = {'author': 'User'}
Expand Down Expand Up @@ -1804,6 +1841,7 @@ class Project(GitlabObject):
('mergerequests', ProjectMergeRequestManager, [('project_id', 'id')]),
('milestones', ProjectMilestoneManager, [('project_id', 'id')]),
('notes', ProjectNoteManager, [('project_id', 'id')]),
('pipelines', ProjectPipelineManager, [('project_id', 'id')]),
('services', ProjectServiceManager, [('project_id', 'id')]),
('snippets', ProjectSnippetManager, [('project_id', 'id')]),
('tags', ProjectTagManager, [('project_id', 'id')]),
Expand Down

0 comments on commit 8257400

Please sign in to comment.