3535#: DevOps platform types in SonarQube
3636DEVOPS_PLATFORM_TYPES = ("github" , "azure" , "bitbucket" , "bitbucketcloud" , "gitlab" )
3737
38-
39- _OBJECTS = {}
40-
4138_CREATE_API_GITHUB = "alm_settings/create_github"
4239_CREATE_API_GITLAB = "alm_settings/create_gitlab"
4340_CREATE_API_AZURE = "alm_settings/create_azure"
@@ -54,21 +51,23 @@ class DevopsPlatform(sq.SqObject):
5451 Abstraction of the SonarQube ALM/DevOps Platform concept
5552 """
5653
54+ _OBJECTS = {}
55+
5756 def __init__ (self , endpoint : platform .Platform , key : str , platform_type : str ) -> None :
5857 """Constructor"""
5958 super ().__init__ (endpoint = endpoint , key = key )
6059 self .type = platform_type #: DevOps platform type
6160 self .url = None #: DevOps platform URL
6261 self ._specific = None #: DevOps platform specific settings
63- _OBJECTS [self .uuid ()] = self
62+ DevopsPlatform . _OBJECTS [self .uuid ()] = self
6463 log .debug ("Created object %s" , str (self ))
6564
6665 @classmethod
6766 def read (cls , endpoint : platform .Platform , key : str ) -> DevopsPlatform :
6867 """Reads a devops platform object in Sonar instance"""
6968 uu = sq .uuid (key , endpoint .url )
70- if uu in _OBJECTS :
71- return _OBJECTS [uu ]
69+ if uu in DevopsPlatform . _OBJECTS :
70+ return DevopsPlatform . _OBJECTS [uu ]
7271 data = json .loads (endpoint .get (APIS ["list" ]).text )
7372 for plt_type , platforms in data .items ():
7473 for p in platforms :
@@ -81,8 +80,8 @@ def load(cls, endpoint: platform.Platform, plt_type: str, data: types.ApiPayload
8180 """Finds a devops platform object and loads it with data"""
8281 key = data ["key" ]
8382 uu = sq .uuid (key , endpoint .url )
84- if uu in _OBJECTS :
85- return _OBJECTS [uu ]
83+ if uu in DevopsPlatform . _OBJECTS :
84+ return DevopsPlatform . _OBJECTS [uu ]
8685 o = DevopsPlatform (endpoint = endpoint , key = key , platform_type = plt_type )
8786 return o ._load (data )
8887
@@ -198,9 +197,9 @@ def count(platf_type: str = None) -> int:
198197 :rtype: int
199198 """
200199 if platf_type is None :
201- return len (_OBJECTS )
200+ return len (DevopsPlatform . _OBJECTS )
202201 # Hack: check first 5 chars to that bitbucket cloud and bitbucket server match
203- return sum (1 for o in _OBJECTS .values () if o .type [0 :4 ] == platf_type [0 :4 ])
202+ return sum (1 for o in DevopsPlatform . _OBJECTS .values () if o .type [0 :4 ] == platf_type [0 :4 ])
204203
205204
206205def get_list (endpoint : platform .Platform ) -> dict [str , DevopsPlatform ]:
@@ -213,12 +212,12 @@ def get_list(endpoint: platform.Platform) -> dict[str, DevopsPlatform]:
213212 if endpoint .is_sonarcloud ():
214213 raise exceptions .UnsupportedOperation ("Can't get list of DevOps platforms on SonarCloud" )
215214 if endpoint .edition () == "community" :
216- return _OBJECTS
215+ return DevopsPlatform . _OBJECTS
217216 data = json .loads (endpoint .get (APIS ["list" ]).text )
218217 for alm_type in DEVOPS_PLATFORM_TYPES :
219218 for alm_data in data .get (alm_type , {}):
220219 DevopsPlatform .load (endpoint , alm_type , alm_data )
221- return _OBJECTS
220+ return DevopsPlatform . _OBJECTS
222221
223222
224223def get_object (devops_platform_key : str , endpoint : platform .Platform ) -> DevopsPlatform :
@@ -228,7 +227,7 @@ def get_object(devops_platform_key: str, endpoint: platform.Platform) -> DevopsP
228227 :return: The DevOps platforms corresponding to key, or None if not found
229228 :rtype: DevopsPlatform
230229 """
231- if len (_OBJECTS ) == 0 :
230+ if len (DevopsPlatform . _OBJECTS ) == 0 :
232231 get_list (endpoint )
233232 return DevopsPlatform .read (endpoint , devops_platform_key )
234233
@@ -265,7 +264,7 @@ def import_config(endpoint: platform.Platform, config_data: types.ObjectJsonRepr
265264 if endpoint .is_sonarcloud ():
266265 raise exceptions .UnsupportedOperation ("Can't get import DevOps platforms in SonarCloud" )
267266 log .info ("Importing DevOps config %s" , util .json_dump (devops_settings ))
268- if len (_OBJECTS ) == 0 :
267+ if len (DevopsPlatform . _OBJECTS ) == 0 :
269268 get_list (endpoint )
270269 for name , data in devops_settings .items ():
271270 try :
0 commit comments