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

Commit2816c1a

Browse files
author
Gauvain Pocentek
committed
Make the project services work in v4
1 parenteee39a3 commit2816c1a

File tree

3 files changed

+56
-50
lines changed

3 files changed

+56
-50
lines changed

‎gitlab/mixins.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,8 @@ def save(self, **kwargs):
274274
# call the manager
275275
obj_id=self.get_id()
276276
server_data=self.manager.update(obj_id,updated_data,**kwargs)
277-
self._update_attrs(server_data)
277+
ifserver_dataisnotNone:
278+
self._update_attrs(server_data)
278279

279280

280281
classObjectDeleteMixin(object):

‎gitlab/v4/objects.py

Lines changed: 46 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
from __future__importprint_function
1919
from __future__importabsolute_import
2020
importbase64
21-
importjson
2221

2322
importsix
2423

@@ -1573,14 +1572,14 @@ class ProjectVariableManager(CRUDMixin, RESTManager):
15731572
_update_attrs= (('key','value'),tuple())
15741573

15751574

1576-
classProjectService(GitlabObject):
1577-
_url='/projects/%(project_id)s/services/%(service_name)s'
1578-
canList=False
1579-
canCreate=False
1580-
_id_in_update_url=False
1581-
_id_in_delete_url=False
1582-
getRequiresId=False
1583-
requiredUrlAttrs=['project_id','service_name']
1575+
classProjectService(SaveMixin,ObjectDeleteMixin,RESTObject):
1576+
pass
1577+
1578+
1579+
classProjectServiceManager(GetMixin,UpdateMixin,DeleteMixin,RESTManager):
1580+
_path='/projects/%(project_id)s/services'
1581+
_from_parent_attrs={'project_id':'id'}
1582+
_obj_cls=ProjectService
15841583

15851584
_service_attrs= {
15861585
'asana': (('api_key', ), ('restrict_to_branch', )),
@@ -1606,16 +1605,10 @@ class ProjectService(GitlabObject):
16061605
'server')),
16071606
'irker': (('recipients', ), ('default_irc_uri','server_port',
16081607
'server_host','colorize_messages')),
1609-
'jira': (tuple(), (
1610-
# Required fields in GitLab >= 8.14
1611-
'url','project_key',
1612-
1613-
# Required fields in GitLab < 8.14
1614-
'new_issue_url','project_url','issues_url','api_url',
1615-
'description',
1616-
1617-
# Optional fields
1618-
'username','password','jira_issue_transition_id')),
1608+
'jira': (('url','project_key'),
1609+
('new_issue_url','project_url','issues_url','api_url',
1610+
'description','username','password',
1611+
'jira_issue_transition_id')),
16191612
'pivotaltracker': (('token', ),tuple()),
16201613
'pushover': (('api_key','user_key','priority'), ('device','sound')),
16211614
'redmine': (('new_issue_url','project_url','issues_url'),
@@ -1625,41 +1618,52 @@ class ProjectService(GitlabObject):
16251618
tuple())
16261619
}
16271620

1628-
def_data_for_gitlab(self,extra_parameters={},update=False,
1629-
as_json=True):
1630-
data= (super(ProjectService,self)
1631-
._data_for_gitlab(extra_parameters,update=update,
1632-
as_json=False))
1633-
missing= []
1634-
# Mandatory args
1635-
forattrinself._service_attrs[self.service_name][0]:
1636-
ifnothasattr(self,attr):
1637-
missing.append(attr)
1638-
else:
1639-
data[attr]=getattr(self,attr)
1621+
defget(self,id,**kwargs):
1622+
"""Retrieve a single object.
16401623
1641-
ifmissing:
1642-
raiseGitlabUpdateError('Missing attribute(s): %s'%
1643-
", ".join(missing))
1624+
Args:
1625+
id (int or str): ID of the object to retrieve
1626+
lazy (bool): If True, don't request the server, but create a
1627+
shallow object giving access to the managers. This is
1628+
useful if you want to avoid useless calls to the API.
1629+
**kwargs: Extra options to send to the Gitlab server (e.g. sudo)
16441630
1645-
# Optional args
1646-
forattrinself._service_attrs[self.service_name][1]:
1647-
ifhasattr(self,attr):
1648-
data[attr]=getattr(self,attr)
1631+
Returns:
1632+
object: The generated RESTObject.
16491633
1650-
returnjson.dumps(data)
1634+
Raises:
1635+
GitlabAuthenticationError: If authentication is not correct
1636+
GitlabGetError: If the server cannot perform the request
1637+
"""
1638+
obj=super(ProjectServiceManager,self).get(id,**kwargs)
1639+
obj.id=id
1640+
returnobj
1641+
1642+
defupdate(self,id=None,new_data={},**kwargs):
1643+
"""Update an object on the server.
1644+
1645+
Args:
1646+
id: ID of the object to update (can be None if not required)
1647+
new_data: the update data for the object
1648+
**kwargs: Extra options to send to the Gitlab server (e.g. sudo)
16511649
1650+
Returns:
1651+
dict: The new object data (*not* a RESTObject)
16521652
1653-
classProjectServiceManager(BaseManager):
1654-
obj_cls=ProjectService
1653+
Raises:
1654+
GitlabAuthenticationError: If authentication is not correct
1655+
GitlabUpdateError: If the server cannot perform the request
1656+
"""
1657+
super(ProjectServiceManager,self).update(id,new_data,**kwargs)
1658+
self.id=id
16551659

16561660
defavailable(self,**kwargs):
16571661
"""List the services known by python-gitlab.
16581662
16591663
Returns:
16601664
list (str): The list of service code names.
16611665
"""
1662-
returnlist(ProjectService._service_attrs.keys())
1666+
returnlist(self._service_attrs.keys())
16631667

16641668

16651669
classProjectAccessRequest(AccessRequestMixin,ObjectDeleteMixin,RESTObject):

‎tools/python_test_v4.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -316,13 +316,14 @@
316316
assert(settings.level==gitlab.NOTIFICATION_LEVEL_WATCH)
317317

318318
# services
319-
# NOT IMPLEMENTED YET
320-
#service = admin_project.services.get(service_name='asana')
321-
#service.active = True
322-
#service.api_key = 'whatever'
323-
#service.save()
324-
#service = admin_project.services.get(service_name='asana')
325-
#assert(service.active == True)
319+
service=admin_project.services.get('asana')
320+
service.api_key='whatever'
321+
service.save()
322+
service=admin_project.services.get('asana')
323+
assert(service.active==True)
324+
service.delete()
325+
service=admin_project.services.get('asana')
326+
assert(service.active==False)
326327

327328
# snippets
328329
snippets=gl.snippets.list(all=True)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp