@@ -287,6 +287,9 @@ def _get_object(self, k, v):
287287 return v
288288
289289 def _set_from_dict (self , data ):
290+ if not hasattr (data , 'items' ):
291+ return
292+
290293 for k , v in data .items ():
291294 if isinstance (v , list ):
292295 self .__dict__ [k ] = []
@@ -1687,6 +1690,82 @@ class ProjectVariableManager(BaseManager):
16871690 obj_cls = ProjectVariable
16881691
16891692
1693+ class ProjectService (GitlabObject ):
1694+ _url = '/projects/%(project_id)s/services/%(service_name)s'
1695+ canList = False
1696+ canCreate = False
1697+ _id_in_update_url = False
1698+ _id_in_delete_url = False
1699+ requiredUrlAttrs = ['project_id' , 'service_name' ]
1700+
1701+ _service_attrs = {
1702+ 'asana' : (('api_key' , ), ('restrict_to_branch' , )),
1703+ 'assembla' : (('token' , ), ('subdomain' , )),
1704+ 'bamboo' : (('bamboo_url' , 'build_key' , 'username' , 'password' ),
1705+ tuple ()),
1706+ 'buildkite' : (('token' , 'project_url' ), ('enable_ssl_verification' , )),
1707+ 'campfire' : (('token' , ), ('subdomain' , 'room' )),
1708+ 'custom-issue-tracker' : (('new_issue_url' , 'issues_url' ,
1709+ 'project_url' ),
1710+ ('description' , 'title' )),
1711+ 'drone-ci' : (('token' , 'drone_url' ), ('enable_ssl_verification' , )),
1712+ 'emails-on-push' : (('recipients' , ), ('disable_diffs' ,
1713+ 'send_from_committer_email' )),
1714+ 'external-wiki' : (('external_wiki_url' , ), tuple ()),
1715+ 'flowdock' : (('token' , ), tuple ()),
1716+ 'gemnasium' : (('api_key' , 'token' , ), tuple ()),
1717+ 'hipchat' : (('token' , ), ('color' , 'notify' , 'room' , 'api_version' ,
1718+ 'server' )),
1719+ 'irker' : (('recipients' , ), ('default_irc_uri' , 'server_port' ,
1720+ 'server_host' , 'colorize_messages' )),
1721+ 'jira' : (('new_issue_url' , 'project_url' , 'issues_url' ),
1722+ ('description' , 'username' , 'password' )),
1723+ 'pivotaltracker' : (('token' , ), tuple ()),
1724+ 'pushover' : (('api_key' , 'user_key' , 'priority' ), ('device' , 'sound' )),
1725+ 'redmine' : (('new_issue_url' , 'project_url' , 'issues_url' ),
1726+ ('description' , )),
1727+ 'slack' : (('webhook' , ), ('username' , 'channel' )),
1728+ 'teamcity' : (('teamcity_url' , 'build_type' , 'username' , 'password' ),
1729+ tuple ())
1730+ }
1731+
1732+ def _data_for_gitlab (self , extra_parameters = {}, update = False ,
1733+ as_json = True ):
1734+ data = (super (ProjectService , self )
1735+ ._data_for_gitlab (extra_parameters , update = update ,
1736+ as_json = False ))
1737+ missing = []
1738+ # Mandatory args
1739+ for attr in self ._service_attrs [self .service_name ][0 ]:
1740+ if not hasattr (self , attr ):
1741+ missing .append (attr )
1742+ else :
1743+ data [attr ] = getattr (self , attr )
1744+
1745+ if missing :
1746+ raise GitlabUpdateError ('Missing attribute(s): %s' %
1747+ ", " .join (missing ))
1748+
1749+ # Optional args
1750+ for attr in self ._service_attrs [self .service_name ][1 ]:
1751+ if hasattr (self , attr ):
1752+ data [attr ] = getattr (self , attr )
1753+
1754+ return json .dumps (data )
1755+
1756+
1757+ class ProjectServiceManager (BaseManager ):
1758+ obj_cls = ProjectService
1759+
1760+ def available (self , ** kwargs ):
1761+ """List the services known by python-gitlab.
1762+
1763+ Returns:
1764+ list (str): The list of service code names.
1765+ """
1766+ return json .dumps (ProjectService ._service_attrs .keys ())
1767+
1768+
16901769class Project (GitlabObject ):
16911770 _url = '/projects'
16921771 _constructorTypes = {'owner' : 'User' , 'namespace' : 'Group' }
@@ -1725,6 +1804,7 @@ class Project(GitlabObject):
17251804 ('mergerequests' , ProjectMergeRequestManager , [('project_id' , 'id' )]),
17261805 ('milestones' , ProjectMilestoneManager , [('project_id' , 'id' )]),
17271806 ('notes' , ProjectNoteManager , [('project_id' , 'id' )]),
1807+ ('services' , ProjectServiceManager , [('project_id' , 'id' )]),
17281808 ('snippets' , ProjectSnippetManager , [('project_id' , 'id' )]),
17291809 ('tags' , ProjectTagManager , [('project_id' , 'id' )]),
17301810 ('triggers' , ProjectTriggerManager , [('project_id' , 'id' )]),
0 commit comments