Skip to content

feat: add methods to retrieve an individual project environment #865

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
Aug 22, 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
4 changes: 4 additions & 0 deletions docs/gl_objects/environments.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ Create an environment for a project::

environment = project.environments.create({'name': 'production'})

Retrieve a specific environment for a project::

environment = project.environments.get(112)

Update an environment for a project::

environment.external_url = 'http://foo.bar.com'
Expand Down
30 changes: 30 additions & 0 deletions gitlab/tests/test_gitlab.py
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,36 @@ def resp_get_project(url, request):
self.assertEqual(data.name, "name")
self.assertEqual(data.id, 1)

def test_project_environments(self):
@urlmatch(
scheme="http", netloc="localhost", path="/api/v4/projects/1$", method="get"
)
def resp_get_project(url, request):
headers = {"content-type": "application/json"}
content = '{"name": "name", "id": 1}'.encode("utf-8")
return response(200, content, headers, None, 5, request)

@urlmatch(
scheme="http",
netloc="localhost",
path="/api/v4/projects/1/environments/1",
method="get",
)
def resp_get_environment(url, request):
headers = {"content-type": "application/json"}
content = '{"name": "environment_name", "id": 1, "last_deployment": "sometime"}'.encode(
"utf-8"
)
return response(200, content, headers, None, 5, request)

with HTTMock(resp_get_project, resp_get_environment):
project = self.gl.projects.get(1)
environment = project.environments.get(1)
self.assertIsInstance(environment, ProjectEnvironment)
self.assertEqual(environment.id, 1)
self.assertEqual(environment.last_deployment, "sometime")
self.assertEqual(environment.name, "environment_name")

def test_groups(self):
@urlmatch(
scheme="http", netloc="localhost", path="/api/v4/groups/1", method="get"
Expand Down
2 changes: 1 addition & 1 deletion gitlab/v4/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -1944,7 +1944,7 @@ def stop(self, **kwargs):


class ProjectEnvironmentManager(
ListMixin, CreateMixin, UpdateMixin, DeleteMixin, RESTManager
RetrieveMixin, CreateMixin, UpdateMixin, DeleteMixin, RESTManager
):
_path = "/projects/%(project_id)s/environments"
_obj_cls = ProjectEnvironment
Expand Down