8000 add support for project builds · andreascian/python-gitlab@ebf36b8 · GitHub
[go: up one dir, main page]

Skip to content

Commit ebf36b8

Browse files
author
Gauvain Pocentek
committed
add support for project builds
1 parent fc8affd commit ebf36b8

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

gitlab/exceptions.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,14 @@ class GitlabTransferProjectError(GitlabOperationError):
7575
pass
7676

7777

78+
class GitlabBuildCancelError(GitlabOperationError):
79+
pass
80+
81+
82+
class GitlabBuildRetryError(GitlabOperationError):
83+
pass
84+
85+
7886
def raise_error_from_response(response, error, expected_code=200):
7987
"""Tries to parse gitlab error message from response and raises error.
8088

gitlab/objects.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -691,6 +691,30 @@ class ProjectBranchManager(BaseManager):
691691
obj_cls = ProjectBranch
692692

693693

694+
class ProjectBuild(GitlabObject):
695+
_url = '/projects/%(project_id)s/builds'
696+
_constructorTypes = {'user': 'User',
697+
'commit': 'ProjectCommit'}
698+
requiredUrlAttrs = ['project_id']
699+
canDelete = False
700+
canUpdate = False
701+
canCreate = False
702+
703+
def cancel(self):
704+
url = '/projects/%s/builds/%s/cancel' % (self.project_id, self.id)
705+
r = self.gitlab._raw_post(url)
706+
raise_error_from_response(r, GitlabBuildCancelError, 201)
707+
708+
def retry(self):
709+
url = '/projects/%s/builds/%s/retry' % (self.project_id, self.id)
710+
r = self.gitlab._raw_post(url)
711+
raise_error_from_response(r, GitlabBuildRetryError, 201)
712+
713+
714+
class ProjectBuildManager(BaseManager):
715+
obj_cls = ProjectBuild
716+
717+
694718
class ProjectCommit(GitlabObject):
695719
_url = '/projects/%(project_id)s/repository/commits'
696720
canDelete = False
@@ -716,6 +740,20 @@ def blob(self, filepath, **kwargs):
716740

717741
return r.content
718742

743+
def builds(self, **kwargs):
744+
url = '/projects/%s/repository/commits/%s/builds' % (self.project_id,
745+
self.id)
746+
r = self.gitlab._raw_get(url, **kwargs)
747+
raise_error_from_response(r, GitlabListError)
748+
749+
l = []
750+
for j in r.json():
751+
o = ProjectBuild(self, j)
752+
o._from_api = True
753+
l.append(o)
754+
755+
return l
756+
719757

720758
class ProjectCommitManager(BaseManager):
721759
obj_cls = ProjectCommit
@@ -1088,6 +1126,7 @@ class Project(GitlabObject):
10881126
shortPrintAttr = 'path'
10891127
managers = [
10901128
('branches', ProjectBranchManager, [('project_id', 'id')]),
1129+
('builds', ProjectBuildManager, [('project_id', 'id')]),
10911130
('commits', ProjectCommitManager, [('project_id', 'id')]),
10921131
('commitstatuses', ProjectCommitStatusManager, [('project_id', 'id')]),
10931132
('events', ProjectEventManager, [('project_id', 'id')]),

0 commit comments

Comments
 (0)
0