Skip to content

Commit a428051

Browse files
nejchJohnVillalovos
authored andcommitted
refactor: migrate services to integrations
1 parent c6dd57c commit a428051

File tree

5 files changed

+79
-55
lines changed

5 files changed

+79
-55
lines changed

docs/gl_objects/projects.rst

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -643,56 +643,56 @@ Delete a project hook::
643643
# or
644644
hook.delete()
645645

646-
Project Services
647-
================
646+
Project Integrations
647+
====================
648648

649649
Reference
650650
---------
651651

652652
* v4 API:
653653

654-
+ :class:`gitlab.v4.objects.ProjectService`
655-
+ :class:`gitlab.v4.objects.ProjectServiceManager`
656-
+ :attr:`gitlab.v4.objects.Project.services`
654+
+ :class:`gitlab.v4.objects.ProjectIntegration`
655+
+ :class:`gitlab.v4.objects.ProjectIntegrationManager`
656+
+ :attr:`gitlab.v4.objects.Project.integrations`
657657

658-
* GitLab API: https://docs.gitlab.com/ce/api/services.html
658+
* GitLab API: https://docs.gitlab.com/ce/api/integrations.html
659659

660660
Examples
661661
---------
662662

663663
.. danger::
664664

665-
Since GitLab 13.12, ``get()`` calls to project services return a
665+
Since GitLab 13.12, ``get()`` calls to project integrations return a
666666
``404 Not Found`` response until they have been activated the first time.
667667

668668
To avoid this, we recommend using `lazy=True` to prevent making
669-
the initial call when activating new services unless they have
669+
the initial call when activating new integrations unless they have
670670
previously already been activated.
671671

672-
Configure and enable a service for the first time::
672+
Configure and enable an integration for the first time::
673673

674-
service = project.services.get('asana', lazy=True)
674+
integration = project.integrations.get('asana', lazy=True)
675675

676-
service.api_key = 'randomkey'
677-
service.save()
676+
integration.api_key = 'randomkey'
677+
integration.save()
678678

679-
Get an existing service::
679+
Get an existing integration::
680680

681-
service = project.services.get('asana')
681+
integration = project.integrations.get('asana')
682682
# display its status (enabled/disabled)
683-
print(service.active)
683+
print(integration.active)
684684

685-
List active project services::
685+
List active project integrations::
686686

687-
service = project.services.list()
687+
integration = project.integrations.list()
688688

