Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitfc52221

Browse files
committed
feat(services): add project service list API
Can be used to list available servicesIt was introduced in GitLab 12.7
1 parent70cefe4 commitfc52221

File tree

3 files changed

+130
-2
lines changed

3 files changed

+130
-2
lines changed

‎docs/gl_objects/projects.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -608,6 +608,10 @@ Get a service::
608608
# display its status (enabled/disabled)
609609
print(service.active)
610610

611+
List active project services::
612+
613+
service = project.services.list()
614+
611615
List the code names of available services (doesn't return objects)::
612616

613617
services = project.services.available()

‎gitlab/tests/objects/test_projects.py

Lines changed: 125 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,102 @@ def resp_update_remote_mirror(url, request):
161161
returnresponse(200,content,headers,None,5,request)
162162

163163

164+
@urlmatch(
165+
scheme="http",
166+
netloc="localhost",
167+
path="/api/v4/projects/1/services/pipelines-email",
168+
method="put",
169+
)
170+
defresp_update_service(url,request):
171+
"""Mock for Service update PUT response."""
172+
content="""{
173+
"id": 100152,
174+
"title": "Pipelines emails",
175+
"slug": "pipelines-email",
176+
"created_at": "2019-01-14T08:46:43.637+01:00",
177+
"updated_at": "2019-07-01T14:10:36.156+02:00",
178+
"active": true,
179+
"commit_events": true,
180+
"push_events": true,
181+
"issues_events": true,
182+
"confidential_issues_events": true,
183+
"merge_requests_events": true,
184+
"tag_push_events": true,
185+
"note_events": true,
186+
"confidential_note_events": true,
187+
"pipeline_events": true,
188+
"wiki_page_events": true,
189+
"job_events": true,
190+
"comment_on_event_enabled": true,
191+
"project_id": 1
192+
}"""
193+
content=content.encode("utf-8")
194+
returnresponse(200,content,headers,None,5,request)
195+
196+
197+
@urlmatch(
198+
scheme="http",
199+
netloc="localhost",
200+
path="/api/v4/projects/1/services/pipelines-email",
201+
method="get",
202+
)
203+
defresp_get_service(url,request):
204+
"""Mock for Service GET response."""
205+
content="""{
206+
"id": 100152,
207+
"title": "Pipelines emails",
208+
"slug": "pipelines-email",
209+
"created_at": "2019-01-14T08:46:43.637+01:00",
210+
"updated_at": "2019-07-01T14:10:36.156+02:00",
211+
"active": true,
212+
"commit_events": true,
213+
"push_events": true,
214+
"issues_events": true,
215+
"confidential_issues_events": true,
216+
"merge_requests_events": true,
217+
"tag_push_events": true,
218+
"note_events": true,
219+
"confidential_note_events": true,
220+
"pipeline_events": true,
221+
"wiki_page_events": true,
222+
"job_events": true,
223+
"comment_on_event_enabled": true,
224+
"project_id": 1
225+
}"""
226+
content=content.encode("utf-8")
227+
returnresponse(200,content,headers,None,5,request)
228+
229+
230+
@urlmatch(
231+
scheme="http",netloc="localhost",path="/api/v4/projects/1/services",method="get",
232+
)
233+
defresp_get_active_services(url,request):
234+
"""Mock for Service update PUT response."""
235+
content="""[{
236+
"id": 100152,
237+
"title": "Pipelines emails",
238+
"slug": "pipelines-email",
239+
"created_at": "2019-01-14T08:46:43.637+01:00",
240+
"updated_at": "2019-07-01T14:10:36.156+02:00",
241+
"active": true,
242+
"commit_events": true,
243+
"push_events": true,
244+
"issues_events": true,
245+
"confidential_issues_events": true,
246+
"merge_requests_events": true,
247+
"tag_push_events": true,
248+
"note_events": true,
249+
"confidential_note_events": true,
250+
"pipeline_events": true,
251+
"wiki_page_events": true,
252+
"job_events": true,
253+
"comment_on_event_enabled": true,
254+
"project_id": 1
255+
}]"""
256+
content=content.encode("utf-8")
257+
returnresponse(200,content,headers,None,5,request)
258+
259+
164260
classTestProject(unittest.TestCase):
165261
"""Base class for GitLab Project tests."""
166262

@@ -169,7 +265,7 @@ def setUp(self):
169265
"http://localhost",
170266
private_token="private_token",
171267
ssl_verify=True,
172-
api_version=4,
268+
api_version="4",
173269
)
174270
self.project=self.gl.projects.get(1,lazy=True)
175271

@@ -356,3 +452,31 @@ def test_update_project_remote_mirror(self):
356452
mirror.save()
357453
self.assertEqual(mirror.update_status,"finished")
358454
self.assertTrue(mirror.only_protected_branches)
455+
456+
457+
classTestProjectServices(TestProject):
458+
@with_httmock(resp_get_active_services)
459+
deftest_list_active_services(self):
460+
services=self.project.services.list()
461+
self.assertIsInstance(services,list)
462+
self.assertIsInstance(services[0],ProjectService)
463+
self.assertTrue(services[0].active)
464+
self.assertTrue(services[0].push_events)
465+
466+
deftest_list_available_services(self):
467+
services=self.project.services.available()
468+
self.assertIsInstance(services,list)
469+
self.assertIsInstance(services[0],str)
470+
471+
@with_httmock(resp_get_service)
472+
deftest_get_service(self):
473+
service=self.project.services.get("pipelines-email")
474+
self.assertIsInstance(service,ProjectService)
475+
self.assertEqual(service.push_events,True)
476+
477+
@with_httmock(resp_get_service,resp_update_service)
478+
deftest_update_service(self):
479+
service=self.project.services.get("pipelines-email")
480+
service.issues_events=True
481+
service.save()
482+
self.assertEqual(service.issues_events,True)

‎gitlab/v4/objects.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3995,7 +3995,7 @@ class ProjectService(SaveMixin, ObjectDeleteMixin, RESTObject):
39953995
pass
39963996

39973997

3998-
classProjectServiceManager(GetMixin,UpdateMixin,DeleteMixin,RESTManager):
3998+
classProjectServiceManager(GetMixin,UpdateMixin,DeleteMixin,ListMixin,RESTManager):
39993999
_path="/projects/%(project_id)s/services"
40004000
_from_parent_attrs= {"project_id":"id"}
40014001
_obj_cls=ProjectService

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp