@@ -287,6 +287,9 @@ def _get_object(self, k, v):
287
287
return v
288
288
289
289
def _set_from_dict (self , data ):
290
+ if not hasattr (data , 'items' ):
291
+ return
292
+
290
293
for k , v in data .items ():
291
294
if isinstance (v , list ):
292
295
self .__dict__ [k ] = []
@@ -1687,6 +1690,82 @@ class ProjectVariableManager(BaseManager):
1687
1690
obj_cls = ProjectVariable
1688
1691
1689
1692
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
+
1690
1769
class Project (GitlabObject ):
1691
1770
_url = '/projects'
1692
1771
_constructorTypes = {'owner' : 'User' , 'namespace' : 'Group' }
@@ -1725,6 +1804,7 @@ class Project(GitlabObject):
1725
1804
('mergerequests' , ProjectMergeRequestManager , [('project_id' , 'id' )]),
1726
1805
('milestones' , ProjectMilestoneManager , [('project_id' , 'id' )]),
1727
1806
('notes' , ProjectNoteManager , [('project_id' , 'id' )]),
1807
+ ('services' , ProjectServiceManager , [('project_id' , 'id' )]),
1728
1808
('snippets' , ProjectSnippetManager , [('project_id' , 'id' )]),
1729
1809
('tags' , ProjectTagManager , [('project_id' , 'id' )]),
1730
1810
('triggers' , ProjectTriggerManager , [('project_id' , 'id' )]),
0 commit comments