18
18
from __future__ import print_function
19
19
from __future__ import absolute_import
20
20
import base64
21
- import json
22
21
23
22
import six
24
23
@@ -1573,14 +1572,14 @@ class ProjectVariableManager(CRUDMixin, RESTManager):
1573
1572
_update_attrs = (('key' , 'value' ), tuple ())
1574
1573
1575
1574
1576
- class ProjectService (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
+ class ProjectService (SaveMixin , ObjectDeleteMixin , RESTObject ):
1576
+ pass
1577
+
1578
+
1579
+ class ProjectServiceManager ( GetMixin , UpdateMixin , DeleteMixin , RESTManager ):
1580
+ _path = '/projects/%(project_id)s/services'
1581
+ _from_parent_attrs = { 'project_id' : 'id' }
1582
+ _obj_cls = ProjectService
1584
1583
1585
1584
_service_attrs = {
1586
1585
'asana' : (('api_key' , ), ('restrict_to_branch' , )),
@@ -1606,16 +1605,10 @@ class ProjectService(GitlabObject):
1606
1605
'server' )),
1607
1606
'irker' : (('recipients' , ), ('default_irc_uri' , 'server_port' ,
1608
1607
'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' )),
1619
1612
'pivotaltracker' : (('token' , ), tuple ()),
1620
1613
'pushover' : (('api_key' , 'user_key' , 'priority' ), ('device' , 'sound' )),
1621
1614
'redmine' : (('new_issue_url' , 'project_url' , 'issues_url' ),
@@ -1625,41 +1618,52 @@ class ProjectService(GitlabObject):
1625
1618
tuple ())
1626
1619
}
1627
1620
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 = []
EDBE
td>1634
- # Mandatory args
1635
- for attr in self ._service_attrs [self .service_name ][0 ]:
1636
- if not hasattr (self , attr ):
1637
- missing .append (attr )
1638
- else :
1639
- data [attr ] = getattr (self , attr )
1621
+ def get (self , id , ** kwargs ):
1622
+ """Retrieve a single object.
1640
1623
1641
- if missing :
1642
- raise GitlabUpdateError ('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)
1644
1630
1645
- # Optional args
1646
- for attr in self ._service_attrs [self .service_name ][1 ]:
1647
- if hasattr (self , attr ):
1648
- data [attr ] = getattr (self , attr )
1631
+ Returns:
1632
+ object: The generated RESTObject.
1649
1633
1650
- return json .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
+ return obj
1641
+
1642
+ def update (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)
1651
1649
1650
+ Returns:
1651
+ dict: The new object data (*not* a RESTObject)
1652
1652
1653
- class ProjectServiceManager (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
1655
1659
1656
1660
def available (self , ** kwargs ):
1657
1661
"""List the services known by python-gitlab.
1658
1662
1659
1663
Returns:
1660
1664
list (str): The list of service code names.
1661
1665
"""
1662
- return list (ProjectService ._service_attrs .keys ())
1666
+ return list (self ._service_attrs .keys ())
1663
1667
1664
1668
1665
1669
class ProjectAccessRequest (AccessRequestMixin , ObjectDeleteMixin , RESTObject ):
0 commit comments