Skip to content

Commit b81bd30

Browse files
committed
feat: add deployment creation
Added in GitLab 12.4 Fixes #917
1 parent e790b1e commit b81bd30

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

gitlab/tests/test_gitlab.py

+28
Original file line numberDiff line numberDiff line change
@@ -651,6 +651,34 @@ def resp_mark_all_as_done(url, request):
651651
with HTTMock(resp_mark_all_as_done):
652652
self.gl.todos.mark_all_as_done()
653653

654+
def test_deployment_create(self):
655+
content = '{"id": 42, "status": "success", "ref": "master"}'
656+
json_content = json.loads(content)
657+
658+
@urlmatch(
659+
scheme="http",
660+
netloc="localhost",
661+
path="/api/v4/projects/1/deployments",
662+
method="post",
663+
)
664+
def resp_deployment_create(url, request):
665+
headers = {"content-type": "application/json"}
666+
return response(200, json_content, headers, None, 5, request)
667+
668+
with HTTMock(resp_deployment_create):
669+
deployment = self.gl.projects.get(1, lazy=True).deployments.create(
670+
{
671+
"environment": "Test",
672+
"sha": "1agf4gs",
673+
"ref": "master",
674+
"tag": False,
675+
"status": "created",
676+
}
677+
)
678+
self.assertEqual(deployment.id, 42)
679+
self.assertEqual(deployment.status, "success")
680+
self.assertEqual(deployment.ref, "master")
681+
654682
def test_update_submodule(self):
655683
@urlmatch(
656684
scheme="http", netloc="localhost", path="/api/v4/projects/1$", method="get"

gitlab/v4/objects.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -3739,11 +3739,12 @@ class ProjectDeployment(RESTObject):
37393739
pass
37403740

37413741

3742-
class ProjectDeploymentManager(RetrieveMixin, RESTManager):
3742+
class ProjectDeploymentManager(RetrieveMixin, CreateMixin, RESTManager):
37433743
_path = "/projects/%(project_id)s/deployments"
37443744
_obj_cls = ProjectDeployment
37453745
_from_parent_attrs = {"project_id": "id"}
37463746
_list_filters = ("order_by", "sort")
3747+
_create_attrs = (("sha", "ref", "tag", "status", "environment"), tuple())
37473748

37483749

37493750
class ProjectProtectedBranch(ObjectDeleteMixin, RESTObject):

0 commit comments

Comments
 (0)