8000 feat: add deployment creation by max-wittig · Pull Request #920 · python-gitlab/python-gitlab · GitHub
[go: up one dir, main page]

Skip to content

feat: add deployment creation #920

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 1 commit into from
Oct 24, 2019
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
16 changes: 16 additions & 0 deletions docs/gl_objects/deployments.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,19 @@ List deployments for a project::
Get a single deployment::

deployment = project.deployments.get(deployment_id)

Create a new deployment::

deployment = project.deployments.create({
"environment": "Test",
"sha": "1agf4gs",
"ref": "master",
"tag": False,
"status": "created",
})

Update a deployment::

deployment = project.deployments.get(42)
deployment.status = "failed"
deployment.save()
44 changes: 44 additions & 0 deletions gitlab/tests/test_gitlab.py
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,50 @@ def resp_mark_all_as_done(url, request):
with HTTMock(resp_mark_all_as_done):
self.gl.todos.mark_all_as_done()

def test_deployment(self):
content = '{"id": 42, "status": "success", "ref": "master"}'
json_content = json.loads(content)

@urlmatch(
scheme="http",
netloc="localhost",
path="/api/v4/projects/1/deployments",
method="post",
)
def resp_deployment_create(url, request):
headers = {"content-type": "application/json"}
return response(200, json_content, headers, None, 5, request)

@urlmatch(
scheme="http",
netloc="localhost",
path="/api/v4/projects/1/deployments/42",
method="put",
)
def resp_deployment_update(url, request):
headers = {"content-type": "application/json"}
return response(200, json_content, headers, None, 5, request)

with HTTMock(resp_deployment_create):
deployment = self.gl.projects.get(1, lazy=True).deployments.create(
{
"environment": "Test",
"sha": "1agf4gs",
"ref": "master",
"tag": False,
"status": "created",
}
)
self.assertEqual(deployment.id, 42)
self.assertEqual(deployment.status, "success")
self.assertEqual(deployment.ref, "master")

with HTTMock(resp_deployment_update):
json_content["status"] = "failed"
deployment.status = "failed"
deployment.save()
self.assertEqual(deployment.status, "failed")

def test_update_submodule(self):
@urlmatch(
scheme="http", netloc="localhost", path="/api/v4/projects/1$", method="get"
Expand Down
5 changes: 3 additions & 2 deletions gitlab/v4/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -3735,15 +3735,16 @@ def set_approvers(self, approver_ids=None, approver_group_ids=None, **kwargs):
self.gitlab.http_put(path, post_data=data, **kwargs)


class ProjectDeployment(RESTObject):
class ProjectDeployment(RESTObject, SaveMixin):
pass


class ProjectDeploymentManager(RetrieveMixin, RESTManager):
class ProjectDeploymentManager(RetrieveMixin, CreateMixin, UpdateMixin, RESTManager):
_path = "/projects/%(project_id)s/deployments"
_obj_cls = ProjectDeployment
_from_parent_attrs = {"project_id": "id"}
_list_filters = ("order_by", "sort")
_create_attrs = (("sha", "ref", "tag", "status", "environment"), tuple())


class ProjectProtectedBranch(ObjectDeleteMixin, RESTObject):
Expand Down
0