689-
List the code names of available services (doesn't return objects)::
689+
List the code names of available integrations (doesn't return objects)::
690690

691-
services = project.services.available()
691+
integrations = project.integrations.available()
692692

693-
Disable a service::
693+
Disable an integration::
694694

695-
service.delete()
695+
integration.delete()
696696

697697
File uploads
698698
============

gitlab/v4/objects/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
from .group_access_tokens import *
4545
from .groups import *
4646
from .hooks import *
47+
from .integrations import *
4748
from .issues import *
4849
from .jobs import *
4950
from .keys import *
@@ -67,7 +68,6 @@
6768
from .releases import *
6869
from .repositories import *
6970
from .runners import *
70-
from .services import *
7171
from .settings import *
7272
from .sidekiq import *
7373
from .snippets import *

gitlab/v4/objects/services.py renamed to gitlab/v4/objects/integrations.py

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,23 @@
1717
)
1818

1919
__all__ = [
20+
"ProjectIntegration",
21+
"ProjectIntegrationManager",
2022
"ProjectService",
2123
"ProjectServiceManager",
2224
]
2325

2426

25-
class ProjectService(SaveMixin, ObjectDeleteMixin, RESTObject):
27+
class ProjectIntegration(SaveMixin, ObjectDeleteMixin, RESTObject):
2628
_id_attr = "slug"
2729

2830

29-
class ProjectServiceManager(GetMixin, UpdateMixin, DeleteMixin, ListMixin, RESTManager):
30-
_path = "/projects/{project_id}/services"
31+
class ProjectIntegrationManager(
32+
GetMixin, UpdateMixin, DeleteMixin, ListMixin, RESTManager
33+
):
34+
_path = "/projects/{project_id}/integrations"
3135
_from_parent_attrs = {"project_id": "id"}
32-
_obj_cls = ProjectService
36+
_obj_cls = ProjectIntegration
3337

3438
_service_attrs = {
3539
"asana": (("api_key",), ("restrict_to_branch", "push_events")),
@@ -263,14 +267,27 @@ class ProjectServiceManager(GetMixin, UpdateMixin, DeleteMixin, ListMixin, RESTM
263267

264268
def get(
265269
self, id: Union[str, int], lazy: bool = False, **kwargs: Any
266-
) -> ProjectService:
267-
return cast(ProjectService, super().get(id=id, lazy=lazy, **kwargs))
270+
) -> ProjectIntegration:
271+
return cast(ProjectIntegration, super().get(id=id, lazy=lazy, **kwargs))
268272

269-
@cli.register_custom_action("ProjectServiceManager")
273+
@cli.register_custom_action(("ProjectIntegrationManager", "ProjectServiceManager"))
270274
def available(self) -> List[str]:
271275
"""List the services known by python-gitlab.
272276
273277
Returns:
274278
The list of service code names.
275279
"""
276280
return list(self._service_attrs.keys())
281+
282+
283+
class ProjectService(ProjectIntegration):
284+
pass
285+
286+
287+
class ProjectServiceManager(ProjectIntegrationManager):
288+
_obj_cls = ProjectService
289+
290+
def get(
291+
self, id: Union[str, int], lazy: bool = False, **kwargs: Any
292+
) -> ProjectService:
293+
return cast(ProjectService, super().get(id=id, lazy=lazy, **kwargs))

gitlab/v4/objects/projects.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
from .export_import import ProjectExportManager, ProjectImportManager # noqa: F401
5555
from .files import ProjectFileManager # noqa: F401
5656
from .hooks import ProjectHookManager # noqa: F401
57+
from .integrations import ProjectIntegrationManager, ProjectServiceManager # noqa: F401
5758
from .issues import ProjectIssueManager # noqa: F401
5859
from .jobs import ProjectJobManager # noqa: F401
5960
from .labels import ProjectLabelManager # noqa: F401
@@ -79,7 +80,6 @@
7980
from .releases import ProjectReleaseManager # noqa: F401
8081
from .repositories import RepositoryMixin
8182
from .runners import ProjectRunnerManager # noqa: F401
82-
from .services import ProjectServiceManager # noqa: F401
8383
from .snippets import ProjectSnippetManager # noqa: F401
8484
from .statistics import ( # noqa: F401
8585
ProjectAdditionalStatisticsManager,
@@ -178,6 +178,7 @@ class Project(RefreshMixin, SaveMixin, ObjectDeleteMixin, RepositoryMixin, RESTO
178178
groups: ProjectGroupManager
179179
hooks: ProjectHookManager
180180
imports: ProjectImportManager
181+
integrations: ProjectIntegrationManager
181182
issues: ProjectIssueManager
182183
issues_statistics: ProjectIssuesStatisticsManager
183184
jobs: ProjectJobManager

tests/unit/objects/test_services.py

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
"""
2-
GitLab API: https://docs.gitlab.com/ce/api/services.html
2+
GitLab API: https://docs.gitlab.com/ce/api/integrations.html
33
"""
44

55
import pytest
66
import responses
77

8-
from gitlab.v4.objects import ProjectService
8+
from gitlab.v4.objects import ProjectIntegration, ProjectService
99

1010

1111
@pytest.fixture
12-
def resp_service():
12+
def resp_integration():
1313
content = {
1414
"id": 100152,
1515
"title": "Pipelines emails",
@@ -35,21 +35,21 @@ def resp_service():
3535
with responses.RequestsMock(assert_all_requests_are_fired=False) as rsps:
3636
rsps.add(
3737
method=responses.GET,
38-
url="http://localhost/api/v4/projects/1/services",
38+
url="http://localhost/api/v4/projects/1/integrations",
3939
json=[content],
4040
content_type="application/json",
4141
status=200,
4242
)
4343
rsps.add(
4444
method=responses.GET,
45-
url="http://localhost/api/v4/projects/1/services",
45+
url="http://localhost/api/v4/projects/1/integrations",
4646
json=content,
4747
content_type="application/json",
4848
status=200,
4949
)
5050
rsps.add(
5151
method=responses.GET,
52-
url="http://localhost/api/v4/projects/1/services/pipelines-email",
52+
url="http://localhost/api/v4/projects/1/integrations/pipelines-email",
5353
json=content,
5454
content_type="application/json",
5555
status=200,
@@ -58,36 +58,42 @@ def resp_service():
5858
updated_content["issues_events"] = False
5959
rsps.add(
6060
method=responses.PUT,
61-
url="http://localhost/api/v4/projects/1/services/pipelines-email",
61+
url="http://localhost/api/v4/projects/1/integrations/pipelines-email",
6262
json=updated_content,
6363
content_type="application/json",
6464
status=200,
6565
)
6666
yield rsps
6767

6868

69-
def test_list_active_services(project, resp_service):
70-
services = project.services.list()
71-
assert isinstance(services, list)
72-
assert isinstance(services[0], ProjectService)
73-
assert services[0].active
74-
assert services[0].push_events
69+
def test_list_active_integrations(project, resp_integration):
70+
integrations = project.integrations.list()
71+
assert isinstance(integrations, list)
72+
assert isinstance(integrations[0], ProjectIntegration)
73+
assert integrations[0].active
74+
assert integrations[0].push_events
7575

7676

77-
def test_list_available_services(project, resp_service):
78-
services = project.services.available()
79-
assert isinstance(services, list)
80-
assert isinstance(services[0], str)
77+
def test_list_available_integrations(project, resp_integration):
78+
integrations = project.integrations.available()
79+
assert isinstance(integrations, list)
80+
assert isinstance(integrations[0], str)
8181

8282

83-
def test_get_service(project, resp_service):
84-
service = project.services.get("pipelines-email")
85-
assert isinstance(service, ProjectService)
86-
assert service.push_events is True
83+
def test_get_integration(project, resp_integration):
84+
integration = project.integrations.get("pipelines-email")
85+
assert isinstance(integration, ProjectIntegration)
86+
assert integration.push_events is True
87+
8788

89+
def test_update_integration(project, resp_integration):
90+
integration = project.integrations.get("pipelines-email")
91+
integration.issues_events = False
92+
integration.save()
93+
assert integration.issues_events is False
8894

89-
def test_update_service(project, resp_service):
95+
96+
def test_get_service_returns_service(project, resp_integration):
97+
# todo: remove when services are removed
9098
service = project.services.get("pipelines-email")
91-
service.issues_events = False
92-
service.save()
93-
assert service.issues_events is False
99+
assert isinstance(service, ProjectService)

0 commit comments

Comments
 (0)