Skip to content

Commit f965821

Browse files
Merge pull request #1783 from atlassian/apps-count-bitbucket
added bitbucket apps count
2 parents 85d1768 + 7a73590 commit f965821

File tree

5 files changed

+87
-16
lines changed

5 files changed

+87
-16
lines changed

app/util/analytics/analytics_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ def generate_report_summary(collector):
107107
summary_report.append(f'Success|{success}')
108108
summary_report.append(f'Has app-specific actions|{bool(collector.app_specific_rates)}')
109109

110-
if collector.app_type in [JIRA, JSM, CONFLUENCE]:
110+
if collector.app_type in [JIRA, JSM, CONFLUENCE, BITBUCKET]:
111111
summary_report.append(f'Applications count|{collector.apps_count}')
112112
summary_report.append(f'Custom applications count|{collector.custom_apps_count}')
113113
summary_report.append(f'Custom applications count enabled|{collector.custom_apps_count_enabled}')

app/util/analytics/application_info.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,37 @@ def nodes_count(self):
206206
def dataset_information(self):
207207
return f'{self.client.get_bitbucket_repo_count()} repositories'
208208

209+
@property
210+
def apps_count(self):
211+
return len(self.__get_apps)
212+
213+
@cached_property
214+
def __get_apps(self):
215+
try:
216+
return self.client.get_installed_apps()
217+
except Exception as e:
218+
print(f'ERROR: Could not get the installed applications. Error: {e}')
219+
return []
220+
221+
@cached_property
222+
def __get_custom_apps(self):
223+
all_apps = self.__get_apps
224+
apps_with_vendor_defined = [app for app in all_apps if 'vendor' in app]
225+
non_atlassian_apps = [app for app in apps_with_vendor_defined if 'Atlassian' not in
226+
app['vendor']['name'] and app['userInstalled'] == True]
227+
return non_atlassian_apps
228+
229+
@property
230+
def custom_app_count(self):
231+
return len(self.__get_custom_apps)
232+
233+
@property
234+
def custom_app_count_enabled(self):
235+
non_atlassian_apps = self.__get_custom_apps
236+
non_atlassian_apps_enabled = [app for app in non_atlassian_apps if app['enabled'] == True]
237+
return len(non_atlassian_apps_enabled)
238+
239+
209240

210241
class Jsm(BaseApplication):
211242
type = JSM
@@ -228,6 +259,37 @@ def __issues_count(self):
228259
def dataset_information(self):
229260
return f"{self.__issues_count()} issues"
230261

262+
@property
263+
def apps_count(self):
264+
return len(self.__get_apps)
265+
266+
@cached_property
267+
def __get_apps(self):
268+
try:
269+
return self.client.get_installed_apps()
270+
except Exception as e:
271+
print(f'ERROR: Could not get the installed applications. Error: {e}')
272+
return []
273+
274+
@cached_property
275+
def __get_custom_apps(self):
276+
all_apps = self.__get_apps
277+
apps_with_vendor_defined = [app for app in all_apps if 'vendor' in app]
278+
non_atlassian_apps = [app for app in apps_with_vendor_defined if 'Atlassian' not in
279+
app['vendor']['name'] and app['userInstalled'] == True]
280+
return non_atlassian_apps
281+
282+
@property
283+
def custom_app_count(self):
284+
return len(self.__get_custom_apps)
285+
286+
@property
287+
def custom_app_count_enabled(self):
288+
non_atlassian_apps = self.__get_custom_apps
289+
non_atlassian_apps_enabled = [app for app in non_atlassian_apps if app['enabled'] == True]
290+
return len(non_atlassian_apps_enabled)
291+
292+
231293

232294
class Crowd(BaseApplication):
233295
type = CROWD

app/util/api/bitbucket_clients.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,3 +200,9 @@ def get_status(self):
200200
else:
201201
print(f"Warning: failed to get {api_url}: Error: {e}")
202202
return False
203+
204+
def get_installed_apps(self):
205+
plugins_url = f'{self.host}/rest/plugins/1.0/'
206+
r = self.get(plugins_url, error_msg="ERROR: Could not get installed plugins.",
207+
headers={'X-Atlassian-Token': 'no-check'})
208+
return r.json()['plugins']

app/util/api/jira_clients.py

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -302,19 +302,7 @@ def get_license_details(self):
302302
return r.json()
303303

304304
def get_installed_apps(self):
305-
login_url = f'{self.host}/login.jsp'
306-
auth_url = f'{self.host}/secure/admin/WebSudoAuthenticate.jspa'
307-
auth_body = {
308-
'webSudoDestination': '/secure/admin/ViewSystemInfo.jspa',
309-
'webSudoIsPost': False,
310-
'webSudoPassword': self.password
311-
}
312-
self.post(login_url, error_msg='Could not login in')
313-
auth_body['atl_token'] = self.session.cookies.get_dict()['atlassian.xsrf.token']
314-
self._session.post(auth_url, data=auth_body)
315-
self.headers['Accept'] = 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,' \
316-
'image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7'
317-
318305
api_url = f'{self.host}/rest/plugins/1.0/'
319-
r = self.get(api_url, error_msg="ERROR: Could not get the installed apps.")
306+
r = self.get(api_url, error_msg="ERROR: Could not get installed plugins.",
307+
headers={'X-Atlassian-Token': 'no-check'})
320308
return r.json()['plugins']

app/util/data_preparation/bitbucket_prepare_data.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,21 @@ def __check_for_admin_permissions(bitbucket_api):
134134
bitbucket_api.get_user_global_permissions()
135135

136136

137+
def __check_number_of_custom_app(bitbucket_api):
138+
try:
139+
all_apps = bitbucket_api.get_installed_apps()
140+
apps_with_vendor_defined = [app for app in all_apps if 'vendor' in app]
141+
non_atlassian_apps = [app for app in apps_with_vendor_defined if 'Atlassian' not in
142+
app['vendor']['name'] and app['userInstalled'] == True]
143+
non_atlassian_apps_names = [app['name'] for app in non_atlassian_apps]
144+
print(f"Custom application count: {len(non_atlassian_apps)}")
145+
if non_atlassian_apps:
146+
print(f'Custom app names:')
147+
print(*non_atlassian_apps_names, sep='\n')
148+
except Exception as e:
149+
print(f'ERROR: Could not get the installed applications. Error: {e}')
150+
151+
137152
def main():
138153
print("Started preparing data")
139154

@@ -142,7 +157,7 @@ def main():
142157

143158
client = BitbucketRestClient(url, BITBUCKET_SETTINGS.admin_login, BITBUCKET_SETTINGS.admin_password,
144159
verify=BITBUCKET_SETTINGS.secure)
145-
160+
__check_number_of_custom_app(client)
146161
__check_current_language(client)
147162
__check_for_admin_permissions(client)
148163

0 commit comments

Comments
 (0)